Generic MQTT notifications

I need a simple example of a generic MQTT payload that sends a message on any state change to any device with a payload or topic identifying the device and the change.

For now, it would be sufficient to get an on/off request or even just “something changed” so I can query for the details though better to have the information in the payload.

If you want all events, maybe MQTT eventstream could do the trick.
Otherwise, I’d just create an automation that triggers on state changes and calls mqtt.publish. You can use trigger variables like this in you payload: {{ trigger.to_state.state }}.
However, triggering an automation for every state change is probably not a good idea. I think you should select only the entities that you need.

Thanks.

This does seem to be what I want. To expedite my learning, can you show this as a topic and payload for MQTT, or do I need to set configuration information elsewhere?

Home Assistant is configured partially from the UI via config flows and partially via a file called configuration.yaml.
What you’re referring to is probably MQTT discovery. I don’t think you’ll be able to configure MQTT eventstream that way.
Instead, you’ll need to add it to your configuration.yaml:

mqtt_eventstream:
  publish_topic: MyServerName

I’ll need to experiment a bit to fully understand this.

I’m back to trying again. I’ve found a lot of documentation for listening for events. The documentation for publishing seems to have much implicit knowledge but I need just one example of publishing events for one device or, perhaps, for group.lights (if that’s the right idea).

I already have the broker. With one example of publish I should be able to figure out the rest

image

You could use MQTT statestream. List entities that you want to include in include:. It will publish states of the listed entities when they change.
Depending on what exactly you are trying to do, it might be more suitable than MQTT eventstream.

Thanks. Thanks eventstream seems exactly what I want. But I tried both without any exclude or include which implies everything would be sent but I don’t see any events. Thoughts?

MQTT Eventstream does not support include / exclude. MQTT Statestream does.
Please post the exact YAML configuration you are trying out.

oops - -just changed

Solved. Apparently, I have to use the IP address rather than the DNS entry. I need to understand how HomeAssistant uses the DNS. It may not use the DHCP-supplied DNS server.

Sorry for not responding, I had quite a busy day yesterday. I’m glad you got it working.

Just a reminder, please post configuration as text and not images. See point 11 for information about how to use code blocks on the forum.

This will probably depend on how you installed Home Assistant (Container, OS, …). For container, your system’s DNS server should be used. In OS, you should be able to configure it under Settings > System > Network.