Node-red-contrib-home-assistant-websocket

Release v0.5.1

Fixed

  • Fixed get-entities to use custom label if valid

  • Correct possessive apostrophe in trigger state node constraint list (@albertnis)

  • Fixed condition where wildcard type state changes fired before current states were actually saved

  • Fixed onDeploy for trigger-state node when using substring/regex for entity id


If you run into any issues please report them on github


Buy me a coffee For those that enjoy my work.

After a crash of my home assistant, I’m moving a lot of my applications into Docker. I have node-red operating in a Docker, but I’m having an issue with installing the home-assistant-websocket node. I don’t have issues with other nodes, so I’m assuming that it’s maybe a port forwarding issue, or similar inside of Docker. You may, or may not, be able to help and I thought I’d just throw it out and see.

So, the installation goes just fine and completes without any errors. However, as soon as I restart the Docker I receive errors that the nodes can’t be deployed. When checking the status I see the blow:

Screenshot%20from%202018-12-31%2008-46-37

Also, pulling up the node-red log gives me this:

31 Dec 16:45:13 - [info]

Welcome to Node-RED

===================

31 Dec 16:45:13 - [info] Node-RED version: v0.19.5

31 Dec 16:45:13 - [info] Node.js version: v6.11.0

31 Dec 16:45:13 - [info] Linux 4.14.79-v7+ arm LE

31 Dec 16:45:14 - [info] Loading palette nodes

31 Dec 16:45:18 - [warn] ------------------------------------------------------

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/server] SyntaxError: Unexpected identifier

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/server-events] SyntaxError: Unexpected identifier

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/server-state-changed] SyntaxError: Unexpected identifier

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/trigger-state] SyntaxError: Unexpected identifier

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/poll-state] SyntaxError: Unexpected identifier

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/api-call-service] SyntaxError: Unexpected identifier (line:2)

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/ha-fire-event] SyntaxError: Unexpected identifier (line:1)

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/api-current-state] SyntaxError: Unexpected identifier

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/ha-get-entities] SyntaxError: Unexpected identifier

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/api-get-history] SyntaxError: Unexpected identifier (line:2)

31 Dec 16:45:18 - [warn] [node-red-contrib-home-assistant-websocket/api-render-template] SyntaxError: Unexpected identifier (line:2)

31 Dec 16:45:18 - [warn] ------------------------------------------------------

Any idea on what might be causing this? As mentioned earlier, I don’t have any issues with the installation of other simpler nodes such as timers, etc.

Thanks in advance!

From the README

If you're running Node-Red in Docker you'll need to pull the -v8 image for this to work.

Okay, I’ll give that a shot. It’s running on a Pi so I went with the RPI variant. I’ll see if the v8 plays well with that hardware.

Thanks for the help. I’ll report back once I have a chance to try it out.

there’s a raspberry pi v8 version

rpi-v8

Hi,
I’m running node-red in a docker-container, and have installed this module through the pallette. Home assistant is running on a different host in the same network. Everything is working fine at first, I can set up some flows and test them, node-red receives the events it supposed to. But, when left over night, the connection is somehow lost. I need to restart the nodered container to get the connection back.
I can’t find anything in the logs suggesting that the connection is lost, only thing there is [info] [server:Hass] WebSocket Connected to <host>.

I’m a new with node-red, can I enable some extended logging to help out with debugging?

I don’t see anything on the home assistant side on losing connection. Should I enable some debug logging there as well?

I’m running v0.5.1 of the module, but it was the same thing in previous verison.
Node-red docker-compose container running on fedora host:

[info] Node-RED version: v0.19.5
[info] Node.js  version: v8.12.0
[info] Linux 4.18.19-100.fc27.x86_64 x64 LE

Edit: When the connection is lost, the node-red ui seems happy, but it won’t receive any events from home assistant.

When it goes into its “non receiving” state are you able to trigger a call-service node and see if it completes, like turning a light on/off?

Yes. In that state, I can use the inject node to trigger a service call

The injected call succeeds, and my light is toggled. But when I click my button that triggers the event, nothing gets in the debug log.

Above is just one example. I have a flow that listens for other events, and another that listens for state change. Both behave the same as the above.

Quick but for me complex question.

