Dump Global contents to dashboard

Hi, I'm trying to dump the contents of global object into a dashboard, but I'm not having success.
In my node-red, I persist the values of my sensors per room in the global object, like:

global.rooms.living - temperature
L hummidity
L etc
bathroom - temp
L other...

What I want is to loop through the rooms printing it's name, and then all it's properties. The problem I have is that rooms name is variable and so the sensor data. I can't made them hard-coded in the template.
Does anyone knows how to make this?

Heres a stackoverflow question that might set you going...

You can use a change node, set msg.payload to jsonata with the global variable:
$globalContext("rooms")

This will output an array with the names.

Create the global as an object. Here is the idea

[{"id":"c242fa4f.e1aae","type":"inject","z":"985bfce.e485c","name":"Livingroom","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":100,"wires":[["676c3531.a8386c"]]},{"id":"dbd3a6b4.ceba","type":"inject","z":"985bfce.e485c","name":"Den","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":180,"wires":[["8154f67.6a65988"]]},{"id":"b86297b3.c5a81","type":"inject","z":"985bfce.e485c","name":"Kitchen","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":260,"wires":[["590311d9.096328"]]},{"id":"676c3531.a8386c","type":"change","z":"985bfce.e485c","name":"","rules":[{"t":"set","p":"house.livingroom","pt":"global","to":"{\"temperature\":67,\"humidity\":56}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":100,"wires":[[]]},{"id":"590311d9.096328","type":"change","z":"985bfce.e485c","name":"","rules":[{"t":"set","p":"house.kitchen","pt":"global","to":"{\"temperature\":84,\"humidity\":86}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":260,"wires":[[]]},{"id":"8154f67.6a65988","type":"change","z":"985bfce.e485c","name":"","rules":[{"t":"set","p":"house.den","pt":"global","to":"{\"temperature\":78,\"humidity\":51}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":180,"wires":[[]]}]

click on each and then go look at the context and you will see
23%20AM

@bakman2 @zenofmud Thanks for your answers. I did not explain myself so well. I already have the global.rooms object populated. I do it in other parts of my flows for every sensor. My problem is printing the global.rooms object content into a dashboard.
Sorry for not explaining enough, I should have added the flow section:

[{"id":"c9a71c7d.055ca","type":"comment","z":"3bddddc6.ae5322","name":"Global output","info":"","x":110,"y":580,"wires":[]},{"id":"edfb10e4.c5c12","type":"inject","z":"3bddddc6.ae5322","name":"","topic":"","payload":"rooms","payloadType":"global","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":640,"wires":[["6174d9b3.acc278","1bcf428a.30278d"]]},{"id":"1bcf428a.30278d","type":"ui_template","z":"3bddddc6.ae5322","group":"8a8631eb.55035","name":"Rooms Output","order":1,"width":"6","height":"12","format":"<ul>\n <li ng-repeat=\"x in msg.payload\">\n <font color=\"red\">{{x.name}}</font> <!-- how to get the room name? -->\n    <ul> <!-- don't want this to be hard-coded, want to iterate -->\n        <li>{{x.temp}}</li>\n        <li>{{x.hum}}</li>\n    </ul>\n </li>\n</ul>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":460,"y":640,"wires":[[]]},{"id":"6174d9b3.acc278","type":"debug","z":"3bddddc6.ae5322","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":270,"y":620,"wires":[]},{"id":"8a8631eb.55035","type":"ui_group","z":"","name":"Global Dump","tab":"ffc494ce.ad9f28","disp":true,"width":"6","collapse":false},{"id":"ffc494ce.ad9f28","type":"ui_tab","z":"3bddddc6.ae5322","name":"Log","icon":"dashboard","order":4,"disabled":false,"hidden":false}]

Try this:

[{"id":"faa4a9f9.5b626","type":"ui_template","z":"50a9d0fb.ca78d","group":"a7708ea.3d20df","name":"Rooms Output","order":1,"width":"6","height":"12","format":"<ul>\n <li ng-repeat=\"(key, value) in msg.payload\">\n <font color=\"red\">{{key}}</font>\n    <ul>\n        <li>{{value.temperature}}</li>\n\n    </ul>\n </li>\n</ul>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":556,"y":840,"wires":[[]]},{"id":"80bb6c9c.689268","type":"change","z":"50a9d0fb.ca78d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$globalContext(\"rooms\")","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":336,"y":812,"wires":[["e8f1bbfe.f80c4","faa4a9f9.5b626"]]},{"id":"e8f1bbfe.f80c4","type":"debug","z":"50a9d0fb.ca78d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":546,"y":784,"wires":[]},{"id":"1aebde81.b07921","type":"inject","z":"50a9d0fb.ca78d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":144,"y":812,"wires":[["80bb6c9c.689268"]]},{"id":"a7708ea.3d20df","type":"ui_group","z":"","name":"Global Dump","tab":"22d42ec3.5ddd32","disp":true,"width":"6","collapse":false},{"id":"22d42ec3.5ddd32","type":"ui_tab","z":"50a9d0fb.ca78d","name":"Log","icon":"dashboard","order":4,"disabled":false,"hidden":false}]
1 Like

Thanks @bakman2, with a slight modification on your proposal I've got what I wanted:

<ul>
 <li ng-repeat="(key, value) in msg.payload">
 <font color="red">{{key}}</font>
    <ul>
        <li ng-repeat="(key, value) in value">
            {{key}} - {{value}}
        </li>
    </ul>
 </li>
</ul>

That dumps every property for each node.

1 Like