Announcement

Collapse
No announcement yet.

Z-wave relative dim script?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Z-wave relative dim script?

    Hi Folks
    I am looking to control Z-wave dimmers using relative increments. From what I can see this control is available with X10, but not with Z-Wave. Essentially I want to control each dimmable device with 2 buttons "Up 10%" and "Down 10%". e.g. if current Dim level = 80% and a +10% event is triggered, the light would brighten to absolute 90% level.

    I'm guessing that this would probably need to be a script to retain or inquire on current dim level and then set a new level +/- 10%.

    Does anyone have another way to do this, or is scripting the only way to go? Any pointers to either solution greatly appreciated.

    In case you want to know why? I have set up a virtual device on my Harmony 880 remote and am sending IR signals to HS via irTrans for several Z-Wave devices. I now want to include simple up/down for lighting controls. Beats 'upgrading' to another remote that may or may not have Z-wave support.

    Many thanks
    Cheeryfool
    cheeryfool

    #2
    I recently (very recently) ran into the same situation and came up with a hack that works. I tried to use a select case, but sadly, I didn't think it through well enough at the time to get it working just so. It worked with the if/elseif, so I simply reverted to it, and stopped thinking about it

    I set up events, one for dim and one for bright to call the respective script. It does the trick

    Code:
    ' adjust light dim level down one notch
    Sub Main(parm as object)
    ' script to track current status, and dim down 10% per dim request
    ' updates status / state for given device code.
    '
    ' used to control a z-wave dimmable device via x-10 palmpad input
    '
    ' written by huggy_d1, 4/28/2008
    ' future : use select case structure, and standard subroutine to simplify code
    '            and make it easier to maintain
    '            use parameter to define dev_Light so it can be called from an event
    '            and work for multiple devices
    '
    
    	dim debugmode as Boolean = vbFalse
    	dim dev_Light as String = "Q17"
    	dim lDimLevel as Long
    	
    	'---device status code
    	'0 = All Units Off
    	'2 = ON
    	'3 = OFF
    	'4 = DIM
    	
    	lDimLevel = hs.DeviceValue(dev_Light)
    	if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level      = " & lDimLevel )
    	if lDimLevel > 90 then
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = " & lDimLevel )
    		hs.ExecX10( dev_Light,"DDim", 90, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 90 )
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = (>90) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel > 80 then
    		hs.ExecX10( dev_Light,"DDim", 80, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 80 )
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = (>80) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel > 70 then
    		hs.ExecX10( dev_Light,"DDim", 70, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 70 )
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = (>70) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel > 60 then
    		hs.ExecX10( dev_Light,"DDim", 60, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 60 )
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = (>60) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel > 50 then
    		hs.ExecX10( dev_Light,"DDim", 50, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 50 )
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = (>50) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel > 40 then
    		hs.ExecX10( dev_Light,"DDim", 40, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 40 )
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = (>40) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel > 30 then
    		hs.ExecX10( dev_Light,"DDim", 30, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 30 )
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = (>30) " & hs.DeviceValue(dev_Light) )		
    	elseif lDimLevel > 20 then
    		hs.ExecX10( dev_Light,"DDim", 20, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 20 )
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = (>20) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel > 10 then
    		hs.ExecX10( dev_Light,"DDim", 10, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 10 )
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = (>10) " & hs.DeviceValue(dev_Light) )
    	else
    		hs.ExecX10( dev_Light,"Off", , , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 3 )
    		hs.SetDeviceValue( dev_Light, 0 )
    		if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = (Off) " & hs.DeviceValue(dev_Light) )
    	end if
    	if debugmode then hs.writelog( "palmpad dim", dev_Light & " Dim Level     = " & lDimLevel )
    	if debugmode then hs.writelog( "palmpad dim", dev_Light & " Device Status = " & hs.DeviceStatus(dev_Light) )
    	if debugmode then hs.writelog( "palmpad dim", dev_Light & " Device Value  = " & hs.DeviceValue(dev_Light) )
    end sub
    Code:
    ' adjust light dim level up one notch
    Sub Main(parm as object)
    ' script to track current status, and brighten up 10% per brighten request
    ' updates status / state for given device code.
    '
    ' used to control a z-wave dimmable device via x-10 palmpad input
    '
    ' written by huggy_d1, 4/28/2008
    ' future : use select case structure, and standard subroutine to simplify code
    '            and make it easier to maintain
    '            use parameter to define dev_Light so it can be called from an event
    '            and work for multiple devices
    '
    	dim debugmode as Boolean = vbFalse
    	dim dev_Light as String = "Q17"
    	dim lDimLevel as Long
    
    	
    	'---device status code
    	'0 = All Units Off
    	'2 = ON
    	'3 = OFF
    	'4 = DIM
    	
    	lDimLevel = hs.DeviceValue(dev_Light)
    	if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level      = " & lDimLevel )
    	if lDimLevel < 10 then
    		hs.ExecX10( dev_Light,"DDim", 10, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 10 )
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = (>10) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel < 20 then
    		hs.ExecX10( dev_Light,"DDim", 20, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 20 )
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = (>20) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel < 30 then
    		hs.ExecX10( dev_Light,"DDim", 30, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 30 )
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = (>30) " & hs.DeviceValue(dev_Light) )	
    	elseif lDimLevel < 40 then
    		hs.ExecX10( dev_Light,"DDim", 40, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 40 )
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = (>40) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel < 50 then
    		hs.ExecX10( dev_Light,"DDim", 50, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 50 )
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = (>50) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel < 60 then
    		hs.ExecX10( dev_Light,"DDim", 60, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 60 )
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = (>60) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel < 70 then
    		hs.ExecX10( dev_Light,"DDim", 70, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 70 )
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = (>70) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel < 80 then
    		hs.ExecX10( dev_Light,"DDim", 80, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 80 )
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = (>80) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel < 90 then
    		hs.ExecX10( dev_Light,"DDim", 90, , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 4 )
    		hs.SetDeviceValue( dev_Light, 90 )
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = (>80) " & hs.DeviceValue(dev_Light) )
    	elseif lDimLevel < 100 then
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = " & lDimLevel )
    		hs.ExecX10( dev_Light,"On", , , vbTrue )
    		hs.SetDeviceStatus( dev_Light, 2 )
    		hs.SetDeviceValue( dev_Light, 100 )
    		if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = (<100) " & hs.DeviceValue(dev_Light) )
    	end if
    	if debugmode then hs.writelog( "palmpad bright", dev_Light & " Dim Level     = " & lDimLevel )
    	if debugmode then hs.writelog( "palmpad bright", dev_Light & " Device Status = " & hs.DeviceStatus(dev_Light) )
    	if debugmode then hs.writelog( "palmpad bright", dev_Light & " Device Value  = " & hs.DeviceValue(dev_Light) )
    end sub
    huggy_d1

    Automating made easy

    Comment


      #3
      Originally posted by huggy_d1 View Post
      I recently (very recently) ran into the same situation and came up with a hack that works. I tried to use a select case, but sadly, I didn't think it through well enough at the time to get it working just so. It worked with the if/elseif, so I simply reverted to it, and stopped thinking about it

      I set up events, one for dim and one for bright to call the respective script. It does the trick

      Thanks Huggy - that certainly works great.

      I am one of those guys who works in a tech environment but is definitely NOT a developer, leaving me able to understand simple code, but not write it (a bit like my French and Spanish!). I will play a little and I hope to have a buddy who really is a code monkey see if he can tweak it so that we can pass in parameters to a single version. I'll post here if I am able to get this done.

      Off to set up some more virtual Harmony device(s) and teach my irTrans plugin the codes.

      Thanks again
      cheeryfool

      Comment


        #4
        Huggy

        I finally got around to tweaking your script and I have a single version working as the base for 8 lighting events. I am passing in the device code and desired relative dim value from the optional parameters e.g. ("Main","-10/Q5") and then parsing that out into variables.

        Here's the code:

        Code:
        ' adjust light level up/down 10% based on input parameter
        ' string containing dim/bright value and device code
        
        ' Thanks to initial script from huggy_d1 (2008/04/28)
        ' Modified by CheeryFool (2008/05/12) to use two concatenated event 
        ' input parameters (relative dim value and device code), which are
        ' parsed into variables.
        
        
        Sub Main(ByVal inputparms as String)
        
                dim pos = InStr(inputparms, "/")
                dim strSize = Len(inputparms)
                dim valchg as String = Left(inputparms, pos - 1)
                dim varLight as String = Right(inputparms, strSize - pos)   
        
          
                dim debugmode as Boolean = vbFalse
                dim lDimLevel as Long
        
        
                '---device status code
                '0 = All Units Off
                '2 = ON 
                '3 = OFF
                '4 = DIM
                
                    'store current dim level
                    lDimLevel = hs.DeviceValue(varLight)
        
                    'if debug mode ouput current values to log
        
                if debugmode then hs.writelog( "Harmony Lights", varLight & " Dim Level     = " & lDimLevel )
                if debugmode then hs.writelog( "Harmony Lights", varLight & " Device Status = " & hs.DeviceStatus(varLight) )
                if debugmode then hs.writelog( "Harmony Lights", varLight & " Device Value  = " & hs.DeviceValue(varLight) )
            
                    'max out new dim level at 100% and set to ON
        
                if lDimLevel + valchg > 100 then
                    lDimLevel = 100
                    hs.ExecX10( varLight,"On",,,vbTrue )
                    hs.SetDeviceStatus( varLight, 2 )
                    hs.SetDeviceValue( varLight, lDimLevel)
        
                    'min out new dim level at 0% and set to OFF
        
                elseif lDimLevel + valchg < 0 then
                    lDimLevel = 0
                    hs.ExecX10( varLight,"Off",,,vbTrue )
                    hs.SetDeviceStatus( varLight, 3 )
                    hs.SetDeviceValue( varLight, lDimLevel)
        
                    'else set new dim level, device value and device status
               
                else lDimLevel = lDimLevel + valchg
                    hs.ExecX10( varLight,"DDim", lDimLevel,,vbTrue )
                    hs.SetDeviceStatus( varLight, 4 )
                    hs.SetDeviceValue( varLight, lDimLevel) 
        
                end if
               
        
        'if debug mode output end values to log
               
        if debugmode then hs.writelog( "Harmony Lights", varLight & " Dim Level     = " & lDimLevel )
        if debugmode then hs.writelog( "Harmony Lights", varLight & " Device Status = " & hs.DeviceStatus(varLight) )
        if debugmode then hs.writelog( "Harmony Lights", varLight & " Device Value  = " & hs.DeviceValue(varLight) )
        
        end sub
        I have now set up a virtual Harmony remote device with up/down 10% buttons for each of 4 lights, taught HomeSeer the IR codes and set the events to be triggered by IRmatch. All seems to work great.

        Anyone please feel free to use or modify as desired.

        Thanks again
        cheeryfool

        Comment


          #5
          Looks good. I was very close at one point to the very thing you posted. I was getting wonky typo-related errors, and instead of fixing it, I opted to use it since it was working before I messed around with it

          Thanks for the tweaks.

          What device grabs the IR signals and passes on to HS? How does that work? Do you receive an x10 type signal into HS, or does a device value change? How is your event set up?
          huggy_d1

          Automating made easy

          Comment


            #6
            Huggy

            I have a IRTrans Ethernet device that transmits IR signals to HS and receives IR signals from HS, using YoYo's IRTrans plugin. This solution seems to very good, but the IRTrans device is quite expensive with the EUR/USD exchange rate where it is now. I believe that there are other solutions out there too, that may be cheaper.

            I configured my Harmony 880 with a virtual lighting device - essentially just choosing a device from their huge online catalog that I don't own and that has enough IR commands built in for my needs (at least 8). I renamed the device in Harmony to "Lighting Controller" and also 8 of the custom buttons e.g. "Pwr Toggle" became "LR Side Light -10%", and perhaps "Input 2" became ""LR Side Light +10%". Then re-ordered the buttons so that they line up on the Harmony after being updated via USB connection.

            Now to teach HS the IR commands.
            In the HS IRSignals config screen I created new devices and signal names. Then you hit the Learn button and fire the respective button on the Harmony at the irTrans device until HS confirms that the signal is learned. See the first attached picture.

            Set up HS event to trigger from the learned IR signal. In the event (e.g. "LR Side Light -10"), change the Trigger Type from whatever the current setting is to "I/R Match" and then choose the correct IR match command. In my example "LR_Side_Light,-10%" and save. See the second attached picture.

            Make sure the event is configured to send in the optional parameters e.g. ("Main","-10/Q5"). Where "-10" is the absolute value change to go to the "valchg" variable and the "Q5" is the dimmable device code to go to the "varLight" variable.

            Hope that helps. Fire me any other questions.

            CheeryFool
            Attached Files
            cheeryfool

            Comment

            Working...
            X