teufelm
(Teufelm)
September 27, 2024, 12:35pm
1
Hi!
I’m trying to read the actual value 592 from an XML file, or alternatively the strValue 59.
<eta version="1.0">
<value advTextOffset="0" unit="°C" uri="/user/var/264/10111/0/0/12271" strValue="59" scaleFactor="10" decPlaces="0">592</value>
</eta>
I tried a lot in the configuration.yaml File, but none of my tries were sucesfully.
e.g.
sensor:
- platform: rest
resource: http://10.9.8.94:8080/user/var/264/10111/0/0/12271
name: "Temperatur"
value_template: "{{ value_json['eta']['value'] }}"
unit_of_measurement: "°C"
scan_interval: 60
KInd Regards Martin.
Does the response header for that HTTP request set the Content-Type to ‘text/xml
’, ‘application/xml
’ or ‘application/xhtml+xml
’? If not, it will not be converted to JSON and you will not be able to use a rest sensor for this task.
If it is setting that header, you might try enabling debug logging on the rest
component and see if there are any helpful messages in your log.
If it does not set that header, then you could use a command line sensor . Though there are certainly more elegant and robust ways, this should do the trick:
curl http://10.9.8.94:8080/user/var/264/10111/0/0/12271 | grep -oE '>\d+<' | grep -oE '\d+'
teufelm
(Teufelm)
September 30, 2024, 10:27am
3
atlflyer:
Does the response header for that HTTP request set the Content-Type to ‘text/xml
’, ‘application/xml
’ or ‘application/xhtml+xml
’? If not, it will not be converted to JSON and you will not be able to use a rest sensor for this task.
yes, response is application/xml
.
I got it via the Developer-Tools.
curl http://10.9.8.94:8080/user/var/264/10111/0/0/12271 | grep -oE '>\d+<' | grep -oE '\d+'
returns 535
If it is application/xml the value_template expression shoud be ok?
value_template: "{{ value_json['eta']['value'] }}"
teufelm
(Teufelm)
September 30, 2024, 6:33pm
5
i solved it now with the following:
sensor:
- platform: rest
name: "Temperatur Warmwasser"
resource: "http://10.9.8.94:8080/user/var/264/10111/0/0/12271"
value_template: "{{ value_json['eta']['value']['@strValue'] | int }}"
unit_of_measurement: "°C"
scan_interval: 60