I want to have in my Home Assistant button called Nobody home for different automation purposes (at least to turn off all the lights and some power lines). Every click should toggle switch stated. But it doesn’t work as expected.
in configuration.yaml I created following
switch: !include_dir_list ../entities/switches
in …/entities/switches/nobodyHome.yaml I have this code
Then I open windows MQTT explorer to check what happens when I click the button.
I expect that if current status is ON then after click it should be OFF, then next click ON and so on.
But in reality after connection MQTT explorer shows me that initial state of smarthome/nobodyHome/switch is ON. And every next click just send ON again. So it is never OFF.
What is the problem?
I am newbie in HA and at the moment I have no idea about automations integrated in HA. Under automations I meant that after every click mqtt message must be sent and then my arduino controller should do something.
With this input_boolean I don’t see the way how to send mqtt message. command_topic and payload options are not allowed.
Let’s give your question another try now that I understand what you want (which I should have understood after more careful reading )
The state_topic is the topic that your Arduino device should publish to when it receives an mqtt message from HA, to confirm a state change.
If your Arduino does not publish a state to the state_topic, you can either use the command_topic as the state_topic, or use optimistic mode.
So unless your Arduino publish a state, the following will retain the correct state of your switch:
Basically, your arduino tells the MQTT broker the maximum time it will stay silent until the MQTT broker flags you as unavailable. If for instance the connection from your arduino to the MQTT broker is broken without the Arduino first gracefully disconnects, HA will know that the entity is unavailable.