Hi guys, I working on my device and I have doubts how to working with context global variable object properties. You can see bellow my global context variable:
My global variable object and properties
I was use this function code to get object property storage on global variable, but I don´t know how to read for example, the property nwk_addr and the value storage (528b).
var ext_addr = global.get ("00137a0000009a99");
msg.payload = ext_addr;
return msg;
When I using the unique id (ext_addr = 00137a0000009a99) I receiving all properties, as you can see bellow. How to I can filter only one specific property for each unique id?
note that when you hover your mouse behind the properties you see 2 icons; the first is: copy path, this you can use to eliminate writing the path yourself.
Hi Guys, I working very well using a global variable in the memory, but i found problem in those variables after rpi3 reboot, the object properties disappeared (undefined) as can see below:
I storage it in the memory using this code:
var unique = String(msg.payload.name);
var Epcount = global.get('EP_Count');
var prop1 = global.get('nwk_addr1');
var prop2 = global.get('nwk_addr2');
var prop3 = global.get('ZDP_EP1');
var prop4 = global.get('ZDP_EP2');
var prop5 = global.get('attr.str');
var prop6 = global.get('ext_addr1');
var prop7 = global.get('ext_addr2');
var prop8 = global.get('ext_addr3');
var prop9 = global.get('ext_addr4');
var prop10 = global.get('ext_addr5');
var prop11 = global.get('ext_addr6');
var prop12 = global.get('ext_addr7');
var prop13 = global.get('ext_addr8');
if (Epcount ==1) {
switch (prop5) {
case 'ZBHT-2':{
var properties = {
"nwk_addr": prop1+prop2,
"nwk_addrb1":prop1,
"nwk_addrb2":prop2,
"EP1":prop3,
"ModelID":prop5,
"Ext_addrb1":prop6,
"Ext_addrb2":prop7,
"Ext_addrb3":prop8,
"Ext_addrb4":prop9,
"Ext_addrb5":prop10,
"Ext_addrb6":prop11,
"Ext_addrb7":prop12,
"Ext_addrb8":prop13,
"Type":"Netvox Thermometer"
};
HI zenofmud, thanks a lote. I already read this tutorial. But, it served for me to define how to set global variables in the memory or file.
I tried to get a global variable storage in file using:
var nwk_add = global.get('nwk_addr1',"file") but is not working.
I have success to get the object propertites just using global variable in the memory. As you can see above i have object storage in the memory and file!
Do you give me help to undertanding it well?
Unfortunately, this code does not work.
What's wrong with me? What should I change to work?
The value of the two global variables is okay for it normally!
If you want to share code in the forum, its much easier if you copy and paste the code rather than take a screenshot.
Your syntax is not right. global.get is a function, so you should use () not []:
var temp = global.get("temptest");
var hum = global.get("humtest");
Looking at the rest of your code, you are not using those variables anywhere.
You do set msg.payload.svalue to the string "temp;hum;0" - did you mean for temp and hum in that string to be replaced by the values of those variables?
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
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
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!
As a new user to node-red, I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.
Also, for accessing parts of a message, there’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.
Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.
Thanks much @Steve-Mcl for your fast feedback. Maybe I didn´t make myself clear enough: In general I have no issue to access information from any kind of objects. I just struggle with the object data that are stored in the global context as shown in the picture