I have been trying for a few days now and cannot understand how to do this. Please help. I have implemented a rest call that returns this XML
<LL control="dev/sps/io/1f473a6a-0093-f22a-fffff11ca80f26ac/state" value="21.5" Code="200"/>. Within Home Assistant this gets automatically converted to this JSON value {"LL":{"@control":"dev/sps/io/1f473a6a-0093-f22a-fffff11ca80f26ac/state","@value":"20.5","@Code":"200"}} without me doing anything specific. I want to extract the temperature value itself (20.5 in the example) but cannot work out how to do it. Can anyone please advise?
I would assume this will work:
"{{ value_json['LL']['@value'] }}"
I have tried that - here is the code I used:
- platform: rest
name: lox_temp_api
authentication: basic
username: !secret loxone_user
password: !secret loxone_password
resource: http://192.168.1.50/dev/sps/io/1f473a6a-0093-f22a-fffff11ca80f26ac/state
method: GET
scan_interval: 600
json_attributes_path: "$.LL"
json_attributes:
- control
- value
- code
- platform: template
sensors:
temp_value:
friendly_name: "Living Room Temp"
value_template: "{{ value_json['LL']['@value'] }}"
but all I get back is the sensor value shoing as “Unavailable”
That’s because it’s two different sensors.
the value_json is not linked to the other sensor.
What does the sensor sensor.lox_temp_api look like in developer tools?
What @Hellis81 said. To have the Rest sensor report the value, add:
value_template: "{{ value_json['LL']['@value'] }}"
device_class: temperature
unit_of_measurement: '°C'
Alternatively, your template sensor (which is in legacy format) should read:
value_template: "{{ state_attr('sensors.lox_temp_api','value') }}"
…assuming the Rest sensor is working.
Hooray Thanks Guys - I hadn’t understood that I was creating two different sensors. I have now changed the code so it reads as follows:
- platform: rest
name: lox_temp_api
authentication: basic
username: !secret loxone_user
password: !secret loxone_password
resource: http://192.168.1.50/dev/sps/io/1f473a6a-0093-f22a-fffff11ca80f26ac/state
method: GET
scan_interval: 600
value_template: "{{ value_json['LL']['@value'] }}"
device_class: temperature
unit_of_measurement: '°C'
and it now successfully sets the sensor named lox_temp_api to the actual temperature value itself.
Your assistance has been very much appreciated. I am new to Home Assistant and still struggling to get my head around the scripting.