Node-red-contrib-home-assistant-websocket

If you refer to the first screenshot is from ha event listener.

The get entities node has an option to output array, split or random. Would it be possible to add count to the mix? Quite often I find this is the only thing I care about, not the actual entities, but only how many fits a given criteria. As it is now, I just add a function node or some jsonata in the following node, but would love to keep it clean :slight_smile:

@kermit thanks for the response, although now I feel a bit thick :anguished:. It never occurred to me that I could use the halt-if to provide an output, I took it at face value and assumed it just stopped the flow.

TBH in most scenarios that would be sufficient.

As did I. Had no idea the flow didn’t really halt, but continued out the 2nd output.

Originally it did just halt the flow if it was true. The second output was added later. At this point it probably could be named something better.

1 Like

It will be in the next release or you can grab it from github now.

https://github.com/zachowj/node-red-contrib-home-assistant-websocket/commit/306115129b73359c0b12f243f4485071b75ecbb2

1 Like

not installing it any differently than the other palettes. via the web interface. its only HAWS i have to manually do this.

Randomly dropping in to show some love to @Kermit, you are killing it! :heart_eyes: :heart:
I am enjoying the wait node, as well as the autofill that is now, AFAICT, everywhere. Really, really cool.

2 Likes

Hi,

I’ve installed this package however I’m new to node red and I have no idea how to configure it… Can someone help me ?

Thanks!

Drop one of the Home Assistant nodes onto the workspace. Then double click on it to bring up the editor window.

Within the editor window click on the pencil to add a new server.

Fill in Base Url and Access Token (how to generate one).

Close out of the editor windows by clicking Done, then Deploy the flow.

Hi just a quick heads up kermit I ran npm audit in my NodeRED project folder and it said that there is a Moderate vulnerability with this node, nothing crazy but I thought you should know, here’s the output if my audit command:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Moderate      β”‚ Prototype Pollution                                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Package       β”‚ lodash                                                       β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Dependency of β”‚ node-red-contrib-home-assistant-websocket                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Path          β”‚ node-red-contrib-home-assistant-websocket > lowdb > lodash   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ More info     β”‚ https://nodesecurity.io/advisories/782                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

It looks like an easy fix according to the link, Update lodash to version 4.17.11 or later.

Is it possible to have the get template node overwrite msg.payload? For example, in a flow where two get template nodes are executed one after the other, it appears (at least to me) that msg.payload remains unchanged after the execution of the 2nd node.

The node does overwrite msg.payload, but it also outputs msg.template (from the info panel: The original template sent to home assistant for rendering). This causes the second template node to import msg.template and overwrite its node config. So you’re running two of the same template renders.

The solution is to drop a change node in between them and delete msg.template.

I’ll probably add the same changes I did with the call-service node which will allow these outputs to be customizable.

1 Like

Excellent - thanks for the tip (and pardon my ignorance).

Hi guys,

I have set up Node Red and the connection to Home Assistant is working, however I am having some issues with the Websocket connection failing after ~5-10 minutes, after which I need to restart the flow (or container) for the reconnection to take place. See below the events happening in the HA log. Looking at the Node Red log, there does not seem to be anything wrong (up to trace verbosity)

2019-03-27 00:03:59 INFO (MainThread) [homeassistant.components.http.view] Serving /api/websocket to 172.17.0.5 (auth: False)

2019-03-27 00:12:58 INFO (MainThread) [homeassistant.components.websocket_api.http.connection.139734980901072] Connection closed by client

2019-03-27 00:23:34 INFO (MainThread) [homeassistant.components.http.view] Serving /api/websocket to 172.17.0.5 (auth: False)

2019-03-27 00:32:42 INFO (MainThread) [homeassistant.components.websocket_api.http.connection.139734973733800] Connection closed by client

What could the issue be? I am running the latest version of the Node Red (v8) docker, latest version of HA docker, and latest version of the package in Node Red.

Thanks in advance for any pointers in the right direction.

Do you have a certain flow that runs every ~9 mins? Do you need to just redeploy all your flows or restart the docker container?

It is a re-deployed instance of Node-red, that only contains a troubleshooting flow with 2 state nodes flowing into a debug node.

When I (re)deploy the flow, it seems to work again for a short while. Also, the ~9 minutes is still a random interval, just happened to be 9 minutes in my example.

I did some more digging into the issue, and have some more logs to share.

Node-Red:

