Announcement

Collapse
No announcement yet.

Script Help Toggle On/Off

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

    Script Help Toggle On/Off

    Need some help with this script. It changes the value on the device but the device does not turn on/of when ran.

    Sub Main(ByVal Parms As String)
    ''
    '' Toggle the Specified Device ON/OFF
    '' DIM is considered ON
    ''
    '' Specify the Device Name, including Locations, as a Parm
    Dim devValue As Double
    Dim theDevice As String

    '' Get Device from the Parms
    theDevice = Parms.ToString
    '' Get the Device Status
    devValue = hs.DeviceValueByName(theDevice)
    '' Toggle it
    Select Case devValue
    Case Is > 0
    '' Device ON or DIM, turn it OFF
    hs.SetDeviceValueByName(theDevice, 0)
    hs.SetDeviceStringByName(theDevice, "Off", True)
    Case 0
    '' Device OFF, turn it ON
    hs.SetDeviceValueByName(theDevice, 255)
    hs.SetDeviceStringByName(theDevice, "On", True)
    End Select
    End Sub

    #2
    What sort of devices are you trying to control? As you say it is changing the value correctly but it depends on how the device is set up as to whether when it's value is changed whether or not it notices.

    Comment


      #3
      GE Light switches. Yes the status and value are changing.

      Comment


        #4
        Originally posted by Mad leal View Post
        GE Light switches. Yes the status and value are changing.
        I am going to guess Z-Wave then? I don't know how the Z-Wave plugin is set up but I am going to guess that it does not monitor when values change (some plugins do, some don't). The new way to control devices is by CAPI, a good guide on scripting for CAPI is here http://board.homeseer.com/showthread.php?t=161009.

        To clarify some plugins are written so whenever something else changes it's values then it gets notified in case it needs to do something about it, some don't need it and are not written that way.

        Comment


          #5
          Perfect!! Figured it out. Thanks for you help.

          Sub Main(ByVal theDevice As String)
          ''
          '' Toggle the Specified Device ON/OFF
          '' DIM is considered ON
          ''
          '' Specify the Device Name, including Locations, as a Parm
          Dim devValue As Double
          ''

          '' Get the Device Status
          devValue = hs.DeviceValue(theDevice)
          '' Toggle it
          Select Case devValue
          Case Is > 0
          '' Device ON or DIM, turn it OFF
          hs.CAPIControlHandler(hs.CAPIGetSingleControl(theDevice,true ,"off",false,true))
          Case 0
          '' Device OFF, turn it ON
          hs.CAPIControlHandler(hs.CAPIGetSingleControl(theDevice,true ,"on",false,true))
          End Select
          End Sub

          Comment

          Working...
          X