I’d like to toggle the hammam on & off.
Unfortunately, the switch doesn’t get the status from state_topic & value_template.
Maybe my understanding is wrong
Thank for you support
Here the yaml file I wrote :
customize:
# Add an entry for each entity that you want to overwrite.
sensor.etat_hammam:
icon: mdi:hot-tub
friendly_name: Etat Hammam
device_class: Binary_Sensor.none
sensor device_1:
- platform: mqtt
name: "Etat_Hammam"
state_topic: "homehorn"
value_template: "{{ value_json.Etat_hammam }}"
switch:
- platform: mqtt
name: "Hammam"
state_topic: "homehorn"
value_template : "{{ value_json.Etat_hammam }}"
command_topic: "device_1"
payload_on: "{\"device\":1,\"function\":5,\"cmd\":\"ON\"}"
payload_off: "{\"device\":1,\"function\":5,\"cmd\":\"OFF\"}"
state_on: "Marche"
state_off: "Arret"
The default values for state_on: and state_off: are ON and OFF (see documentation). That is precisely what Etat_hammam normally reports so there is no need for state_on: "Marche" and state_off: "Arret" in the switch’s configuration. Remove them.
Even without state_on and off I can’t get the status in the switch but it works now if I display the entity in a card.
I triple checked the topic and value template.
Can I use value_template in a switch ? Json doesn’t like to work …
After spending hours on google I understood that “payload_on” & “payload_off” was not well used. I just removed it
but didn’t get why the state doesn’t work in the switch where as it works perfectly in the sensor with exactly the same state_topic or value_template…
Any idea ?