Custom Component for node-red-contrib-home-assistant-websocket

The zachowj/ hass-node-red is installed via HACS, Node Red added on integration page but nothing appeared in the Node RED. It was several Hassio restart without any result. I use Hassio in Docker under Ubuntu 18.04.



image
image

:tada: A new version of the add-on with node-red-contrib-home-assistant-websocket v0.17.1 was just released.

You might need to update the Node-RED add-on to its newest version (v5.0.7).

Thank you! It is working now! :beers:

I am not seeing the “off” events in node red on the event: state node. I am expecting on/off message when I toggle the switch, instead it moves to “DISABLED” on NR… what am I missing? I an not sure how I can use the DISABLED state of that node.

Is this a valid use case? I want to turn on/off a switch to control the flow of data in the middle of a flow rather than use it a method to start the flow. I guess that is where my disconnect its. I was assuming the main event: state node would output a on and off since it matches the entity_id of the switch that is created. but once its disabled it doesn’t output anything…

I have gotten around fixed this by creating one node to create the switch in HA and another node with the entity_id with the id of the switch that was created to get its true on/off state.

I don’t see that working because when you turn off the switch in HA it will disable the node and it won’t trigger on the switch.send_notifacation_garage state change event.

Interesting use from your post on Github with the traffic light. A possible change to those would be to swap out the traffic node and use a current-state node where you check the state of the exposed switch unless you’re turning on and off the traffic node from something off-screen. I have it on my todo list to create a node that does this exact use-case but I haven’t implemented it.

[{"id":"c5c37106.31bc6","type":"inject","z":"9ce184b.0f5bb78","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":256,"y":1520,"wires":[["1b39943.738206c"]]},{"id":"1b39943.738206c","type":"api-current-state","z":"9ce184b.0f5bb78","name":"","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.test_event","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":482,"y":1520,"wires":[["ac14dc49.0c81c"],[]]},{"id":"bcc85509.194c78","type":"server-state-changed","z":"9ce184b.0f5bb78","name":"test_event","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"test_event","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":252,"y":1568,"wires":[[]]},{"id":"ac14dc49.0c81c","type":"debug","z":"9ce184b.0f5bb78","name":"Send Alarm Alerts","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":730,"y":1520,"wires":[]}]

The scenario where I see exposed nodes being used is if you have a flow that is started by an event and you want to have the ability to disable it from the HA UI. Something like if you have a motion sensor that triggers a light turning on and off in the bathroom and for some reason you want the light to be a dumb switch now.

[{"id":"2cea436.7c324bc","type":"server-state-changed","z":"9ce184b.0f5bb78","name":"","version":1,"exposeToHomeAssistant":true,"haConfig":[{"property":"name","value":"bathroom motion"},{"property":"icon","value":""}],"entityidfilter":"sensor.bathroom_motion","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":210,"y":1744,"wires":[["efb949c.4bd71b8","60777439.e2037c"],[]]},{"id":"efb949c.4bd71b8","type":"ha-wait-until","z":"9ce184b.0f5bb78","name":"","outputs":2,"entityId":"sensor.bathroom_motion","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"5","timeoutUnits":"minutes","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":460,"y":1792,"wires":[[],["ff66455d.a47be8"]]},{"id":"60777439.e2037c","type":"api-call-service","z":"9ce184b.0f5bb78","name":"","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_{{payload}}","entityId":"switch.bathroom_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":680,"y":1744,"wires":[[]]},{"id":"ff66455d.a47be8","type":"change","z":"9ce184b.0f5bb78","name":"off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":1792,"wires":[["60777439.e2037c"]]}]

Thanks for the confirmation.

I have gotten it working using something like what you mentioned in first use case. Where I have event: state node tied to switch.enable_front_notifications and then created a HA switch using a new set of nodes.

I use traffic lights pretty heavily in my flows too. Nearly everything goes through a traffic light node before it gets processed, in case I want to disable things.

Also found something, if you stick one of these nodes into a sub flow then every time the sub flow is hit, it creates a new switch not just the first time its used… no biggie, i have created a NR flow in which I am creating all the “switches”

This is fantastic… just tried, but will put to some real testing asap and report back :smile: thanks!

Yeah after ruining this for sometime, I am seeing a number of issues like the switches disappearing and hence affecting the flows causing flows to fire and execute some seemingly random behavior. there are some errors in the logs around unbound websocket errors to HA…

How could I use these in conjunction with the bigtimer? i use a lot of flows to turn on and off lights with the bigtimer node. Would like to have a disable switch to disable the timers. This is what I have now. I have to use a change node before the bigtimer to change the “on” to “auto” for the timer to work. But this does not give me the option to put the timer into a override off state.

Just started using this and it is creating sensors successfully in HA
Is there anyway to get the name of the sensor to be a field within the msg.payload

Not really. What’s your use case?

I use it to let my wife know what birthdays are due in our very large family
Nodered reads a file and passes the next two months of birthdays into sensors
These are then displayed on a card so she can just look at the tablet screen
So the number of sensors can vary from month to month

For a similar usage (not birthdays though!), I only use one sensor and put the other informations as an attribute in JSON format.
The sensor value gives the number of items in the list and the list is a json array with values. With this in lovelace, you can do pretty much what you want…
GV

image

[{"id":"fe43e6cb.441098","type":"ha-api","z":"9ce184b.0f5bb78","name":"","debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\t    \"type\": \"config/entity_registry/update\",\t    \"entity_id\": \"sensor.birthdays\",\t    \"name\": payload.name\t}","dataType":"jsonata","location":"payload","locationType":"msg","responseType":"json","x":562,"y":704,"wires":[[]]},{"id":"53a88849.f87f28","type":"inject","z":"9ce184b.0f5bb78","name":"","topic":"","payload":"{\"name\":\"Albert Einstein\",\"date\":\"March 14\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":262,"y":704,"wires":[["fe369a23.97a158"]]},{"id":"fe369a23.97a158","type":"ha-entity","z":"9ce184b.0f5bb78","name":"","server":"913f8aa4.627b78","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"birthdays"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload.date","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":406,"y":704,"wires":[["fe43e6cb.441098"]]},{"id":"dd790516.9c5448","type":"inject","z":"9ce184b.0f5bb78","name":"","topic":"","payload":"{\"name\":\"Isaac Newton\",\"date\":\"12/25\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":258,"y":752,"wires":[["fe369a23.97a158"]]}]

I think the same thing is happening for sensor nodes. if I put a sensor node in a subflow it creates multiple entries in home assistant…

Sensor nodes don’t work in subflows because of how they register themselves in Home Assistant with a combination of the server config node id and the sensor node id. The nodes in a subflow get new node ids every time NR reboots.