Hi. Im have a problem with my climete state in mqtt
In can read and set all data, except state
My MQTT returns O if off and 1 if heat.
How can I use mode_state_tempate to correct 0 to “off” and 1 to “heat”
Here is my code:
Can you edit your post, and use the Code button in the editor to format your YAML correctly.
It’s the button that looks like this: </> (because until you do, we can’t tell if the indentation is correct)
EDIT: It’s possible that Home Assistant is seeing the received value as a string not a number, so either use:
any ideas what could be wrong?
Double checked if mode_state_topic is ok (via MQTT explorer), but even if I made some error there, the template should return “off” but it dont.
The problem is due to the double-quotes used in the mode_state_template. They are are used literally and therefore the string the template produces includes them.
Change it to this:
mode_state_template: >-
{% if value|int(0) == 1 %}
heat
{% else %}
off
{% endif %}
Or simply do this (quotes are not handled literally when used like this in an inline-if statement):
mode_state_template: "{{ 'heat' if value|int(0) == 1 else 'off' }}"