I have my laptop reporting power to HA via MQTT (iot-link) and have a device in the UI with the various sensors listed. I am also using the command functionality in iot-link to suspend the laptop from automations. I have done this by creating an mqtt button in my config that send the appropriate topic.
All of this works fine.
However, what I would like to do is add the button entity to the device so that they both appear in the UI together under the same device with button press listed under controls.
But I have to admit, I am struggling. Can anyone link to any other guides on how to publish MQTT discovery messages to add an extra entity to a device?
It’s done exactly like I explained in the linked topic. In order for the discovery message to add an entity (i e. a button entity) to an existing device, the discovery message must contain the same device parameters as the device.
Go to Settings > Devices & Services > Devices
Click on the device you want to add a button to.
Take note of the device’s parameters displayed in the upper left corner of the first card.
Example:
Here’s one of my devices that was created via MQTT Discovery.
Check if the payload that is published to the availability topic is a retained message. If it is then Home Assistant receives immediately upon connecting to the MQTT broker. If it isn’t then, yes, you would have to wait until it’s published.