Hello
I use JSON file to get init values in automations.
the sensor works well, data are seen in TEMPLATE UI:
{{states.sensor.test_json_command_line.attributes.zone}}
give the good value:
bureau
prefered ‘new’ syntax:
{{state_attr('sensor.test_json_command_line','zone')}}
give the good value (but this is first level of JSON file):
bureau
Again:
{{states.sensor.test_json_command_line.attributes.radiateur.rad2}}
give again the good value:
{'nom': 'bureau2', 'pilote': '100', 'puiss': '1500', 'priorite': '10'}
my (double) question:
1 How transform
{{states.sensor.test_json_command_line.attributes.radiateur.rad2}}
in the ‘state_attr’ syntax ? (this is second level of JSON file) like:
{{state_attr('sensor.test_json_command_line','??? radiateur.rad2 ???')}}
2 How make iteration to read second or third level of JSON, EG (pseudo code):
for each radiateur
if {{states.sensor.test_json_command_line.attributes.radiateur.rad(i).pilote}}==1
set command inverse
else
set command direct
I have read many doc/posts without success
EDIT
found answer to point 1
{{ state_attr('sensor.test_json_command_line', 'radiateur').rad1 }}
{{ state_attr('sensor.test_json_command_line', 'radiateur').rad1.pilote }}
give good values:
{'nom': 'bureau1', 'pilote': '1', 'puiss': '1000', 'priorite': '10'}
1
point N°2 stay without answer
i try Template looping through state-attributes - #6 by Didgeridrew
with adapted:
{% set rads = state_attr('sensor.test_json_command_line','radiateur') %}
{% for i in range(0, rads | count, 1) %}
{{ rads[i] }}
{% endfor %}
TEMPLATE UI says:
UndefinedError: dict object has no element 0