In Node Red, sometimes, when I need to check the state of an entity, it is easier to check it inside a function node instead of in a “get entities” or “current state” node.
This code:
var states = global.get('homeassistant.homeAssistant.states');
var timerstate = states["timer.timer1"].state;
seems to do the job. Is this a reliable way to do it?
Should be. I use it quite a bit myself and haven’t had any issues. The other thing you can do is to create a events: state node in a separate flow and have that feed into a change node to set a global variable. That way, as soon as it changes, it will trigger that node and update a global variable.
Either way should work well and accomplish what you want to do.
Instead of creating a new array of all the entites in global home assistant I just reference the exact location
var newLocation = global.get("homeassistant.homeAssistant.states['device_tracker.mkx_location'].state");
if you click the context tab on the right side (where debug is & probably under the down arrow)
you can see all the flow variables/ global variables and then search for your entity
sometimes it can be difficult to find, when that happens I copy and paste into notepad → search for what I want and then figure out roughly where it is in the list so I can narrow down the area I’m looking in… like… oh its 25% down from the top
I am currently having a problem with a function. For now I just want to get the state of a helper and return it to the msg.payload.
The output I get is undefined. Where is the problem?
var temp1 = global.get("homeassistant.homeAssistant.states['input_text.temp_1'].state");
var newMsg = { payload: temp1};
return newMsg;