HTTP Device - URL to get value (JSON parse)

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
iblis
Posts: 11
Joined: 21 Jun 2015 15:44

HTTP Device - URL to get value (JSON parse)

Post by iblis »

Hi gents,

I'm trying to use the "HTTP Device" app to control a remote device using GET and JSON.

I can easily turn the remote device On or Off by using the following URLs.

On: http://IP_ADDRESS/JSON?request=controldevicebyvalue&ref=58&value=255

Off: http://IP_ADDRESS/JSON?request=controldevicebyvalue&ref=58&value=0

But when it comes to the "URL to get value" option I'm having difficulties to parse the correct value from the url to the HTTP Device.

The URL I use for getting the device value is this : http://IP_ADDRESS/JSON?request=getstatus&ref=58

that gives me this information:

Code: Select all

// 20150621151221
// http://IP_ADDRESS/JSON?request=getstatus&ref=58

{
  "Name": "HomeSeer Devices",
  "Version": "1.0",
  "Devices": [
    {
      "ref": 58,
      "name": "Spotlights",
      "location": "TV Stue",
      "location2": "Lys",
      "value": 0,
      "status": "Off",
      "device_type_string": "Z-Wave Switch Multilevel",
      "last_change": "/Date(1434841201998)/",
      "relationship": 3,
      "hide_from_view": false,
      "associated_devices": [
        
      ],
      "device_type": {
        "Device_API": 4,
        "Device_API_Description": "Plug-In API",
        "Device_Type": 999,
        "Device_Type_Description": "Plug-In Root Device",
        "Device_SubType": 17,
        "Device_SubType_Description": ""
      },
      "device_image": ""
    }
  ]
}
The information I want to parse is the ""value": 0" field so when the value is 0 the light is off, when it is 255 the light is on. Can anyone show me the correct way of doing this using javascript.

My next question will be on how to do the dimming devices (switchMultilevel), but first things first. ;)

Thanks
User avatar
PoltoS
Posts: 7571
Joined: 26 Jan 2011 19:36

Re: HTTP Device - URL to get value (JSON parse)

Post by PoltoS »

Example similar to the one mentioned in the helper line for the Getter field:

$S.Devices.value ? 'on' : 'off'

UPD: $ changed to $$
iblis
Posts: 11
Joined: 21 Jun 2015 15:44

Re: HTTP Device - URL to get value (JSON parse)

Post by iblis »

PoltoS wrote:Example similar to the one mentioned in the helper line for the Getter field:

$.Devices.value ? 'on' : 'off'
Thanks for your input PoltoS.

Unfortunately your command did not work and gave me this error in the log when executed:

Code: Select all

[2015-06-22 02:53:59.019] [E] [core] Callback execution error: ReferenceError: $ is not defined
    at eval (eval at <anonymous> (automation/modules/HTTPDevice/index.js:132:37), <anonymous>:1:1)
    at automation/modules/HTTPDevice/index.js:132:32
    at Function.http.request.success (automation/modules/HTTPDevice/index.js:133:23)
User avatar
PoltoS
Posts: 7571
Joined: 26 Jan 2011 19:36

Re: HTTP Device - URL to get value (JSON parse)

Post by PoltoS »

Excuse, fixed my answer. Should be $$ (there is a but in the UI that it shows $$ string as $ in helper field.)
Wikibear
Posts: 102
Joined: 01 Jul 2016 14:10

Re: HTTP Device - URL to get value (JSON parse)

Post by Wikibear »

Can anybody explane how i did get a result as this back?

{"result":false,"success":true}

I try:

$$.result === 'true' ? 'on' : 'off'

but this doesn't work. Any suggestions?
Greatings from the noob
User avatar
PoltoS
Posts: 7571
Joined: 26 Jan 2011 19:36

Re: HTTP Device - URL to get value (JSON parse)

Post by PoltoS »

$$.result === true ? 'on' : 'off'

or just

$$.result ? 'on' : 'off'
Wikibear
Posts: 102
Joined: 01 Jul 2016 14:10

Re: HTTP Device - URL to get value (JSON parse)

Post by Wikibear »

i use now $$.result ? 'on' : 'off' and set a checkbox for: Update value on action. But the http devices response only if i klick on/off switch. No response if i click on clickable icon symbol.
Greatings from the noob
User avatar
PoltoS
Posts: 7571
Joined: 26 Jan 2011 19:36

Re: HTTP Device - URL to get value (JSON parse)

Post by PoltoS »

On clickable toggle only the on ON and on OFF URLs are requested, the value should be updated via request to getter (that will be evaluated by your string)
DrHeck
Posts: 5
Joined: 04 Jun 2019 16:50

Re: HTTP Device - URL to get value (JSON parse)

Post by DrHeck »

Hi,
i have the same problem.
I have made a binary switch (for a Denon AVR Receiver Zone 2) for powering ON or OFF (it works).
The Status URL returns a xml file:
How can i get the status (<Power><value>OFF</value></Power>)?
i tried $$.item.Power === 'ON' ? 'on' : 'off' , but this does not work...

thanks a lot...
Peter

<?xml version="1.0" encoding="utf-8" ?>
<item>
<Zone><value>TERRASSE
</value></Zone>
<Power><value>OFF</value></Power>
<InputFuncList>
<value>CBL/SAT</value>
<value>DVD</value>
<value>Blu-ray</value>
<value>GAME</value>
<value>AUX</value>
<value>Media Player</value>
<value>iPod/USB</value>
<value>TUNER</value>
<value>NETWORK</value>
<value>TV AUDIO</value>
<value>Bluetooth</value>
</InputFuncList>
<RenameSource>
<value><value>VU+ </value></value>
<value><value>DVD </value></value>
<value><value>Blu-ray </value></value>
<value><value>Game </value></value>
<value><value>AUX </value></value>
<value><value>Apple TV </value></value>
<value><value>iPod/USB</value></value>
<value><value>Tuner</value></value>
<value><value>Online Music</value></value>
<value><value>TV Audio </value></value>
<value><value>Bluetooth</value></value>
</RenameSource>
<SourceDelete>
<value>USE</value>
<value>USE</value>
<value>USE</value>
<value>USE</value>
<value>USE</value>
<value>USE</value>
<value>USE</value>
<value>USE</value>
<value></value>
<value>USE</value>
<value>USE</value>
</SourceDelete>
<InputFuncSelect><value>Favorites</value></InputFuncSelect>
<VolumeDisplay><value>Absolute</value></VolumeDisplay>
<MasterVolume><value>-32</value></MasterVolume>
<Mute><value>off</value></Mute>
</item>
User avatar
PoltoS
Posts: 7571
Joined: 26 Jan 2011 19:36

Re: HTTP Device - URL to get value (JSON parse)

Post by PoltoS »

If you look in HTTP Device hints below the field, you will find an example that is almost exactly what you want.

You need this:

Code: Select all

$$.findOne("/item/Power/value/text()") === "ON" ? "on" : "off"
[may be without /item - please test]
Post Reply