Node-red-contrib-home-assistant-websocket

Hi. Hope you can help.

Just recently, every time i deploy a state node (doesn’t seem to matter which entity) I get an error. Seems to have been since I upgraded to 2021.8.8 but that could be coincidence.

I do check breaking changes before updating but … have i missed something?

“Malformed JSON in file: /config/node-red//node-red-contrib-home-assistant-websocket.json↵Unexpected token in JSON at position 0”

Thanks in advance

I would guess that node-red-contrib-home-assistant-websocket.json got corrupted at some point. If you open up the file is it empty?

That file stores the state of events nodes and sensor nodes. If it was corrupted and now is empty you can either delete it or place {} in it.

2 Likes

Good guess. I had a peek and it had somehow become a binary file (visual studio code couldn’t read it)
Deleted it, and it regenerated so it looks like that’s sorted. Nodes are now deploying without issue.

Many thanks for your help. Not a clue how it ended up in that state, but hopefully that’s the end of it.

Hi,

I’m new to both Home Assistant and Node-Red, so have been pulling my hair the last few days.
I’m no programmer, so all this yaml and json is a bit much at times :stuck_out_tongue:

I have a easy setup with a integration to my car charger and MQTT.
For now I want to change the charge mode on the charger with MQTT. Everything is set up and working with MQTT, but I have made a complete stop on how to change the entity in HA.

I’m not to familiar with domain and service and how they work. All examples I have read online have normally used a more common service, like for lights, switches and toggle etc.

Anyone that can send me in the right direction to get a better understanding of this and for future work? :slight_smile:

Edit: I changed the data string to
{ “option”: “{{ payload }}” }
Now I get no errors, but the entity does not change the value according to the MQTT payload.

Are your select options capitalized like the payload “Stopped”?

Yes,
image

Have you tried without the variable, just to see if that works?

{"option":"Stopped"}

Tried with this now, but nothing changed. The sequence is running without error, but the service node is not changing the entity.

How did you set up the input select? In the UI? If so could you delete the Stopped entry and then re-add it again. Make sure there isn’t any spaces after the entry. then try nodered again.

Hmm… Not sure what you are referring to. I’m just using the Node-Red dashboard in HA.
but it made me take a look at the domain at least. And I found the culprit.
It was not input_select, just select!
When I changed to “domain: select”, it now works! :grinning:

My original thought that Home Assistant would have a very steep learning curve is so true! :laughing:

There is an input_select in HA that has the same function, a drop down list. I didn’t realize you could set one up in nodered as well.

Recently I realized, all entity changes executed by NR are signed by Superuser user.

I have NR installed as HA addon. in Configuration nodes in NR I found “I use Hone Assistant addon” option checked. This gives no option to select a user NR actions will be signed by.
I can uncheck this, which gives me an option to enter server options: base url and access token.
Base url is prefilled with: http://supervisors/core but I doubt it’s something valid. Is it? Or what should I put here for best eficiency?

second question is: Is there an option to change logged user for selected automations in runtime? Example scenario: user triggers some action using gui. in response NR changes some entities. I would like to sign those changes by user who initialized this action

It would probably be the same instructions as using docker.

I had looked into changing users at one point and the only thing I was able to come across was the fire event node. Where you would construct a custom event rather than using a call service node.

Trying to set up that message was too much for me and I gave up.

1 Like

http://supervisors/core is the address the node-red add-on connects to the supervisor proxy. You can uncheck the I use Home Assistant add-on and connect using the IP address. https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/#configuration

context in the event data will show you what user was logged into the HA UI when an entity was changed.

edit:

TIP
Creating a separate Home Assistant user for Node-RED and using their access token will give you the ability to track which entities were changed by Node-RED.

1 Like

What about the other way around? I have 2 sensors, bluetooth and wifi, to determine presence. Now when I look at the lock entity in HA all I can see is turned on by supervisor.

Is there a way so that it showed the user that triggered the flow rather than supervisor?

Is NR changing the lock or someone via the HA UI?

thank you for clarification.
What about my second question? is it possible (or would it be possible) to change user in runtime?
I suspect it must not be done by connecting to HA with different user. But don’t know HA provides api ready for such thing.

yes, create a new user in HA and use that in the server config in NR.

I think we missunderstand each other. I’m asking about ability to set user to be logged in run time.
For example to take user who triggered the automation (from context) and use it when changing other entities.

image

[{"id":"2d794897238d2e7e","type":"inject","z":"577057499d713472","name":"HA event node","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":192,"y":304,"wires":[["79715d920ff24aa5"]]},{"id":"79715d920ff24aa5","type":"switch","z":"577057499d713472","name":"","property":"data.new_state.context.user_id","propertyType":"msg","rules":[{"t":"eq","v":"userone","vt":"str"},{"t":"eq","v":"usertwo","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":354,"y":304,"wires":[["8138b62c5e846484"],["b9825dfd0a2f0971"]]},{"id":"8138b62c5e846484","type":"api-call-service","z":"577057499d713472","name":"user one server config","server":"","version":3,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":548,"y":304,"wires":[[]]},{"id":"b9825dfd0a2f0971","type":"api-call-service","z":"577057499d713472","name":"user two server config","server":"","version":3,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":548,"y":352,"wires":[[]]}]