29 Mar 14:31:52 - [info] Starting flows
29 Mar 14:31:52 - [debug] red/nodes/flows.start : starting flow : global
29 Mar 14:31:52 - [debug] red/nodes/flows.start : starting flow : edb8c4cd.f2b358
29 Mar 14:31:52 - [trace] [flow:global] start flow
29 Mar 14:31:52 - [debug] [server:Home Assistant] instantiated node, name: Home Assistant
29 Mar 14:31:52 - [trace] [flow:global] ------------------|--------------|-----------------
29 Mar 14:31:52 - [trace] [flow:global]  id               | type         | alias
29 Mar 14:31:52 - [trace] [flow:global] ------------------|--------------|-----------------
29 Mar 14:31:52 - [trace] [flow:global]  c9eaa2a.0c90c6   | server       | 
29 Mar 14:31:52 - [trace] [flow:global] ------------------|--------------|-----------------
29 Mar 14:31:52 - [trace] [flow:edb8c4cd.f2b358] start flow
29 Mar 14:31:52 - [debug] [server-state-changed:b327dba6.302618] instantiated node, name: undefined
29 Mar 14:31:52 - [debug] [server-state-changed:51e3b626.706708] instantiated node, name: undefined
29 Mar 14:31:52 - [trace] [flow:edb8c4cd.f2b358] ------------------|--------------|-----------------
29 Mar 14:31:52 - [trace] [flow:edb8c4cd.f2b358]  id               | type         | alias
29 Mar 14:31:52 - [trace] [flow:edb8c4cd.f2b358] ------------------|--------------|-----------------
29 Mar 14:31:52 - [trace] [flow:edb8c4cd.f2b358]  bac59ea7.99a66   | debug        | 
29 Mar 14:31:52 - [trace] [flow:edb8c4cd.f2b358]  b327dba6.302618  | server-state-changed | 
29 Mar 14:31:52 - [trace] [flow:edb8c4cd.f2b358]  51e3b626.706708  | server-state-changed | 
29 Mar 14:31:52 - [trace] [flow:edb8c4cd.f2b358] ------------------|--------------|-----------------
29 Mar 14:31:52 - [trace] runtime event: {"id":"runtime-state","retain":true}
29 Mar 14:31:52 - [info] Started flows
29 Mar 14:31:52 - [trace] runtime event: {"id":"runtime-deploy","payload":{"revision":"add6a148bb463c726126d3b710b3393e"},"retain":true}
29 Mar 14:31:52 - [info] [server:Home Assistant] WebSocket Connected to http://192.168.1.154:8123
29 Mar 14:31:52 - [debug] [server:Home Assistant] config server event listener connected
29 Mar 14:31:57 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:32:00 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: on, old_state: off
29 Mar 14:32:02 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:32:26 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: off, old_state: on
29 Mar 14:32:34 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: on, old_state: off
29 Mar 14:32:53 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: off, old_state: on
29 Mar 14:33:53 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:33:57 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:36:13 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:36:21 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:36:34 - [info] [server:Home Assistant] WebSocket Closed http://192.168.1.154:8123
29 Mar 14:36:34 - [debug] [server:Home Assistant] config server event listener closed
29 Mar 14:36:34 - [debug] [server:Home Assistant] WebSocket Connecting http://192.168.1.154:8123
29 Mar 14:36:34 - [debug] [server:Home Assistant] config server event listener connecting
29 Mar 14:36:34 - [debug] [server:Home Assistant] config server event listener closed
29 Mar 14:36:39 - [debug] [server:Home Assistant] WebSocket Connecting http://192.168.1.154:8123
29 Mar 14:36:39 - [debug] [server:Home Assistant] config server event listener connecting
29 Mar 14:36:39 - [debug] [server:Home Assistant] config server event listener closed
29 Mar 14:36:44 - [debug] [server:Home Assistant] WebSocket Connecting http://192.168.1.154:8123
29 Mar 14:36:44 - [debug] [server:Home Assistant] config server event listener connecting
29 Mar 14:36:44 - [info] [server:Home Assistant] WebSocket Connected to http://192.168.1.154:8123
29 Mar 14:36:44 - [debug] [server:Home Assistant] config server event listener connected
29 Mar 14:37:30 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:37:31 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:41:02 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:41:04 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:43:18 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: on, old_state: off
29 Mar 14:43:27 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: off, old_state: on
29 Mar 14:43:48 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: on, old_state: off
29 Mar 14:44:02 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: off, old_state: on
29 Mar 14:44:16 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: on, old_state: off
29 Mar 14:44:54 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: off, old_state: on
29 Mar 14:44:59 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: on, old_state: off
29 Mar 14:45:59 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: off, old_state: on
29 Mar 14:47:25 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:47:31 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:49:43 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: on, old_state: off
29 Mar 14:49:56 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: off, old_state: on
29 Mar 14:50:25 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: on, old_state: off
29 Mar 14:50:53 - [debug] [server-state-changed:51e3b626.706708] Incoming state event: entity_id: binary_sensor.kitchen_motion_sensor, new_state: off, old_state: on
29 Mar 14:53:07 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:53:08 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:53:56 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:53:56 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:53:56 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:53:56 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:55:55 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:55:56 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:56:25 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:56:25 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 14:57:26 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 14:57:26 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on
29 Mar 15:01:53 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: on, old_state: off
29 Mar 15:01:54 - [debug] [server-state-changed:b327dba6.302618] Incoming state event: entity_id: light.hue_white_lamp_1, new_state: off, old_state: on

