Accessing data stored in global nodes

Hi there,

I have a challenge that I´m working on now for days, which, for Node-Red Pros is probably the most easy thing to solve. But as I just can´t get my head around it, I just address this to the community and see if this can be easily solved :slight_smile:

Here is my setup: Beside Home Assistant I run another Smart Home System (“Homee”) which is providing an API node for Node-Red. This API node is configured to store and constantly update data from all devices added to it in the global context of Node-Red (see picture attached).

Here is my challenge: The whole setup actually works quite well, as all device information gets synched to Node-Red. But now I want to use this information in I all kind of different flows but I just don´t know how to access this data. This can probably be done by any kind of Java Script magic in a function node but as I have literally zero coding skills, I´m quite limited here :frowning:

Request for help: This may sound pretty simple for you but if anyone could point me in the direction of how to i.e. access a current value from such node that has been stored in global context this would really help me a lot!

I dont know that those values really exist as context stores, I have yet been able to extract them. You can get the current state of entities with the get entities, event state, and current state nodes.

To set a global use a change node. Here the incoming payload will be stored as global.nameValue

To recall it. Here the out going payload will be changed to whatever the value is stored in global.nameValue

1 Like

If you want to use the data in a function-node you can use:

global.get("YOU_VAR_NAME")

for example in your case:

var value = global.get("YOU_VAR_NAME").nodes.ALL_THE_OTHER_OBJECTS.current_value;
msg.payload = value;
return msg;

the output of the function node will be the value of current_value so 0

1 Like

If I try to use that with the home assistant context I get the error.

Expected ')' and instead saw 'sensor'
var value = global.get("homeAssistant.states["sensor.flue_temp"].state");
msg.payload = value;
return msg;

So here are 2 options to get the home assistant data.

var value = global.get('homeassistant.homeAssistant.states["sensor.flue_temp"].state');
msg.payload = value;
return msg;
var ha = global.get("homeassistant");
var value = ha.homeAssistant.states["sensor.flue_temp"].state;
msg.payload = value;
return msg;

Just for completion you could also use:

var value = global.get("homeassistant").homeAssistant.states["sensor.flue_temp"].state;