MQTT device to receive state updates from other entities

Exploring HA, will build a device that will have 2-3 buttons, each button with signal led. Target is to trigger HA automation with the button press. Connection via MQTT integration.

  • Example 1: Button 1 will Toggle the state of the HUE lamp, but this lamp can also be controlled by the phone app or other HA automations. LED on the device shall be ON if hue lamp is ON, regardless of who sets the state.

  • Example 2: Button 2 will turn on (set on?) the scene. I’d like to keep the LED on until all the lights are set as defined by the scene, and off when one of them isn’t at the “scene” level anymore.

Is there a systematic way to receive updates to my device when another entity state changes, or do I need to create an automation that is triggered by hue lamp state change and manually send MQTT packet to my device about the state, that will then turn on/off the LED?

Thanks

This would be easiest if the device had some power metering, so it senses itself if the lamp is on.

That will be a difficult one. The only state is a scene has is ‘scening’, so you will have to track all the lights individually.

I think esphome will do all this, and has the bonus of the API as an alternative to MQTT.

In fact my device would have no power part, just few buttons and same amount of leds. Led shall be ON, when entity this button controls, is ON, of OFF otherwise. The idea is that user knows the state of an entity this it controls.

HA shall be the one to decide what the buttons do when pressed.

As for scene, I agree it may be a bit difficult.

For button/led combination, my best guess is that HA will have to implement 2 automations.

  • Automation 1: Toggle the entity state when pressed, trigger is the button
  • Automation 2: Send MQTT message when toggled entity changes the state. Entity state change shall be the trigger.