Sending events to remote listeners

I’ve been rolling my own linux-based home automation for many many years. I’ve recently installed HA because it seemed to be the easiest path to get access to a zigbee thermostat. The RESTful API has made it easy to fetch/set current temperature, setpoint, etc, so I’m pleased so far.

The next step, though, in integrating HA into my world, is getting HA to export events, so that my scripts and systems can act on them. Ideally, this would be as simple as a json bundle sent via network socket. But the JSON api in HA seems to be read-only – or, more correctly, it’s strictly synchronous. (Correct?)

I’ve seen the WebSockets documentation, but that seems like overkill for my purposes. I’m looking for an event – not a conversation.

Have I missed some obvious HA capability that I should be using?

And… since websocket might be the only answer: does anyone have a very simple means of listening for events using the websocket API? I’ve been trying to use websocat to set up a connection, but haven’t had any luck.

I just wanted to circle back with my solution.

I was never able to get the websockets interface running, even after asking for more help over here.

But at some point I realized that the answer was simple. By using the RESTful API, I can trigger a REST request for a dummy data item, whose access URL contains a token representing the event. My listener pulls that token out of the request, and does whatever it needs to do.

My “event sender”, from configuration.yaml

### see https://www.home-assistant.io/integrations/rest_command/
rest_command:
  event_send:
    method: get
    url: "http://192.168.10.3:9901/event:{{event}}"

In my automation’s Action section, I have this:
action

The full request at my server is http://192.168.10.3:9901/event:sunroom_set_high, which is easy to deal with.

1 Like