Hello – Is there a generic and supported way to map HA events to an MQTT topic already?
I have a pretty simple HA setup using the Docker image. I prefer to use only official integrations (e.g. MQTT). I have a mix of DIY and HA automations, but generally I have more of the complex logic behind a custom MQTT client (e.g. garage door opens, various stuff happens outside HA).
This weekend I put together a simple client to listen on all state_changed events via HA’s WebSocket API and publish as an MQTT topic. I did this as a proof of concept currently because I couldn’t find a general way of having HA map every event to an MQTT topic.
One more detail: HA awesomeness for me is using it as a one screen view of everything going on with my home automation, including DIY projects, Z-Wave (zwavejs2mqtt), etc.
UPDATE:
Although this provides a solution to forwarding HA state_changed events to MQTT, my client implementation has a requirement to avoid maintaining state between events.
With Statestream, each attribute that changes is a separate message. If you need, let’s say, the actual state (e.g. ‘on’) and the friendly name, you’ll need to be sure your client can collect both before processing.
I came up with my own solution by creating an app (under Docker) that subscribes to HA’s WebSocket API and forwards the entire state_changed JSON as the payload for the MQTT message.