The URI that is generating the data is
A requirement on the client-side is existing support for the EventSource interface.
There are various ways to access the stream. One is
$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ -H "Content-Type: application/json" http://localhost:8123/api/stream
You can create a convenient view for this by creating an HTML file (
sse.html) in the
www folder of your Home Assistant configuration directory (
.homeassistant). Paste this snippet into the file:
Visit http://localhost:8123/local/sse.html to see the stream of events.
A simple way to consume server-sent events is to use a command-line http client like [httpie][https://httpie.org/]. Installation info is on the site (if you use Homebrew, it’s
brew install httpie). Once installed, run this snippet from your terminal:
$ http --stream http://localhost:8123/api/stream x-ha-access:YOUR_PASSWORD content-type:application/json
The home-assistant-sse repository contains a more advanced example.
If you want to test the server-sent events without creating a website, the Python module
sseclient can help. To install (assuming Python and pip3 are already installed):
$ pip3 install sseclient
«««< HEAD The simplest script to consume the SSE looks like the following snippet. ======= The simplest script to consume the SSE in Python looks like this:
from sseclient import SSEClient messages = SSEClient('http://localhost:8123/api/stream?api_password=YOUR_PASSWORD') for msg in messages: print(msg)