Using WebSocket where ever possible for communication to and from Home Assistant.
Ability to use Long-Lived Access Tokens to authenticate with Home Assistant as well as still supporting the legacy API password.
Server credentials are now encrypted and stored in the node-red cred file. This also stops them from being exported in flows.
A new ‘Fire Event’ Node that allows you to fire events to Home Assistant.
Check the CHANGELOG for a list of fixes and changes that have been made so far.
Installation
Install via Node-RED Manage Palette
node-red-contrib-home-assistant-websocket
Install via npm
$ cd cd ~/.node-red
$ npm install node-red-contrib-home-assistant-websocket
# then restart node-red
If you have been using @Ayapejian version there are some breaking changes with two of the nodes. The ‘Poll State’ and ‘Current State’ both have a little different formatted output. Check your nodes and make sure they are outputting what you expect.
If you have been using @Spartan-II-117 fork this should be a drop in replacement as of this posting.
Support
If you find any issues/bugs please create a new issue on github so I can address them. Also if you have any feature requests that you think may improve this, I’d also be glad to hear from you.
Thank you,
What are the advantages of using websockets over REST API and Event Stream? Only the longlived access tokens?
As you can see I’m not well informed on this subject…
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.
I have a number of flows using the nodes from @ayapejian and would like to replace his library with yours. I’m unable to uninstall as the nodes are currently used. Any advise on how to replace the existing library with yours ?
The easiest route would be if you have shell/command line access and are able to stop node-RED uninstall node-red-contrib-home-assistant and then install node-red-contrib-home-assistant-websocket
# stop node-red
$ cd ~/.node-red
$ npm uninstall node-red-contrib-home-assistant
$ npm install node-red-contrib-home-assistant-websocket
# then restart node-red
If that’s not an option you could export all the flows that use the Home Assistant nodes save them in a text file so you accidentally don’t lose them. Then delete the flows you exported which should then allow you to uninstall node-red-contrib-home-assistant via the palette and then install node-red-contrib-home-assistant-websocket. After that, you should be able to import the flows that you exported earlier. Using this method you’ll probably have to re-enter your Home Assistant credentials.
Replaced the original palette with your fork this afternoon. Tested my automations and works great ! Thx for the good work. I’ll report if i have anything wrong.
Happy that there is new maintainers of the home assistant node red flows, but like buses, you wait for 1 and 2 come along. Would it be beneficial or possible if yourself and spartans fork could merge and have 2 or more people who are able to maintain one project?
At the moment i have to choose with staying with spartans fork or moving to this one,and run the risk of my wrong choice going stale and not being maintained
Just swapping the package out and replacing it should work in most cases. The only caveat being that if you’re coming from Ayapejian version you’ll have to check your ‘Poll State’ and ‘Current State’ nodes both have a little different output.
Spoke too soon. I’ve generated a Long Live Account Token under my HA account, and used the generated token on Access Token. Base URL is http://hassio/homeassistant and Use Legacy API Password is checked. When I deploy I get:
What version of nodejs are you running and are you running node-RED in docker? That looks to be same error I was getting when I was testing with an older version of node pre v8.11.2.
If you’re running at least node v8.12 can you let me know your setup so I can look into it