Keep value from another flow on update

#1

I am using a template node to create a machine status page. Here is a screenshot.
image

My problem is when I get a status from a different machine, it clears the machine in red.
The white machine should be green and the red machine should be red.
image
image

The LED needs to keep the last value, unless it changes.

I think that I am struggling with storing values. I have looked at the tutorials and the storing value page on the NR site, but I do not understand.

Here is my code:
[{"id":"5116599.e09b4a8","type":"ui_template","z":"ab8609d3.76eee8","group":"f6f1d68f.b33788","name":"InCycle LH35N-3000B","order":4,"width":"0","height":"0","format":"<style>\n.led {\n float: right;\n padding: 3px;\n width: 10px;\n height: 10px;\n margin: 2px 5px 5px 5px;\n border-radius: 0%;\n \n}\n</style>\n\n<div>LH35N-3000B {{msg.topic}}<span class=\"led\" style=\"background-color: {{msg.payload}}; box-shadow: black 0 -1px 1px 0px, inset black 0 -1px 4px, {{msg.payload}} 0 3px 15px;\"></span></div>\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":2600,"y":280,"wires":[["8ae78367.ad921"]]},{"id":"8ae78367.ad921","type":"change","z":"ab8609d3.76eee8","name":"","rules":[{"t":"set","p":"lh35n3000b","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2920,"y":200,"wires":[["9980e230.a9d4c"]]},{"id":"9980e230.a9d4c","type":"link out","z":"ab8609d3.76eee8","name":"LED LH35N-3000B Status out","links":["d57a88ba.5a8d08"],"x":3075,"y":200,"wires":[]},{"id":"d57a88ba.5a8d08","type":"link in","z":"ab8609d3.76eee8","name":"LED LH35N-3000B Status in","links":["9980e230.a9d4c","84c214e8.33f3c8","79f69d72.a0f734"],"x":2975,"y":280,"wires":[["a8da5e89.290ef","4a49bfa0.b56b9"]]},{"id":"a8da5e89.290ef","type":"ui_template","z":"ab8609d3.76eee8","group":"df7f71ac.38225","name":"","order":0,"width":"27","height":"10","format":"<!DOCTYPE html>\n<html lang=\"en\">\n <body>\n <style>\n.img {\n width: 100%;\n height: 100%;\n}\n.led35nb {\n position: absolute;\n padding: 3px;\n width: 10px;\n height: 10px;\n margin: 2px 5px 5px 5px;\n border-radius: 0%;\n top: 310px;\n right: 660px;\n}\n.led35n {\n position: absolute;\n padding: 3px;\n width: 10px;\n height: 10px;\n margin: 2px 5px 5px 5px;\n border-radius: 0%;\n top: 280px;\n right: 660px;\n}\n.ledht {\n position: absolute;\n padding: 3px;\n width: 10px;\n height: 10px;\n margin: 2px 5px 5px 5px;\n border-radius: 0%;\n top: 270px;\n right: 360px;\n}\n\n</style>\n <div class=\"container\">\n <a><span class=\"led35nb\" style=\"background-color: {{msg.lh35n3000b}}; box-shadow: black 0 -1px 1px 0px, inset black 0 -1px 4px, {{msg.lh35n3000b}} 0 3px 15px;\"></span></a>\n <a><span class=\"led35n\" style=\"background-color: {{msg.lh35n3000}}; box-shadow: black 0 -1px 1px 0px, inset black 0 -1px 4px, {{msg.lh35n3000}} 0 3px 15px;\"></span></a>\n <a><span class=\"ledht\" style=\"background-color: {{msg.ht}}; box-shadow: black 0 -1px 1px 0px, inset black 0 -1px 4px, {{msg.ht}} 0 3px 15px;\"></span></a>\n <img src=\"/turning.png\" alt=\"turning\" class=\"img\">\n </div>\n \n </body>\n\n</html>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":3100,"y":280,"wires":[[]]},{"id":"4a49bfa0.b56b9","type":"debug","z":"ab8609d3.76eee8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":3130,"y":380,"wires":[]},{"id":"f6f1d68f.b33788","type":"ui_group","z":"","name":"Shaft Turning Room","tab":"157f0329.92370d","order":1,"disp":true,"width":"6","collapse":false},{"id":"df7f71ac.38225","type":"ui_group","z":"","name":"Turning Room","tab":"3679129f.641f9e","disp":true,"width":"27","collapse":false},{"id":"157f0329.92370d","type":"ui_tab","z":"","name":"All - MC Status","icon":"dashboard","order":37},{"id":"3679129f.641f9e","type":"ui_tab","z":"","name":"Testing","icon":"dashboard"}]

0 Likes

#2

It is not possible to import your flow. Please try using the 3 backticks before and after the code.

0 Likes

#3

Thank you! I added the backticks.

0 Likes

#4

Apparently, you did not share the full code. Perhaps you have nodes spread over more than one tab ? I remind you that when you export a flow you are exporting only the nodes from a single tab.

From what is available I can see that you set the color of the led35nb using below node change but I can´t see where you set the value for the led35n, so it is not possible to understand the logic in your code.

At the end what display the color of the leds in this chunk of code, so it is critical to understand where and how the properties msg.lh35n3000 and msg.lh35n3000b are configured.

 <a><span class="led35nb" style="background-color: {{msg.lh35n3000b}}; box-shadow: black 0 -1px 1px 0px, inset black 0 -1px 4px, {{msg.lh35n3000b}} 0 3px 15px;"></span></a>
 <a><span class="led35n" style="background-color: {{msg.lh35n3000}}; box-shadow: black 0 -1px 1px 0px, inset black 0 -1px 4px, {{msg.lh35n3000}} 0 3px 15px;"></span></a>
0 Likes

#5

I have a separate tab for each machine. The lh35n3000 machine has the same change node and links to the template node.

Thanks,

Mike

0 Likes

#6

I understand now. You have to make sure that the template node will always get the input msg with values assigned for each and every background-colors. Nowadays the template is getting msgs with undefined values. Probably the easiest way to handle this is using global variables, like shown in below flow.

Flow:

[{"id":"cbfe06cd.3ed808","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"e4516210.98ee4","type":"change","z":"cbfe06cd.3ed808","name":"","rules":[{"t":"set","p":"lh35n3000","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":140,"wires":[["ca8e80ee.bcd5"]]},{"id":"3e2c66a0.09c9ca","type":"ui_template","z":"cbfe06cd.3ed808","group":"5647c8f1.30bf68","name":"","order":0,"width":"27","height":"10","format":"<!DOCTYPE html>\n<html lang=\"en\">\n <body>\n <style>\n.img {\n width: 100%;\n height: 100%;\n}\n.led35nb {\n position: absolute;\n padding: 3px;\n width: 10px;\n height: 10px;\n margin: 2px 5px 5px 5px;\n border-radius: 0%;\n top: 310px;\n right: 660px;\n}\n.led35n {\n position: absolute;\n padding: 3px;\n width: 10px;\n height: 10px;\n margin: 2px 5px 5px 5px;\n border-radius: 0%;\n top: 280px;\n right: 660px;\n}\n.ledht {\n position: absolute;\n padding: 3px;\n width: 10px;\n height: 10px;\n margin: 2px 5px 5px 5px;\n border-radius: 0%;\n top: 270px;\n right: 360px;\n}\n\n</style>\n <div class=\"container\">\n <a><span class=\"led35nb\" style=\"background-color: {{msg.lh35n3000b}}; box-shadow: black 0 -1px 1px 0px, inset black 0 -1px 4px, {{msg.lh35n3000b}} 0 3px 15px;\"></span></a>\n <a><span class=\"led35n\" style=\"background-color: {{msg.lh35n3000}}; box-shadow: black 0 -1px 1px 0px, inset black 0 -1px 4px, {{msg.lh35n3000}} 0 3px 15px;\"></span></a>\n <a><span class=\"ledht\" style=\"background-color: {{msg.ht}}; box-shadow: black 0 -1px 1px 0px, inset black 0 -1px 4px, {{msg.ht}} 0 3px 15px;\"></span></a>\n <img src=\"/turning.png\" alt=\"turning\" class=\"img\">\n </div>\n \n </body>\n\n</html>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":940,"y":200,"wires":[[]]},{"id":"b1db552.49d27a8","type":"inject","z":"cbfe06cd.3ed808","name":"","topic":"BreakDown","payload":"#FF0000","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":180,"wires":[["e4516210.98ee4"]]},{"id":"63bd4513.c4898c","type":"inject","z":"cbfe06cd.3ed808","name":"","topic":"InCycle","payload":"#00FF00","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":260,"y":140,"wires":[["e4516210.98ee4"]]},{"id":"6edf2b29.0535c4","type":"change","z":"cbfe06cd.3ed808","name":"","rules":[{"t":"set","p":"lh35n3000b","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":260,"wires":[["ca8e80ee.bcd5"]]},{"id":"41a483e5.b59cbc","type":"inject","z":"cbfe06cd.3ed808","name":"","topic":"BreakDown","payload":"#FF0000","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":300,"wires":[["6edf2b29.0535c4"]]},{"id":"9d290725.62c838","type":"inject","z":"cbfe06cd.3ed808","name":"","topic":"InCycle","payload":"#00FF00","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":260,"wires":[["6edf2b29.0535c4"]]},{"id":"ca8e80ee.bcd5","type":"function","z":"cbfe06cd.3ed808","name":"Read Global Status","func":"msg.lh35n3000b = global.get(\"lh35n3000b\");\nmsg.lh35n3000 = global.get(\"lh35n3000\");\nmsg.ht = global.get(\"ht\");\nreturn msg;","outputs":1,"noerr":0,"x":770,"y":200,"wires":[["3e2c66a0.09c9ca"]]},{"id":"5647c8f1.30bf68","type":"ui_group","z":"","name":"Turning Room","tab":"18ccbd6a.e61163","disp":true,"width":"27","collapse":false},{"id":"18ccbd6a.e61163","type":"ui_tab","z":"","name":"Testing","icon":"dashboard"}]
1 Like

#7

@Andrei,

I'm sorry that I'm just getting back with you. I had been out of town, and had not gotten a chance to read your message. This was just the answer that I needed. Everything works! I have added more machines to the code and everything is working as expected.

Thanks,
Mike

1 Like

#8

In case you all were interested, here is the result!

1 Like