Node-red-contrib-home-assistant-websocket

I am no expert but do know some of the basics. A very general high overview of a WebSocket is that it allows for two way communication over a single socket/connection. Unlike an HTTP call where it has to open a new connection for each request that contains headers and authentication that the server has to process for each request. In short, using a WebSocket should be faster and able to process more request in the same amount of time. But running node-RED and Home Assistant on the same server or LAN makes most of that irrelevant.

The main reason I switched over to using a WebSocket as the communication layer was to deal with an issue, like posted here, where node-RED would lose it’s connection to Home Assistant. This is where the event stream comes into play, node-RED would open an HTTP connection with Home Assistant asking for all the event changes. Home Assistant would keep this connection open streaming all those changes to node-RED. If there was ever a problem with this connection whether it be restarting Home Assistant or the connection just dying node-RED wouldn’t realize that it had lost the connection and would do nothing about it. So all nodes would stop receiving updates. With a WebSocket, we are easily able to see when the connection dies and attempt to reconnect and continue operations.

1 Like