Announcement

Collapse
No announcement yet.

Setting a status-only device status via API that will actually trigger an event?

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

    Setting a status-only device status via API that will actually trigger an event?

    I've seen a few threads on this in the past, but found nothing that actually resolved the issue. Basically here's what I have. I've found I can control a device (a device that has both status and control set for it's values) using a single line of json:

    Code:
    http://home.fielding.ca/JSON?&request=controldevicebylabel&ref=884&label=Home
    That will properly update the device status, it's last changed time, and hstouch, and any triggers that trigger on that device status will trigger. I can also do the same with 'controldevicebyvalue'.

    However, if the status value that I'm trying to update is a status-only value (or if the device is a status-only device), the above line errors. With much digging I've found I can at least update the status and get hstouch to update using two commands:

    Code:
    http://home.fielding.ca/JSON?&request=setdeviceproperty&ref=563&property=NewDevValue&value=100
    followed by:
    Code:
    http://home.fielding.ca/JSON?&request=setdeviceproperty&ref=563&property=ChangedValueORString&value=TRUE
    This will update the device status and update hstouch. HOWEVER, it does not appear to update the last changed time for the device, and any triggers that trigger on that device do NOT trigger.

    So far I have not found a way around this. I have a bunch of hidden virtual devices for which I'd like to be able to have as status-only and change via json, and have triggers trigger off of those changes. The only thing I've been able to do for now is to make them non-status-only, which works. But I shouldn't have to.

    Anyone know a better way?

    regards,

    Paul
    Last edited by paul; October 8, 2018, 10:26 PM.

    #2
    I have not used JSON to control HS, but here are some ideas.
    The SetDeviceValue function has a parameter to trigger on change. This may be able to be set via JSON.
    There is a scripting function SetDeviceLastChange to change this property. You may be able to explicitly set it in your JSON commands.

    Comment


      #3
      Originally posted by paul View Post
      This will update the device status and update hstouch. HOWEVER, it does not appear to update the last changed time for the device, and any triggers that trigger on that device do NOT trigger.

      So far I have not found a way around this. I have a bunch of hidden virtual devices for which I'd like to be able to have as status-only and change via json, and have triggers trigger off of those changes. The only thing I've been able to do for now is to make them non-status-only, which works. But I shouldn't have to.

      Anyone know a better way?
      l
      So here is a work-around for this issue: Setup an event for the device you are changing the status of with JSON where if the status of the device changes to any value then run an immediate script using this: &hs.SetDeviceLastChange(xxxx, Now) and replace the xxxx with the device reference number. This will place an immediate last change timestamp on the device. Problem solved.

      Here is a screenshot of how it looks:

      Click image for larger version

Name:	example.png
Views:	372
Size:	39.0 KB
ID:	1264157

      Be sure to toggle "Cannot Re-Rerun For" and set it for 5 seconds or so to prevent a loop situation from occurring.

      It's a little clunky, but it does solve the problem.

      Hope this helps.

      --Barry

      Comment


        #4
        That’s a good idea. I have a lot of devices that I’m dealing with though. I wonder if there’s a way to take this and bulk-ify it somehow do I don’t have to have 20 events for 20 devices....

        Comment


          #5
          Why don’t you just change the status devices to both (control and status)? You are trying to update something which isn’t supposed to be updateable by you. Instead of fighting the system just redefine the controls.

          Comment


            #6
            Originally posted by bsobel View Post
            Why don’t you just change the status devices to both (control and status)? You are trying to update something which isn’t supposed to be updateable by you. Instead of fighting the system just redefine the controls.
            Well, that is indeed what I have ended up doing for devices that are simple on/off-ish and are not in a location that is visible by the HS Touch client. However, for example I have one virtual device that I use to change the status of my alarm system between Standby, Home, and Away. However the way I have it setup, it has six states:

            Disarm Standby
            Standby
            Arm Home
            Home
            Arm Away
            Away

            Disarm Standby, Arm Home, and Arm Away are Controllable so that I see the three options on that device to change the state of the Alarm system in a user-friendly way. But Once you hit them, arm gets changed accordingly and then teh state is changed to the final state rather than the transitory state.

            Ultimately I can work around this, but ideally I think it should be reasonable to be able to change a non-controllable status if using the API - it makes sense to not have buttons on the UI, but if using the API the presumption is that you're intentionally hitting the state you're coding for.....

            Paul

            Comment


              #7
              I believe you can set the control use or location vis code so they wont be displayed, so you can just have your actionable controls visible on the UI....

              Comment


                #8
                Originally posted by paul View Post
                That’s a good idea. I have a lot of devices that I’m dealing with though. I wonder if there’s a way to take this and bulk-ify it somehow do I don’t have to have 20 events for 20 devices....
                I'm sure that could be done by calling a single vb script, but that's above my pay grade. Setting up the multiple events is not too difficult... Once you get the first one set up you can just clone it and simply change the device ID reference number in the script and the monitored device in the "if" section". You could set up 20 in just a few moments.


                Comment

                Working...
                X