marek76
(marek)
1
why doesn’t this code do what it’s supposed to?
{% set value_json = {'Battery_State_Test': 1} %}
{% if states('value_json.Battery_State_Test') == 1 %}
ok
{% else %}
nok
{% endif %}
{{ (value_json.Battery_State_Test) }}
I need an explanation because I don’t understand it
123
(Taras)
2
The states()
function is for reporting the state
value of an entity, not a Jinja2 variable.
Reference
Templating - States
Corrected version:
{% set value_json = {'Battery_State_Test': 1} %}
{% if value_json.Battery_State_Test == 1 %}
ok
{% else %}
nok
{% endif %}
{{ (value_json.Battery_State_Test) }}
What is it that you attempting to do?
marek76
(marek)
3
I will try to change the number to text for the entity
victron venus sends battery charge status as number 0-idle , 1-charge, 2-discharge
i use mqtt for that
victron integration does not go as expected
123
(Taras)
4
If it reports a number and you want to display the text that corresponds to the number, you can do it like this:
{% set value_json = {'Battery_State_Test': 1} %}
{{ ['idle', 'charge', 'discharge'][value_json.Battery_State_Test] }}
marek76
(marek)
5
so this is unbelievable. man, I have a beer for you
this is exactly what i need
thx
1 Like