Button with MQTT Discovery

I would like to create a doorbell device, running on RPI. I am using Python and Paho to send MQTT messages to HA.

I have managed to configure a button using MQTT discovery and the topic

homeassistant/button/doorbell/config

and the following msg:

‘name’:‘doorbell’, ‘unique_id’:‘doorbell_button’, ‘payload_press’:‘press’, ‘command_topic’:‘homeassistant/button/doorbell/commands’

On the integration page I can see the new entity. Great.

My question is what topic & message do I need to send/publish to the MQTT server to trigger the button?

I went over a bunch of options but the button is never updated.

On the developer page I can click on the entity and click the PRESS button and that updates the ‘state’ timestamp, not sure if that means anything?

Thanks!

If you use the mosqitto within HA you can go into integrations - mosqitto broker and start listening to a topic. In your example homeassistant/button/doorbell/config

@JackDrake thanks but I think I’m past that stage. I have the integration working just fine.

My question is how do I send a “press” command to the MQTT server from the RPI?

I assume the topic should be the command_topic that was specified in the config message?
What should I put in the message itself?

I think MQTT button does the opposite of what you are trying to do.

The mqtt button platform lets you send an MQTT message when the button is pressed in the frontend or the button press service is called. This can be used to expose some service of a remote device, for example reboot.
MQTT button - Home Assistant

The way you want to go is from doorbell → RPI → MQTT SEND TOPIC → HA MQTT Listen to topic ?

I would assume a RPI is a little bit oversized compared to ESP32? However, this this guy uses a M5Paper with integrated buttons, maybe the example python code from his github might be helpful?

Thanks ondras, you are probably right. Reading this again it probably only works one way from HA to a device.

Yes, that’s the idea. So doorbell is just a push button connected to one of the RPI pins. Button pressed → send a message to HA → run some automation.

The intention is for RPI to be running a few other services: doorbell, irrigation system, cat feeder, garage door control, plus whatever comes in the future if it can still handle it. The ESPs are nice but each one needs a power source and I find it to be too exhausting. I still haven’t figured out the complete structure of how the RPI will run (single script, multiple scripts, it will also require MCP23017 so adds more complexity).

In any case …

I actually found a way of doing what I want by following the MQTT Device Trigger guide, which creates a device with command/triggers and a quicker path to automation, but it’s still not perfect because entities created are still decoupled from the device, so still searching around.