I would love to try this, since I lost a REST based node HASS-post, that is no longer working due to api passwords being dropped by HA,and i used to send attributes to a fake sensor, now i think with your implementation I can make a sensor and update its attributes, but sadly i am still a noob, I use Hassio and I don’t know where exactly to add the npm package, as you described. Thank You.
@rraven Go to the Hassio Node-RED addon, and put it into the config there.
@Kermit, This looks great! I’ll have to think of some ideas to use the new nodes.
Got it, thank you sir, i totally forgot, since i already added a package that way.
I will test these nodes now
This is really interesting!
I don’t use Node-RED, but I’ve always wished for a way to add sensor, binary_sensor, switch, etc entities to Home Assistant from an external source. This can be done with the REST API, of course, but it doesn’t use config flow, doesn’t register like an integration, and the entities aren’t first-class entities in Home Assistant (i.e. you can’t rename them, for example).
Your integration seems to cover all of that.
Do you have any documentation for using the integration available? I can scour the Node Red Node code to find it, but, if you’ve got it documented somewhere, that’ll make it a lot easier.
This is beautiful ! Just yesterday i asked for help to replace a custom node which no longer works (using an the old API password authentication) , “node-red-contrib-hass” , that sent statuses, attributes via REST api to my “fake” template sensor in HA, in order to populate it with info from Node Red, and after just a bit, @Kermit came with this solution. Is like it was made for the old noob me! Thank you!
I already tried the sensor node, and it works beautifully for me.
And the result (on the ‘statusac’ attribute, in a markdown card in lovelace ; don’t mind the language please):
This part didn’t worked, i got the sensor.nodered_randomshere , but i changed it in the integrations, no problem.
Don’t really have any documentation as it is all handled by Node-RED and home-assistant-js-websocket so the end-user doesn’t really need to know how it works.
Pretty much everything you really need to know to use it without node-red is located in
https://github.com/zachowj/hass-node-red/blob/63475d1536d2881ec2cb1ccb62f2ff65a5ff2dff/custom_components/nodered/websocket.py. The integration creates two websocket commands, nodered/discovery
and nodered/entity
. Discovery is what creates the entity in HA and entity is what updates it.
nodered/discovery
component
sensor/binary_sensor/switch
server_id/node_id
Are just unique identifiers so they can be any string
config
Is any normal HA config that would go with the selected component
remove
If this is set to true
the entity will be removed from HA
nodered/entity
server_id/node_id
Are just unique identifiers so they can be any string. Need to be the as what was used in the discovery call
state
The value to set entity state
attributes
key/value pair of attributes to set for the entity
home-assistant-js-websocket handles all the websocket communication between NR and HA so for a switch component the integration will send back a message on the same command id that it received the discovery of the switch on. That’s how it updates node-red of the state change from HA. For sensors, it’s just one-way communication from NR to HA.
In practice this would look something like:
- make a websocket connection to HA
- send all the nodered/discovery messages to HA
- listen for the command id message back from HA for any switch changes
- send nodered/entity updates as needed
Hopefully, that might help you a little. This is all subject to change as it is my first iteration also my first time writing any substantial python.
Nice to hear it’s working for you.
I’m guessing the preset name didn’t work because it used the name for the node at the top and not below in the HA config box. If that’s the case I should have been more clear.
Oh. I’m sorry, my bad then. I didn’t understood properly (inglish iz haard) . Next time I will do it right. Thank you again, I’m so happy it works!
Side question: Is it possible to use the same sensor node in other flow , without creating another sensor in HA? Let’s say i just use the same sensor to update another attribute from another flow.
Take a look at the link in
and link out
nodes
Is there anyway to test this with NR running inside docker. I tried adding the shell command, and restarting NR but no additional nodes showed up
You can install Node RED components using the command pallet (I think that’s what it’s called) in the Node RED GUI. Not sure if it allows arbitrary github URLs or not.
This is enough to get me started. Thank you for this!
i already have the websockets node installed, updating to use the integration branch using the command above said it had updated, yet there is no new nodes available other than the ones for the current websockets node
Ah. That’s goes a bit deeper than my cursory understanding of Node RED. Hopefully, someone else can help.
If you have npm installed on the docker host you just need to run the npm install command from the where you have your config files of node-red.
If you don’t have npm installed on the host system you can log into the shell and do it from there.
$ docker exec -it <containername> /bin/bash
$ cd /data
$ npm install https://github.com/zachowj/node-red-contrib-home-assistant-websocket
$ exit
restart node-red
Working great (HA and NR both on docker)! I can certainly find a lot of use cases for this extension!
Is the “resend state and attributes” toggle supposed to resend the values after a HA restart?
Yes, when NR registers the entity with HA and it doesn’t exist yet it will send the last values if they exist.
This didn’t work the first restart of HA for me, but since then it have worked flawless
Yes, I did find a bug where the sensor wouldn’t resend the old payload until the node had been deployed again.
Hi. I don’t know what is wrong, but now i can’t run the package dependency in Hassio anymore ,after a Hass restart.:
[10:35:08] FATAL: Failed installing npm package git+https://github.com/zachowj/node-red-contrib-home-assistant-websocket#integration
[cont-init.d] user.sh: exited 1.
[cont-finish.d] executing container finish scripts…
[cont-finish.d] 99-message.sh: executing…Oops! Something went wrong.
On the github page i see Build-Failing.
Please advise me if you can. Thank you.