Announcement

Collapse
No announcement yet.

Matching Value Script

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

  • sparkman
    replied
    Here's the script that I use:

    Code:
    Sub Main(ByVal Parms as String)
    
    	Dim ParmArray() as String
    	ParmArray = Parms.tostring.split(",")
    	dim targetDev1 as Double = CDbl(ParmArray(0))		'reference ID of the device to use for existing value
    	dim targetDev2 as Double = CDbl(ParmArray(1))		'reference ID of the device to set based on value of targetDev1
    	dim Debug as Boolean = True
    	Dim logName = "Dim Follower"								'set log name for HS log
    
    	Dim dev1Value,dev2Value As Double
    	dev1Value = hs.DeviceValue(targetDev1)
    	dev2Value = hs.DeviceValue(targetDev2)
    
    	If Debug Then hs.writelog(logName,CStr(targetDev1) & ":" & CStr(dev1Value))
    	If dev1Value <> dev2Value Then
    		Select Case dev1Value
    			Case 1 to 98
    				' Device DIM, set its current dim level
    				hs.CAPIControlHandler(hs.CAPIGetSingleControl(targetDev2, false, CStr(dev1Value), false, true))
    				If Debug Then hs.writelog(logName,CStr(targetDev2) & ":" & CStr(dev1Value))
    			Case 99
    				' Device ON, set it to on
    				hs.CAPIControlHandler(hs.CAPIGetSingleControl(targetDev2, false, "On", false, false))
    				If Debug Then hs.writelog(logName,CStr(targetDev2) & " Set to On")
    			Case 0
    				' Device OFF, set it to off
    				hs.CAPIControlHandler(hs.CAPIGetSingleControl(targetDev2, false, "Off", false, true))
    				If Debug Then hs.writelog(logName,CStr(targetDev2) & " Set to Off")
    		End Select
    	Else
    			If Debug Then hs.writelog(logName,"Devices are at same value already")
    	End If
    
    End Sub
    You need to pass two variables to it, the device reference id of the device that is the "master", and then the reference id of the slave device that needs to "follow", separated with a comma. Save the file with a .vb extension and then create an event that triggers every time the master device changes. For the event action, run the script passing those device reference ids to it. The script was created to allow a real device to change based on another device. Since you are planning on a virtual slave device to follow the master, you may need to replace the hs.CAPIControlHandler command with:

    Code:
    hs.SetDeviceValueByRef(targetDev2, dev1Value, True)
    Hope that helps.

    Cheers
    Al

    Leave a comment:


  • cpd5899
    replied
    Thanks Al!!!

    Leave a comment:


  • sparkman
    replied
    I have a script that can be easily modified to do that. Will post it later today.

    Cheers
    Al


    Sent from my iPhone using Tapatalk

    Leave a comment:


  • cpd5899
    replied
    Anyone?

    Leave a comment:


  • cpd5899
    replied
    It appears properly in HS3 but not in HST.

    Leave a comment:


  • mrhappy
    replied
    Not that it is impossible to do I would wonder if it is more feasbile to work out why the Insteon device does not work. If the dim value range has the controluse property set to dim does it not appear correctly?

    Leave a comment:


  • cpd5899
    started a topic Matching Value Script

    Matching Value Script

    I'm looking for the following script.

    One of my insteon devices isn't sending the value (dim level) to HStouch. I want to create a virtual device and have that device dim to the same level as the insteon switch and use the value from the virtual within HS. I have done it before with an event but that was just for on and off. Cant seem to find a way to match values.
Working...
X