overb
1
Hi! need some help with configuring a value template to extract a temperature value from rest source, the source looks like this:
{“name”:“Temperatur Ute”,“id”:“66”,“className”:“FineOffsetThermometer”,“category”:“Thermometers”,“actions”:[],“attributes”:[{“name”:“Temperature”,“value”:“5.3”,“unit”:“°C”,“readOnly”:true,“default”:true},{“name”:“TimeSinceUpdate”,“value”:“11”,“unit”:“s”,“readOnly”:true},{“name”:“DeviceId”,“value”:“1160”},{“name”:“LogFile”,“value”:""},{“name”:“LastUpdate”,“value”:"17:29:55 2016.11.18 ",“readOnly”:true},{“name”:“K”,“value”:“0.1”},{“name”:“M”,“value”:“0.0”}]}
The variable value i want to extract to home assistant is:“value”:“5.3”,“unit”:“°C”.
//overb
ih8gates
(Scott Reston)
2
I think you want a RESTful sensor:
You can use templating to isolate values.
overb
3
RESTful sensor is another way to get the temperatur value i already got,
It is the templating to isolate the value i need help with
ih8gates
(Scott Reston)
4
You can experiment with the templates dev tool (bottom of HASS sidebar - looks like a sheet of paper with < > on it). This will extract the value:
{% set json = {“name”:“Temperatur Ute”,“id”:“66”,“className”:“FineOffsetThermometer”,“category”:“Thermometers”,“actions”:,“attributes”:[{“name”:“Temperature”,“value”:“5.3”,“unit”:“°C”,“readOnly”:true,“default”:true},{“name”:“TimeSinceUpdate”,“value”:“11”,“unit”:“s”,“readOnly”:true},{“name”:“DeviceId”,“value”:“1160”},{“name”:“LogFile”,“value”:“”},{“name”:“LastUpdate”,“value”:"17:29:55 2016.11.18 ",“readOnly”:true},{“name”:“K”,“value”:“0.1”},{“name”:“M”,“value”:“0.0”}]} %}{{ json.attributes[0].value }}
This get the units:
{% set json = {“name”:“Temperatur Ute”,“id”:“66”,“className”:“FineOffsetThermometer”,“category”:“Thermometers”,“actions”:,“attributes”:[{“name”:“Temperature”,“value”:“5.3”,“unit”:“°C”,“readOnly”:true,“default”:true},{“name”:“TimeSinceUpdate”,“value”:“11”,“unit”:“s”,“readOnly”:true},{“name”:“DeviceId”,“value”:“1160”},{“name”:“LogFile”,“value”:“”},{“name”:“LastUpdate”,“value”:"17:29:55 2016.11.18 ",“readOnly”:true},{“name”:“K”,“value”:“0.1”},{“name”:“M”,“value”:“0.0”}]} %}{{ json.attributes[0].unit }}
Does that help?
1 Like
overb
5
Thank you! That’s exactly what i was looking for!
overb
6
I have managed filter out the temp value with a template in dev tool but still got some issues when adding the template to configuration.yaml.
The command i use in command_line is: curl --header “Accept:application/json” 192.168.1.139:8020/rest/items/85 | python -m json.tool | grep value
which gives me the output:
“value”: “5.3”
“value”: “42”
“value”: “1160”
“value”: “”
“value”: "10:36:18 2016.11.20 "
“value”: “0.1”
“value”: “0.0”
Then i try to filter out the actuall temperature value with: {{ states.sensor.temperatur_ute.state.split()[1] }} in dev tool which give me: “5.3”.
When adding the template to config.yaml i get this error:
ERROR:homeassistant.helpers.template:Error parsing value: ‘None’ has no attribute ‘state’ (value: “value”: “5.3”
“value”: “42”
“value”: “1160”
“value”: “”
“value”: "10:36:18 2016.11.20 "
“value”: “0.1”
“value”: “0.0”, template: {{ states.sensor.temperatur_ute.state.split()[1] }})
any ideas?
ih8gates
(Scott Reston)
7
I think I’m going to need some formatting to read what you’ve got here. And the config from your YAML that you’re using.
What’re you using split for? Are you actually splitting a state? Don’t you need to isolate values from an attribute?