Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95370

Extrating json value from attribute with "#" and "@"

$
0
0

@orc.trial wrote:

hi
need some help figuring out how to extract value from the following response from a http sensor:
http request:

http://192.168.1.30:8688/controller/rest/devices/Zooz%20dimmer%20zen22/status?name=zooz%20dimmer%20a%20switch%20status

Raw response:

<sensors><sensor name="zooz dimmer a switch status">off</sensor></sensors>

I have this setup as a rest sensor in HA

sensor:
  - platform: rest
    #resource: http://192.168.1.30:8688/controller/rest/devices/Zooz%20dimmer%20zen22/status?name=zooz%20dimmer%20a%20switch%20status&name=zooz%20dimmer%20a%20switch%20status
    resource: http://192.168.1.30:8688/controller/rest/devices/Zooz%20dimmer%20zen22/status?name=zooz%20dimmer%20a%20switch%20status
    name: Dinning Light Status 
    #json_attributes: '{{sensor.["#text"]}}'
    value_template: '{{sensor."#text" }}'

without the value_template, on the UI it is displaying status as

{"sensors": {"sensor": {"@name": "zooz dimmer a switch status", "#text": "off"}}}

trying to figue out how to extract just the status and display “off” and not the entire raw response

value:template does not seem to like “#”

error message is



    Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected name or number) for dictionary value @ data['sensors']['dinning_light_status']['value_template']. Got '{{sensor.["@name"] }}'. (See ?, line ?).
    Invalid config for [sensor.rest]: invalid template (TemplateSyntaxError: expected name or number) for dictionary value @ data['value_template']. Got '{{sensor.["#text"] }}'. (See ?, line ?).
    Invalid config for [sensor.rest]: invalid template (TemplateSyntaxError: expected name or number) for dictionary value @ data['value_template']. Got '{{sensor."#text" }}'. (See ?, line ?).

any ideas how to extract and display just the on / off value?

i understand the @ and # are being added as per:


https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95370

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>