MQTT Button setup

My wife is very reluctant to let me put a wifi light bulb in the kitchen. Even though she loves the other ones around the house and their ability to come on or go off automatically or change colour at certain times. Something about the kitchen is just too hard for her. Even yelling out to the Google Home seems to be too much trouble.

So here is my plan. Setup a simple MQTT button, that I can stick on the wall next to the light switch (can’t play with the actual switch as we rent this place). With a button attached to the ESP8266 that simply connect and sends out a MQTT message “dev/button/1/press” whenever the button is pressed.

From there I want to write an automation that simply states that when the button is pressed, and the light is currently off, that it will turn the light on to a certain scene (LIFX bulb).

Another automation would turn off the light if the button is pressed and the light was already on.

Most of the time this will be unused as the light will have a schedule to go on and off just like the other bulbs in the house. It’s really a just in case button to keep the wife happy.

Question I have is what is the best way to set this up in my config.yaml file. The MQTT button only has one state to report, “press”. No off or on. Can I use Switch or would Sensor or even Binary Sensor be more appropriate?

You can use a MQTT Sensor, and set in the config thé « expire_after » at 1 second. Create an automation with a trigger on the state of thid sensor from off to on. You can call the service light.toggle as action

1 Like

thanks, will go with that

The xiaomi switches are quite cheap.

1 Like

I would go with an automation triggered by the MQTT message, rather than creating a separate sensor. The action would then be to toggle the light.

Never thought about doing that, very good idea and I have it working now.

Thanks.

1 Like