Announcement

Collapse
No announcement yet.

JSON ControlDeviceByValue not working on virtual device

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

    JSON ControlDeviceByValue not working on virtual device

    Hi,

    I've set up NUT to feed into a couple of virtual devices in HS representing current status, battery charge, load etc. This seems to work nice so far, but there's one issue I still haven't managed to overcome:

    I'm using a line like this to push the current load of a UPS into HS
    Code:
    response=$(curl "http://192.168.123.209:8080/JSON?request=controldevicebyvalue&ref=1909&value=${batterycharge}")
    This results in a log entry like this:
    Code:
    Jun-26 15:40:03	 	Device Control	Device: Monitoring vUPS UPS Load to 27 @S@ (27) by/from: CAPI Control Handler
    Unfortunately the device doesn't show any change at all. The device is not configured "Status Only" and has one value range from 0-100, which is set to "Both", allowing control & status. I have to use another JSON line to make the device pick up the change:
    Code:
    response=$(curl "http://192.168.123.209:8080/JSON?request=setdeviceproperty&property=NewDevValue&ref=1909&value=${batterycharge}")
    When I do this the device looks all right, displaying the value I want. Only "Last Change" is never updated and events on value change don't trigger. To be clear: right now I'm using both commands, ControlDeviceByValue first, then SetDeviceProperty.

    A script command like these (which is supposed to do the exact same thing) works fine (set device value and trigger event):
    Code:
    hs.SetDeviceValueByRef(1909, 27, True)
    Any idea what I'm doing wrong?

    Cheers,
    Alex

    #2
    Nobody?

    Comment


      #3
      Not certain. I do the same without issue but using APCUPSD and a perl script. Perhaps it's the "@s@" as a suffix??

      I have the following in my log.
      Code:
      12:13:55:7954:[Device Control]->Device: UPS bigUPS bigUPS - Percent Load Capacity to 20 % Load Capacity (20) by/from: CAPI Control Handler
      Attached Files
      Len


      HomeSeer Version: HS3 Pro Edition 3.0.0.435
      Linux version: Linux homeseer Ubuntu 16.04 x86_64
      Number of Devices: 633
      Number of Events: 773

      Enabled Plug-Ins
      2.0.54.0: BLBackup
      2.0.40.0: BLLAN
      3.0.0.48: EasyTrigger
      30.0.0.36: RFXCOM
      3.0.6.2: SDJ-Health
      3.0.0.87: weatherXML
      3.0.1.190: Z-Wave

      Comment


        #4
        This is Linux, right? The construct "response=$( some command ) assigns the output of some command to a variable named "response" which you can print out via

        echo $response

        (Alternately, issue just the curl "http://...." without prepending the "response=$(" and minus the trailing ")" of course).

        I would expect it to look something along the lines of

        Code:
        HTTP/1.0 200 OK
        Server: HomeSeer
        Cache-Control: no-cache
        Access-Control-Allow-Origin: *
        Content-Type: application/json; charset=utf-8
        Accept-Ranges: none
        Content-Length: 21
        
        { "Response":"ok" }
        Which is the response I get from a successful JSON request.

        Comment


          #5
          Hi Len,

          No, the @s@ is just a placeholder for the suffix unit used for this device. Unfortunately I see the same behavior for other devices with static suffixes as well.

          The odd thing is that everything seems to work just fine according to the log and to the JSON return values I get. Only the device won't update. And if I do the exact same thing from a local script instead of JSON I get the exact same results in the log, but this time the device changes as well. It must have something to do with the JSON calls...

          Definitely beats me

          Thanks for looking into this anyway!

          Alex

          Originally posted by lveatch View Post
          Not certain. I do the same without issue but using APCUPSD and a perl script. Perhaps it's the "@s@" as a suffix??

          I have the following in my log.
          Code:
          12:13:55:7954:[Device Control]->Device: UPS bigUPS bigUPS - Percent Load Capacity to 20 % Load Capacity (20) by/from: CAPI Control Handler

          Comment


            #6
            Hi Zwolfpack,

            That's the odd thing: the JSONs result in exatly the log results that I would expect. The JSON return values are also perfect:

            Code:
            {"Name":"HomeSeer Devices","Version":"1.0","Devices":[{"ref":1909,"name":"UPS Battery Charge","location":"Serverraum","location2":"Keller","value":100,"status":"100 %","device_type_string":"vUPS Battery Charge","last_change":"\/Date(1498685402922)\/","relationship":4,"hide_from_view":false,"associated_devices":[1906],"device_type":{"Device_API":0,"Device_API_Description":"No API","Device_Type":0,"Device_Type_Description":"Type 0","Device_SubType":0,"Device_SubType_Description":"UPS Battery Charge"},"device_image":"","UserNote":"","UserAccess":"Any","status_image":"/images/HomeSeer/status/battery_100.png"}]}
            Only the device won't update. It looks like every bit involved in this seems to agree that everything works just fine - only the device doesn't give a ***.

            Very strange indeed.

            Cheers,
            Alex

            Originally posted by zwolfpack View Post
            This is Linux, right? The construct "response=$( some command ) assigns the output of some command to a variable named "response" which you can print out via

            echo $response

            (Alternately, issue just the curl "http://...." without prepending the "response=$(" and minus the trailing ")" of course).

            I would expect it to look something along the lines of

            Code:
            HTTP/1.0 200 OK
            Server: HomeSeer
            Cache-Control: no-cache
            Access-Control-Allow-Origin: *
            Content-Type: application/json; charset=utf-8
            Accept-Ranges: none
            Content-Length: 21
            
            { "Response":"ok" }
            Which is the response I get from a successful JSON request.

            Comment


              #7
              Ran the following and it controlled the device as expected. I'm at a loss...

              Code:
              pi@rpi:~ $ curl "http://192.168.1.103/JSON?request=controldevicebyvalue&ref=756&value=100"
              {"Name":"HomeSeer Devices","Version":"1.0","Devices":[{"ref":756,"name":"Garage Work Mode","location":"Garage","location2":"Access Control","value":100,"status":"On","device_type_string":"","last_change":"\/Date(1499113755304)\/","relationship":0,"hide_from_view":false,"associated_devices":[],"device_type":{"Device_API":0,"Device_API_Description":"No API","Device_Type":0,"Device_Type_Description":"Type 0","Device_SubType":0,"Device_SubType_Description":""},"device_image":"","UserNote":"","UserAccess":"Any","status_image":"/images/HomeSeer/status/on.gif"}]}
              
              pi@rpi:~ $ curl "http://192.168.1.103/JSON?request=controldevicebyvalue&ref=756&value=0"
              {"Name":"HomeSeer Devices","Version":"1.0","Devices":[{"ref":756,"name":"Garage Work Mode","location":"Garage","location2":"Access Control","value":0,"status":"Off","device_type_string":"","last_change":"\/Date(1499113759547)\/","relationship":0,"hide_from_view":false,"associated_devices":[],"device_type":{"Device_API":0,"Device_API_Description":"No API","Device_Type":0,"Device_Type_Description":"Type 0","Device_SubType":0,"Device_SubType_Description":""},"device_image":"","UserNote":"","UserAccess":"Any","status_image":"/images/HomeSeer/status/off.gif"}]}
              And the log entries
              Code:
              Jul-03 1:29:19 PM	 	Device Control	Device: Access Control Garage Garage Work Mode to Off (0) by/from: CAPI Control Handler
              Jul-03 1:29:15 PM	 	Device Control	Device: Access Control Garage Garage Work Mode to On (100) by/from: CAPI Control Handler
              Edit: one difference between mine & your devices is that mine has two single values while yours has a range.
              Last edited by zwolfpack; July 3, 2017, 03:50 PM. Reason: device difference

              Comment


                #8
                The only thing I have found is that sometimes setting the dv.Misc to SHOW_VALUES needs to be done for the devices to show their current value. You could try setting this to see if it plays better - https://homeseer.com/support/homesee...htm?dvmisc.htm

                Comment


                  #9
                  Hi mrhappy,

                  Thanks for the suggestion, but that's already set. Like I said the devices play nice when operated from scripts using the exact same values & commands. They only play dead when addressed through JSON.

                  Cheers,
                  Alex

                  Originally posted by mrhappy View Post
                  The only thing I have found is that sometimes setting the dv.Misc to SHOW_VALUES needs to be done for the devices to show their current value. You could try setting this to see if it plays better - https://homeseer.com/support/homesee...htm?dvmisc.htm

                  Comment


                    #10
                    I'm at a loss too. Not the faintest idea what could cause this. The device I'm using as example has a range, but there's others (status Online/On Battery/Unknown) with single values as well. Same issue.

                    I've now written a little plugin to pick up the log messages and set the devices accordingly from the plugin. Extremely odd and complicated solution, but it works for now. Still irks me, though...

                    Cheers,
                    Alex

                    Originally posted by zwolfpack View Post
                    Ran the following and it controlled the device as expected. I'm at a loss...

                    Code:
                    pi@rpi:~ $ curl "http://192.168.1.103/JSON?request=controldevicebyvalue&ref=756&value=100"
                    {"Name":"HomeSeer Devices","Version":"1.0","Devices":[{"ref":756,"name":"Garage Work Mode","location":"Garage","location2":"Access Control","value":100,"status":"On","device_type_string":"","last_change":"\/Date(1499113755304)\/","relationship":0,"hide_from_view":false,"associated_devices":[],"device_type":{"Device_API":0,"Device_API_Description":"No API","Device_Type":0,"Device_Type_Description":"Type 0","Device_SubType":0,"Device_SubType_Description":""},"device_image":"","UserNote":"","UserAccess":"Any","status_image":"/images/HomeSeer/status/on.gif"}]}
                    
                    pi@rpi:~ $ curl "http://192.168.1.103/JSON?request=controldevicebyvalue&ref=756&value=0"
                    {"Name":"HomeSeer Devices","Version":"1.0","Devices":[{"ref":756,"name":"Garage Work Mode","location":"Garage","location2":"Access Control","value":0,"status":"Off","device_type_string":"","last_change":"\/Date(1499113759547)\/","relationship":0,"hide_from_view":false,"associated_devices":[],"device_type":{"Device_API":0,"Device_API_Description":"No API","Device_Type":0,"Device_Type_Description":"Type 0","Device_SubType":0,"Device_SubType_Description":""},"device_image":"","UserNote":"","UserAccess":"Any","status_image":"/images/HomeSeer/status/off.gif"}]}
                    And the log entries
                    Code:
                    Jul-03 1:29:19 PM	 	Device Control	Device: Access Control Garage Garage Work Mode to Off (0) by/from: CAPI Control Handler
                    Jul-03 1:29:15 PM	 	Device Control	Device: Access Control Garage Garage Work Mode to On (100) by/from: CAPI Control Handler
                    Edit: one difference between mine & your devices is that mine has two single values while yours has a range.

                    Comment


                      #11
                      What's your HS3 set up? OS, HS patch level, curl version, mono, etc?
                      Are you using any special/accented characters in your names?
                      Len


                      HomeSeer Version: HS3 Pro Edition 3.0.0.435
                      Linux version: Linux homeseer Ubuntu 16.04 x86_64
                      Number of Devices: 633
                      Number of Events: 773

                      Enabled Plug-Ins
                      2.0.54.0: BLBackup
                      2.0.40.0: BLLAN
                      3.0.0.48: EasyTrigger
                      30.0.0.36: RFXCOM
                      3.0.6.2: SDJ-Health
                      3.0.0.87: weatherXML
                      3.0.1.190: Z-Wave

                      Comment


                        #12
                        Hi Iveatch,

                        My HS 3.0.0.318 runs on Windows 10 Pro 1607. NUT pushes the values from a Raspberry Pi 1 with Raspbian, latest patch level. I've tried the exact same URLs from other machines as well, like directly from Windows Chrome/FF/IE - always the same result. According to the log everything is working fine, but the devices don't seem to care. Script commands setting the same devices/values work fine (and result in the same log entries!).

                        Cheers,
                        Alex

                        Originally posted by lveatch View Post
                        What's your HS3 set up? OS, HS patch level, curl version, mono, etc?
                        Are you using any special/accented characters in your names?

                        Comment


                          #13
                          Are the problem devices ones that you manually created, or were they created by a plugin or some other means? Do all devices on your system misbehave or just some?

                          Comment


                            #14
                            I might have to start my old windows copy of HS3 to play.

                            What plug-ins do you have installed?
                            Have you tested with all plug-ins disabled?

                            This post got me thinking outside the box and reaching for something ... https://forums.homeseer.com/showthread.php?t=189876 . Could the json dll you have be old and missing some functions? Scan your HS pc for the dll referenced in the above post and confirm all are the same size and date/time. Again, just going out on a limb reaching for anything close.
                            Len


                            HomeSeer Version: HS3 Pro Edition 3.0.0.435
                            Linux version: Linux homeseer Ubuntu 16.04 x86_64
                            Number of Devices: 633
                            Number of Events: 773

                            Enabled Plug-Ins
                            2.0.54.0: BLBackup
                            2.0.40.0: BLLAN
                            3.0.0.48: EasyTrigger
                            30.0.0.36: RFXCOM
                            3.0.6.2: SDJ-Health
                            3.0.0.87: weatherXML
                            3.0.1.190: Z-Wave

                            Comment


                              #15
                              Thats the funny thing... I control lots of devices through JSON, mainly through Alexa/ha-bridge. They all work and show status and all. the only ones that misbehave are my UPS ones. I've tried creating them manually and via script like this

                              Code:
                              dvc = hs.GetDeviceByRef(ref)
                              dvc.Address(hs) = IFACE_NAME
                              dvc.Device_Type_String(hs) = "vUPS Load"
                              
                              Dim DT As New DeviceTypeInfo
                              DT.Device_API = DeviceTypeInfo.eDeviceAPI.No_API
                              DT.Device_SubType_Description = "UPS Load"
                              dvc.DeviceType_Set(hs) = DT
                              dvc.Interface(hs) = IFACE_NAME
                              dvc.InterfaceInstance(hs) = ""
                              dvc.Location(hs) = IFACE_NAME
                              dvc.Location2(hs) = "Monitoring"
                              dvc.Relationship(hs) = Enums.eRelationship.Child
                              dvc.ScaleText(hs) = "%"
                              
                              dv.AssociatedDevice_Add(hs, ref)
                              dvc.AssociatedDevice_ClearAll(hs)
                              dvc.AssociatedDevice_Add(hs, dv.Ref(hs))
                              
                              ' add Controls
                              Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Both)
                              Pair.PairType = VSVGPairType.Range
                              Pair.RangeStart = 0
                              Pair.RangeEnd = 100
                              Pair.RangeStatusSuffix = " " & VSPair.ScaleReplace
                              Pair.RangeStatusDecimals = 0
                              Pair.IncludeValues = True
                              Pair.HasScale = True
                              hs.DeviceVSP_AddPair(ref, Pair)
                              		
                              'Add Graphics
                              GPair = New VGPair
                              GPair.PairType = VSVGPairType.Range
                              GPair.RangeStart = 0
                              GPair.RangeEnd = 100
                              GPair.Graphic = "/images/HomeSeer/status/Electricity.png"
                              hs.DeviceVGP_AddPair(ref, GPair)
                              
                              dvc.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES)
                              dvc.Status_Support(hs) = False
                              Cheers,
                              Alex

                              Originally posted by zwolfpack View Post
                              Are the problem devices ones that you manually created, or were they created by a plugin or some other means? Do all devices on your system misbehave or just some?

                              Comment

                              Working...
                              X