Related to another thread I have going, I’m looking to set up a simple button for my daughter to be able to press to turn her light on or off. Since there is essentially nothing out there that is wireless and battery powered that’ll fit the bill (they all seem to have issues that make them ‘not great’ for a toddler), I’ve taken to wiring up a first gen Raspberry pi that I have sitting around with a button and scripts to interpret that button press and then publish a mqtt event.
I’ve made remarkable headway (for me, lol), but I’m not sure it’s the best or really proper way to do it.
I’ve got the pi that has the button publishing to itself, and I have mqtt in HA set up to point to that pi with the topic and payload, and I have a trigger set to activate a scene and amazingly (again, for me) it works. BUT. I’m not sure this is the best (or even right) way to do the mqtt messages, and I don’t want to activate a scene, but instead toggle a light state (If it’s off, turn it on, it’s on, turn it off). The only possible challenge with that requirement (toggling the state) is most of my switches are the Leviton DZMX1-1LZ, which do not send the instant status updates back to the controller if activated manually. I’ve read that they eventually do, but my experience has been that HA has no clue if they have been turned on or off manually and the status never updates. I have not figured out how to make HA poll the status of the devices to update them if they’ve changed. I have a few of the Vizia RF line of z-wave switches that DO send the instant status update when operated manually, so if I have to get one of those to make this work how I want, so be it (I do want to eventually replace the DZM switches with the Vizia RF switches).
I would THINK the better approach with the mqtt messages would be to have HA set up to look to itself, and have the pi publish it’s messages to HA. It seems like setting HA to point to the pi with the button would be pigeon-holing it to not be able to interface with other mqtt sources, such as my Open Energy Monitor setup, if I wanted it to get data from that, for example.
One other part, which I’m no sure where the best place to address it would be, is since this is for my Toddler daughter, It would be a good idea to have some kind if ‘sleep’, where if you press the button, subsequent presses will be ignored for a period of time (say 15 seconds), so she can’t be turning her light on and off 50 times a minute. Is this something that could be handled by HA, or should it be done on the button side?
Does anyone have any advice on how to best set up the mqtt messaging, and how to get the button press to toggle a dimmer state, or if need be, have HA poll the switch, and activate the opposite scene, so if the status is ‘off’, it activates the ‘Turn light on’ scene, and if the status is ‘on’, it activates the ‘Turn light off’ scene?
Edit: Probably wouldn’t hurt to include my relevant config settings.
configuration.yaml:
mqtt:
broker: 192.168.1.17
port: 1883
client_id: home-assistant-1
automation.yaml:
- alias: 'Toggle Room Light'
trigger:
platform: mqtt
topic: hass/light/Room
# Optional
payload: 'Toggle'
action:
service: scene.turn_on
entity_id: scene.Office_Lights_Off
I’m using my office lights for testing since that’s where I’m working and my daughter is sleeping :).