Node-red-contrib-home-assistant-websocket

Currently, there is no “force_update” on the NR entity node.

You can fake it by adding another attribute to the entity that could be named anything with the value as timestamp.

2 Likes

Thanks for reply. Unfortunately, this didn’t do the trick.
Screenshot_1

I added attribute updated, assigned it to timestamp and it is indeed changing, however, since the temperature value doesn’t change, it’s reporting as “dead sensor”.

Perhaps I’d need to rethink the whole concept. Any ideas, how to approach this?

I’ve gotten the new Philips Hue Dimmer Switch that has a Power button instead of On/Off buttons so I want to create a logic for toggling the lights using just one button. The button has to toggle two (or more) lights so the logic can’t be as simple as using “homeassistant.toggle”.

The logic should be:

  • if any light is on then the Power button turns off all of them
  • if none of the lights are on then the Power button turns on all of them

For implementing that I would need to get the state of all related lights and based on their ON/OFF states determine what to do.

I wonder if anyone has suggestions on how to do that. It seems like the “Current state” node can only get the state of one entity so that seems the biggest blocker for me.

Once I get the state I guess I can write some custom JS logic using the “Function” node since I don’t think this addon has anything so specific to my use case.

Use a HA group with all the lights. If it’s on there’s at least one light on the group is on and if they are all off the group is off

Thanks. That would work nicely but I want to depend as little as possible on HA configuration in NodeRed so as to not have to maintain two moving pieces at the same time.

I’ve implemented that using the “Get entities” node (apparently it can get states of multiple entities using regexp) + a custom function node that returns a payload formatted for the “Call service” node.

Hi,

I’ve just posted this topic about a problem with the service homeassistant set_location which is demanding a lot of memory (until my Pi freezes).

I’m just linking from here, since I’ve got the feeling people are reading here, who can help me out.

Thanks!

Hi,

I’ve a problem with using global variable in render template node.
This example doesn’t work:

