I am using Adafruit feather Huzzah (ESP8266 board) and a relay to switch an AC bulb using toggle switch on HA. It works really well. Now i came across a situation when the user donot have a cell phone with him and he wants to switch this bulb. There is no way he can do it.
In order to create a way i think i can connect a SPDT switch to one of the pin of esp8266 and monitor it in esp8266 software and when button is pressed it should turn on/off the relay. Also if i turn on the realy using the physical switch the state of toggle button on the HA page should also change. so that i can now turn the bulb off from the on screen button as well as from the physical button
I supposed that you use MQTT to control your relay? If it’s the case, just make your ESP publish an MQTT message whenever the button is pressed.
Than use the toggle function in an automation:
automation:
- alias: Toggle lamp status using button
trigger:
platform: mqtt
topic: home/MQTTButton1
action:
service: switch.toggle
entity_id: switch.your_lamp_entity_id
@Kareem for your solution I suppose the button would have to be aware of the relay state to send either 0 or 1 as a payload.
@touliloup not necessarly I forgot to attach this but you are right it needs the automation rule and look much logical to write it the way you did with a toggle thx for the advise
Good, that makes things straightforward. Does the current set up return a response to the mqtt message from HA, or does HA currently assume that the switch has been activated?
If it replies with a message, then turning the new switch on the esp8266 needs to send this message. If it doesn’t currently, we need to make it do so (which is more reliable anyway).
HA assume the switch has been activated when it receive the MQTT publish from the ESP so HA should trigger on the real state of your switch.
switch pressed >Input detected by the ESP >ESP MQTT publish > HA MQTT subscribe > HA trigger the event (automation)
If you got a 2 position switch on/off (up/down) you should maybe do things a bit different and maybe wire 2 inputs on your ESP and punlish 2 diferent MQTT message depending on which input have been detected.
how can i integrate 1 button to ON and OFF in home assistant with state showing ON/OFF. I can only press to ON with state in home assistant showing ON, but when I press OFF, it does not respond.
I try using physical remote and can only show ON in home assistant.
My push button only support single push button Data in Tasmota.
I’m using MQTT over the rf bridge