HA filtered on WebSocket:

2019-03-29 14:31:51 INFO (MainThread) [homeassistant.components.websocket_api.http.connection.140189325461712] Connection closed by client
2019-03-29 14:31:52 INFO (MainThread) [homeassistant.components.http.view] Serving /api/websocket to 172.17.0.5 (auth: False)
2019-03-29 14:36:32 INFO (MainThread) [homeassistant.components.websocket_api.http.connection.140189612441104] Connection closed by client
2019-03-29 14:36:32 INFO (MainThread) [homeassistant.components.websocket_api.http.connection.140189612927072] Connection closed by client
2019-03-29 14:36:38 INFO (MainThread) [homeassistant.loader] Loaded websocket_api from homeassistant.components.websocket_api
2019-03-29 14:36:38 INFO (MainThread) [homeassistant.setup] Setting up websocket_api
2019-03-29 14:36:38 INFO (MainThread) [homeassistant.setup] Setup of domain websocket_api took 0.0 seconds.
2019-03-29 14:36:44 INFO (MainThread) [homeassistant.components.http.view] Serving /api/websocket to 172.17.0.5 (auth: False)
2019-03-29 15:09:05 INFO (MainThread) [homeassistant.components.websocket_api.http.connection.139740613977536] Connection closed by client

A restart of the HA docker container was performed at 14:36 to check if the connection comes back after this, and as you can see, it does, while also logging a disconnect in the Node-Red log. However, at 15:09, HomeAssistant reports closing the connection, but nothing like that is visible in the Node-Red side and

I don’t mind to do more troubleshooting at all, but I hope someone can help me in the right direction.

At this point I don’t have to many ideas. I’m assume both docker containers are running the same machine so them losing a connection to each other really isn’t possible.

Does rode-red itself seem unresponsive when this happens or just the HA nodes? If you try and run a call-service node when it’s in this state does it go through? Same with a get-template node?

[{"id":"9e66f282.eef6","type":"inject","z":"ffbd7f06.4a014","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":428,"y":848,"wires":[["4c27dcd.649ff24"]]},{"id":"4c27dcd.649ff24","type":"api-call-service","z":"ffbd7f06.4a014","name":"turn on light","server":"2dad33ee.42bf5c","service_domain":"light","service":"toggle","data":"{\"entity_id\":\"light.light1\"}","mergecontext":"","output_location":"","output_location_type":"none","x":598,"y":848,"wires":[["5e7c158a.53330c"]]},{"id":"5e7c158a.53330c","type":"debug","z":"ffbd7f06.4a014","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":774,"y":848,"wires":[]},{"id":"7d3de24f.8a109c","type":"inject","z":"ffbd7f06.4a014","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":428,"y":896,"wires":[["715374a4.b3d23c"]]},{"id":"715374a4.b3d23c","type":"api-render-template","z":"ffbd7f06.4a014","name":"sun state","server":"2dad33ee.42bf5c","template":"{{states.sun.sun.state}}","x":588,"y":896,"wires":[["ee4fbbc4.540648"]]},{"id":"ee4fbbc4.540648","type":"debug","z":"ffbd7f06.4a014","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":774,"y":896,"wires":[]}]

Well, it was a networking issue in the end. I am running the HA docker in β€œhost” networking, while the NodeRed docker was running in Bridge. I did some more trial and erroring, and set the Node-Red docker to Host networking as well, this seems to have fixed the problem, and everything stays connected(thus far, 12 hours later… :slight_smile:)

Thanks for helping me out though!