What does this actually mean?

“Call Service and Fire Event nodes are now able to render mustache templates in the data property. Templates also work on the new entity id field for the Call Service node”

Any property of the message object that gets passed into a call-service node is accessible via a template variable.

Example message object being passed in

message: {
  payload: "home",
  data: {
    attributes: {
       friendly_name: "Jason"
    }
  }
}

You can use these values within the Data field. Variables are defined by having double curly brackets around them. So to access the message.payload you would use {{payload}}

Before you were able to use templates within the data string you had to use a template or function node to format the data property before passing it to the call-service node.

Try dropping a events: all node with a full debug message node and see if that is still outputing events.

[{"id":"e5b10769.4c9968","type":"server-events","z":"ffbd7f06.4a014","name":"","server":"2dad33ee.42bf5c","event_type":"","x":204,"y":784,"wires":[["1b5ee05f.b199f"]]},{"id":"1b5ee05f.b199f","type":"debug","z":"ffbd7f06.4a014","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":338,"y":784,"wires":[]}]

Kermit

Is there any difference (dumb question time) between ‘node-red-contrib-home-assistant-websocket’ and ’ Community Hass.io Add-ons: Node-RED’?

The terminology (for a non-tech person) confuses me.

I have been using ’ Community Hass.io Add-ons: Node-RED’ for a long time, and when I look at the pallet manager I can see ‘node-red-contrib-home-assistant-websocket’ as installed

I am considering (as I have a spare 3B+) putting Node Red with your branch and my MQTT broker on it.

The add-on merely runs node-red in a container. It has a preconfigured palette to connect to home Assistant

The ‘node-red-contrib-home-assistant-websocket’ is the palette used in node-red

Because that’s the palette being used by the add-on.

Node-red is really nothing to do with home assistant. It’s a separate project that has been around for years. There just happens to be a way to connect to home assistant and use it. Some of us don’t run hassio, but use node-red to run our automation, so the palette is a way for us to connect them.

Thanks @Kermit for this!

Just migrated to it from the llat version…totally painless - all previous flows work fine.

To confirm what I did:

Stop Node Red
cd to the Node Red directory on my box
nano package.json
remove the line with the node-red-contrib-home-assistant-llat package, close and save file.

cd  node-modules
rm -r node-red-contrib-home-assistant-llat
cd ..
npm install node-red-contrib-home-assistant-websocket

Then reboot. I then created a new access token in HA and everything connected!

The reason I manually removed the old package is that I was having all sorts of issues with files being left behind the other way.

Thanks again and hopefully I am ‘future proofed’ for a while as I know the llat node is not being developed any further.

I spoke too soon. After about 2 hours I get errors:

‘Error calling service. Home Assistant API error’

Reboot and it works for another couple of hours.

I am on HA 0.84.6, NR 19.2 on the latest version of the node. Tried using both access token and legacy password. Running it in a LXC container (not docker). Weird as I saw issue HERE that has been closed but it seems to describe the intermittent issue I had.

Restored from a backup (i just love Linux containers!) and back on the LLAT at the moment. Any ideas?

Thank you. Appreciate the explanation.

Can you post your call-service node and the a full output debug message of the node before the call-service node?

I misread your post, and outputed msg.payload. At 3 AM, the events just stopped coming in. Nothing in the node-red debug log indicates anything wrong, and nothing in home assistant. I’ve updated the debug print, and added debug logging for homeassistant.components.websocket_api. I hope I can get something good out of that.

Doing a re-deploy seem to wake the connection, and the events come in again.

I also have a polling flow, that stops working at the same time. So even if the websocket is up, it seems stale.

Will do in a bit. Need to reinstall node again to do this.

I did do it yesterday again and although it worked, it took about a minute for state changes etc - if at all.
A re-deploy got things working again for about 5 mins before it broke. I’ll see when I have time later today to reinstall as obviously troubleshooting without the logs is impossible!

Once I rolled back to the LLAT node all worked fine again and motion sensors etc were instant.

Thanks

EDIT: looking at dlindau’s post - these seem to be the exact issues I am getting. You wouldn’t know there are issues in the UI or in HA…except that nothing is being passed (or if so very slowly) from HA to NR. All node show as connected.