in the last few weeks I’ve notices that some HomeAssistant automation are not working as expected. My automation are built 90% on NodeRed and the rest in Home Assistant. I hadn’t had time to investigate untill yesterday. It seems that the problem ca be found on the Node Red side, and I’d found that every automation that has a function node retriving information FROM Home Assistant is not working anymore.
After some test I’d found that I can’t get/read any “state” from Home Assistant FROM a function note. Neither with simple function like
const ha = global.get('homeassistant').homeAssistant.states;
var test = ha["sensor.maindoor"].state;
msg.payload = test;
return msg;
I have almost 20 automations that are using function node to retrive states from HA and none are working anymore. Maybe it’s some update related?
OK, I’ve found the problem BUT I don’t understand WHY is a problem now and not before or why “the server name” is changed.
As you can see I’m creating a constant variable named “ha”
const ha = global.get('homeassistant').homeAssistant.states;
The problem is the “homeAssistant.states;” because is wrong. If I modify it to “homeassistant.states;” the function node start to work again.
I don’t understand how a server name can change.
When you set up the Home Assistant websocket nodes, you will have added a home assistant server configuration node. You can find this by looking under the config tab of the debug right hand window.
This sets up the server, which if you have the option set, will copy the HA state to the global context, using a variable name ‘homeassistant’.
Under this you will find your HA server instance, which is called by the name given to the config node.
Hence the ‘homeassistant’ context name is the name given by the server, and the ‘homeAssistant’ object name is the name given by you, which you can change. If you change this name on the config node then it will change how it is saved in the context, so I guess that either you or a recent update has modified this name.
I have two machines running HA, and I have set up two HA servers, one local and one remote. I have named the config nodes differently (so I can tell which is which) and you can see I therefore have homeassistant.hA1 and homeassistant.hA2, since the object name given is the config name with the first letter lower case.