Announcement

Collapse
No announcement yet.

How to turn on a switch from single script command?

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

    How to turn on a switch from single script command?

    I am trying to turn on a switch in Hubitat using the following single script command:

    &IF (hs.devicevalueex(970) - hs.devicevalueex(971))>0 THEN hs.SetDeviceValueByRef 988,255,true

    The switch turns on in HS4 but not in Hubitat. When I turn the switch on and off manually in the HS4 device interface it works. Any thoughts on what else I need to do to activate this switch? The device is set as a virtual switch in Hubitat. Thanks.

    #2
    CAPI control is used to affect things on an interface. Look at post #83 Add support for Echo Speaks? - HomeSeer Message Board

    Comment


      #3
      I was afraid you would say that. I must say I don't really understand the logic behind CAPI and probably have to invest some more time. In HS3 I use tenscriptaid usually to figure out what the command looks like. I believe it works under HS4 so will have to look into that. Is there a better/easier way to decipher what command will operate a device? Thanks.

      Comment


        #4
        Use a Event Action to control a device. You can trigger the event from your script.

        The Status/Graphics tab from HS contains all the information you need. There will be a control label for the desired state. You can also define ControlUse property at the same place and then the CAPI control can use ControlUse rather than label.

        Comment


          #5
          Thanks for bearing with me on this. I have no idea what I am doing here but I am a quick learn.

          Here is what I see on the Status/Graphics tab in the device in question. It is a simple virtual switch in Hubitat.

          If you can indulge me - what would I put in the following command to switch it on if the conditions are met:

          &IF (hs.devicevalueex(970) - hs.devicevalueex(971))>0 THEN hs.SetDeviceValueByRef 988,255,true

          By way of background, this device tells me if I am solar independent at any point in time. In other words, am I producing more electricity than I am using.

          Thanks.

          Click image for larger version

Name:	Screen Shot 2021-09-28 at 8.12.50 AM.png
Views:	55
Size:	302.0 KB
ID:	1499151

          Comment


            #6
            The reference from the Echo Speaks thread is below where text is being changed and routed to the interface
            Code:
            &hs.CAPIControlHandler(hs.CAPIGetSingleControlByUse(2865, HomeSeerAPI.ePairControlUse._Off).ControlString = "This is a test")
            In this case text is not involved. It is a two step process that can be combined into one line
            1, Create a CAPI object that represents the ON control of the device. Your screenshot above shows that this device has a ControlUse of On and a second for Off.
            hs.CAPIGetSingleControlByUse(988, HomeSeerAPI.ePairControlUse._On)
            2. Pass this CAPI object to HS asking it to be forwarded to the interface that is able to control it
            hs.CAPIControlHandler(CAPIobject)

            Combined into one line it is
            Code:
            hs.CAPIControlHandler(hs.CAPIGetSingleControlByUse(988, HomeSeerAPI.ePairControlUse._On))
            If you want to command the interface to the Off value then step 1 above would get the _Off CAPI object. The Off corresponds to a DeviceValue of 0. The Off corresponds to a DeviceValue of 255 per your screenshot.

            If ControlUse is not setup for the device then Label would would be used to identify which state the CAPI control should represent. In this case HS returns all CAPI objects for a device and then your script would iterate through the list looking for the label of interest. Your screenshot shows Label column values of "Off" and "On". Since ControlUse is setup it is easier to use.

            Comment


              #7
              Hi, I finally got around to spending some more time on my HS4 installation. I setup a simple event to execute the single script command and keep getting "init error: Invalid character". Thanks for the help.

              Running script statement immediately (Test CAPI On Command): &hs.CAPIControlHandler(hs.CAPIGetSingleControlByUse(988, HomeSeerAPI.ePairControlUse._On))

              Running script(2) &hs.CAPIControlHandler(hs.CAPIGetSingleControlByUse(988, HomeSeerAPI.ePairControlUse._On)), init error: Invalid character
              11/6/2021 3:19:51 PM

              Comment


                #8
                HomeSeerAPI.ePairControlUse._On is the same as 1
                HomeSeerAPI.ePairControlUse._Off is the same as 2

                I have also seen &nhs for HS4 scripts

                Comment

                Working...
                X