[{"id":"4da1c3b6.ecf84c","type":"change","z":"1497555b.20160b","name":"","rules":[{"t":"set","p":"var1","pt":"global","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":1580,"wires":[["15b0ee15.17c1f2"]]},{"id":"15b0ee15.17c1f2","type":"api-render-template","z":"1497555b.20160b","name":"test","server":"f52dc269.9226a","template":"{{ global.var1 }}","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":610,"y":1580,"wires":[["a8c839d6.c4f668"]]},{"id":"aee883ee.441c","type":"inject","z":"1497555b.20160b","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":1580,"wires":[["4da1c3b6.ecf84c"]]},{"id":"a8c839d6.c4f668","type":"debug","z":"1497555b.20160b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":1580,"wires":[]},{"id":"f52dc269.9226a","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Help, plz.

Hi,
The home-assistant template doesn’t see node-red scoped variables. You can get around this by stringing together a node-red template then a home-assistant template. Here’s your example with an additional node-red template node. The node-red template makes a string that will be expanded by the home-assistant template, so 1. I had to change the delimiter so that the {{ }}'s were preserved in the output, 2. I added a home-assistant variable to expand (assuming you have a sun sensor).

[{"id":"aee883ee.441c","type":"inject","z":"1c7b6f3e.2903c9","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":140,"wires":[["4da1c3b6.ecf84c"]]},{"id":"4da1c3b6.ecf84c","type":"change","z":"1c7b6f3e.2903c9","name":"","rules":[{"t":"set","p":"var1","pt":"global","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":140,"wires":[["9d37cf2c.baae78"]]},{"id":"9d37cf2c.baae78","type":"template","z":"1c7b6f3e.2903c9","name":"","field":"template","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{=<% %>=}}\n{{ (10.5 * <% global.var1 %>)|int }}\n{{ states.sun.sun.state }}","output":"str","x":470,"y":140,"wires":[["937938be.5629e8","15b0ee15.17c1f2"]]},{"id":"937938be.5629e8","type":"debug","z":"1c7b6f3e.2903c9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"template","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":100,"wires":[]},{"id":"15b0ee15.17c1f2","type":"api-render-template","z":"1c7b6f3e.2903c9","name":"test","server":"f52dc269.9226a","template":"","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":650,"y":140,"wires":[["a8c839d6.c4f668"]]},{"id":"a8c839d6.c4f668","type":"debug","z":"1c7b6f3e.2903c9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":140,"wires":[]},{"id":"f52dc269.9226a","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Hope that helps,
Benjamin

3 Likes

Firstly, thanks Kermit for all your hard work on this, really appreciated.

Can anyone point me to some instructions on using the trigger-state node? I thought I had it figured out, but no matter what I try I keep messing it up, so I feel I need some ELI5 explanation and my Google searches have failed me.

I’m just trying to test it out with something simple where when a light in my office is turned on it outputs a custom boolean message of true, as below. Sadly the debug shows multiple lines of the state of the office light, not the true message I was expecting. :confused: I’m sure I’m doing something wrong and that it’s dead simple but I just can’t figure it out.

seems good to me

image

[{"id":"a8b197db.7713f8","type":"trigger-state","z":"f61766ce.f85398","name":"","server":"","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_boolean.test","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"outputs":3,"customoutputs":[{"messageType":"custom","messageValue":"true","messageValueType":"bool","comparatorPropertyType":"always","comparatorType":"is","comparatorValue":"","comparatorValueDataType":"str","comparatorPropertyValue":""}],"outputinitially":false,"state_type":"str","x":240,"y":3280,"wires":[[],[],["3d39521d.effe8e"]]},{"id":"3d39521d.effe8e","type":"debug","z":"f61766ce.f85398","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":466,"y":3280,"wires":[]}]

Thanks, once again, no idea what I’d messed up but that’s working just as I wanted. :slight_smile:

I have been attempting to migrate my automations to Node Red and have run into a bit of a snag. Some of my existing (non-NR) automations permit me to enable / disable them from the lovelace UI. I would like this functionality while using NR and apparently this thread indicates that this IS possible. Unfortunatly I am unable to get this to work. My NR is running in a docker container, My HA is also running Core in docker. I have created the Long lived access token in NR, and NR is controlling my devices when I create flows. I have installed the Node-red-contrib-home-assistant-websocket, I have installed the HACS Node-Red Companion, and I have installed the Node Red-Companion integration. My NR can see all my HA entities but I am not seeing any NR entities begin created in HA that I can enable / disable my flows. Am I missing something?

When you edit an event node towards the bottom of the config window should be Expose to Home Assistant

image

1 Like

I am sure I did not see that before you posted. Maybe a reset or re-creating the access token revealed it. Thanks

A beta has been released for the next version. If you’re feeling adventurous please give it a try and leave some feedback.

Release notes and discussion can be found here https://github.com/zachowj/node-red-contrib-home-assistant-websocket/discussions/382

2 Likes

Thanks for your work on this great set of nodes. A feature that I’d like to request (if not possible yet already) to help make my system a bit more stable: monitor if NR loses the connection to HA, and be able to us that info in a sequence.

You could use an events: all node listening for home_assistant_client.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/events-all.html#client-events

2 Likes

New Release 0.31.0 (2021-05-19)

New nodes

  • Tag (beta)
  • Time (move to beta from alpha)
  • Device (alpha) requires v0.5.2+ of the NR companion custom component
    • Create device based event triggers
    • Trigger device actions

Features

Queues for call-service node

There always seemed to be confusion over why the call-service node would report an error of no connection to server. This error is often thrown when using a starting node that fires directly after loading, i.e. Bigtimer, eztimer. The cause was that the node would trigger the flow before the HA config node had a chance to connect to Home Assistant hence no connection to server. This update adds a queue system to the call-service node. With the ability to save only the first/last message or all messages and then resend them after NR has successfully connected to HA.

Async done / complete

Home Assistant nonevent nodes will notify the Node-RED runtime when it has completed its action. Basically, the complete node will now function with HA nodes.

Helper functions added to JSONata Expressions

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/jsonata.html

  • $randomNumber
  • $sampleSize

Migrations

The node migration system has been reworked and allows for updating all HA nodes with a push of a single button. With this release, a lot of nodes have changed how certain data is saved. So it is highly recommended to make a backup of your flows before doing upgrades.

Custom Outputs

  • [x] API
  • [x] Current state
  • [x] Device
  • [x] Events: all
  • [x] Events: state
  • [ ] Fire event
  • [ ] Poll state
  • [ ] Render Template
  • [ ] Tag
  • [ ] Time
  • [ ] Wait Until
  • [x] Webhook
  • [ ] Zone

Features

  • Add $randomNumber and $sampleSize as JSONata helper functions (b5b65bf)
  • Add device node (b08fcbe)
  • api: Add custom outputs (da0187f)
  • call-service: Add message queue (58df3a0)
  • current-state: Add custom ouputs (f4ecbb8)
  • events-all: Add custom outputs (0a3fc23)
  • events-state: Add custom outputs (aa07fb4)
  • Make use of NR v1.0 async send and done (d5b69f4)
  • migrations: Add config nodes to mass update (5d23126)
  • tag: Add tag node (17585bb)
  • time: Move time node to beta release (27caacc)
  • webhook: Add custom outputs (5dff14b)

Bug Fixes

  • api: add try catch for setCustomOutputs (ee5189d)
  • Check for valid property for custom outputs (f971856)
  • Check for valid server before processing input (a86a9a6)
  • check for valid server config before using it (d7b322b)
  • ci: Don’t lint included external libs (8cd6735)
  • destroy bonjour after finished using it (eb2208f)
  • entity-switch: Remove unused declaration (e6b15a0)
  • Fix Comms import (8c51877)
  • migration: Move event-state for properties to a newer version (de68154)
  • migrations: make sure schema version is a number (e1bc0f8)
  • migrations: swap conditional for default value (996b9ef)
  • only trim spaces of server url if it exists (f9ce69f)
  • poll-state: call correct error method (5f7b1a8)
  • poll-state: Use correct element id for entity_id input (0c2fe30)
  • request autocomplete results only if server actually changes (27dc32a)
  • routes: fix server id for getting integration version (fc6c808)
  • routes: flatten out properties array (45df3f1)
  • status: check for valid homeAssistant before adding listeners (c1d29ec)
  • time: Check jsonata length before attempting to find entity ids (e3de59e)
  • time: use correct i18n errror message (be3db24)
  • Use correct element id for update all button (6bcf9a8)
  • use the correct RED (03bb7a0)

Documentation

  • Add github discussions link to header (dfa74a7)
  • Add new nodes to index (7b305d0)
  • Add new nodes to TOC (9a73e86)
  • cookbook: Correct spelling (28928b4)
  • cookbook: Update starting flow after HA reboot (388b70a)
  • current-state: add information about custom outputs (e9fcb91)
  • events-state: Add custom output information (e2a11a9)

Buy me a coffee For those that enjoy my work.

5 Likes

Double post, but I think better fit…

please help me out… I have 772 home assistant nodes…

Hi, I recently had this message upon starting node-red:

image
(screenshot from my test instance)
And this when pressing:
image

But I decided not yet to press it… so I opened 1 node and did not save…

then the button disappeared and now I think I have to manually open and save all nodes?

Is there a better way? And what is it for?

If you still have any “old” nodes refreshing the page should bring back the button.

You can also open up a console in your browser dev tools and run the function nodeVersion.getOldNodeCount(). That will show how many actual “old” nodes you still have.