Hi,
Excuse me if I posted on wrong topic.
I’m new but I’ve googled for an hour and could’nt find reliable answer.
How to toggle a button using mqtt and arduino (esp8266)?
In domoticz i’d send “command” : “toggle” to domoticz/in topic.
I need to “toggle” the wall switch and perform action and don’t want to check if it’s on or off on esp8266 side (cause it’s not reliable).
In domoticz it was just ‘toggle’.
OK, the answer is: there is no “toggle” command in mqtt.
Please leave the answer for other guys moving from Domoticz that are coding by their own.
The key to success is to use “retain” function in HA that allows you to set the last status.
When you have the last status you just create new global bool to control the toggle behaviuor. Something like this:
button press:
if ( debouncer.fell() ) {
if (isOn==false) publikuj(“ON”); else publikuj(“OFF”);
isOn = !isOn;
}
and you set the bool value in callback services like for example:
I just want to help you, things are different in the Home Assistant ecosystem and ESPHome is by far the easiest solution to integrate ESP devices into Home Assistant, as it was made especially for this purpose.
What retain function? MQTT can have payloads with a retained flag, but what is the retain function of HA?