I’m new to HA, so I may not understand correctly how “value_template” works …
I want to get a switch that, when turned on, sets the brightness to 120 units. But since in the topic there may be other values, then for all values greater than 0 - the switch should be interpreted as “on”, with a value of 0 - “off”.
I made a template to interpret the value from the state topic as: if it is greater than 0, then 1, if it is 0, then 0.
But for some reason the switch does not see the value “on” - when the value in the state topic ! = 0.
Here is the code for the switch:
- platform: mqtt
name: "50%"
unique_id: kitchen_ceiling_light_switch
state_topic: "Kitchen/state/brightness"
command_topic: "Kitchen/ctrl/brightness"
payload_on: 120
payload_off: 0
value_template: >
{% if value|int > 0 %}1{% else %}0{% endif %}
state_on: 1
state_off: 0
qos: 0
optimistic: false
retain: true
Thank you!!!