In my set up it is an array - I think....
["0,0,1","0,0,0","0,0,0","0,0,0","0,0,0","0,0,20","0,0,0","0,0,0","0,0,0"]
So I think that is addressed. I don't know if deleting the context is a good idea. IT is ongoing and can be used at any time.
In my set up it is an array - I think....
["0,0,1","0,0,0","0,0,0","0,0,0","0,0,0","0,0,20","0,0,0","0,0,0","0,0,0"]
So I think that is addressed. I don't know if deleting the context is a good idea. IT is ongoing and can be used at any time.
This is part of the code where the messages are received and shown to me.
[{"id":"e6b6c8fc.bdde08","type":"ui_template","z":"9b7e7466.a4b698","group":"88a8780d.513c68","name":"Ack Event","order":15,"width":"1","height":"1","format":"<div id=\"GButtonM_AckA\">\n <md-button style=\"background-color:darkgreen\" class=\"md-button program-names small bold\">ACK\n <md-tooltip>Ack</md-tooltip>\n </md-button>\n</div>\n\n<script>\n\n(function($scope) {\n\n$('#GButtonM_AckA').on('click', function(e) {\n e.preventDefault(); //prevent default behavior\n $scope.send({\"topic\":\"momentary_regular\",\"payload\": \"Foo\"});\n});\n \n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","x":3850,"y":2820,"wires":[["9176b92e.6d44c","26cd32e8.252c1e","97b67acd.dc9af"]]},{"id":"9176b92e.6d44c","type":"change","z":"9b7e7466.a4b698","name":"Create message","rules":[{"t":"set","p":"payload","pt":"msg","to":"{ \"who\" : \"All clear\", \"colour\" : \"green\" }","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":4060,"y":2860,"wires":[["fed40e07.141c68","4d0f9491.26f514","b8dc082e.a19d58"]]},{"id":"67db5ef0.eb6e7","type":"link in","z":"9b7e7466.a4b698","name":"EVENT OCCURENCE *","links":["5eb89375.770fac","ca207e32.88b67","2797f3ee.59ba64","c1d95db5.6ee1a8","f659cfe0.f65f68","a8f77fce.998ec","eafdfa87.79d67","1cb5eeb5.de8569","8107bd82.02c35","82a007d4.d373d"],"x":4040,"y":2900,"wires":[["9e985e0a.0b003","4d0f9491.26f514","ee0be344.adcb5","fed40e07.141c68"]],"l":true,"info":"This is input from local flows."},{"id":"97b67acd.dc9af","type":"change","z":"9b7e7466.a4b698","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"trigger","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":4060,"y":2940,"wires":[["ee0be344.adcb5"]]},{"id":"ee0be344.adcb5","type":"q-gate","z":"9b7e7466.a4b698","name":"Notifications","controlTopic":"CONTROL","defaultState":"queueing","openCmd":"Go","closeCmd":"Stop","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"100","keepNewest":true,"qToggle":false,"persist":false,"x":4290,"y":2940,"wires":[["fed40e07.141c68"]]},{"id":"fed40e07.141c68","type":"function","z":"9b7e7466.a4b698","name":"Ack event","func":"var x = msg.payload.colour;\nvar who = msg.payload.who;\nvar led = msg.payload.led;\n\n//node.warn(x);\n//node.warn(who);\n\nif (who == \"All clear\")\n{\n //\n msg = {\n \"payload\": \"rgb,6,0,0,0\", // Not needed? Now handled downstrem in LED flow.\n \"who\":\"All clear\", // Depricated 2021 12 04\n \"wipe\":\"WIPE\"\n };\n \n msg1 = {payload: '<font color = '+x+'><i class=\"fa fa-bullseye fa-2x\"></i></font>',who: who};\n //\n}\nelse\n{\n //\n msg.payload = led;\n msg1 = {payload: '<font color = '+x+'><i class=\"fa fa-bullseye fa-2x\"></i></font>',who: who};\n}\n\nreturn [msg,msg1];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":4280,"y":2900,"wires":[["410375d8.ecfa5c","c2d7f5e9.a00568"],["749ca0c3.37f9b","14e74a30.ce9276"]]},{"id":"410375d8.ecfa5c","type":"link out","z":"9b7e7466.a4b698","name":"Tele_LED","links":["ccf13909.72b9f"],"x":4690,"y":2630,"wires":[],"l":true},{"id":"14e74a30.ce9276","type":"ui_text","z":"9b7e7466.a4b698","group":"88a8780d.513c68","order":14,"width":"2","height":"1","name":"Event","label":"{{msg.who}}","format":"{{msg.payload}}","layout":"row-spread","x":4690,"y":2900,"wires":[]},{"id":"88a8780d.513c68","type":"ui_group","name":"Weather Display Mode","tab":"3245f51f.065aba","order":3,"disp":false,"width":"4","collapse":false},{"id":"3245f51f.065aba","type":"ui_tab","name":"TelePi Telemetry","icon":"track_changes","order":1,"disabled":false,"hidden":false}]
Event_occurence is the incoming message and the MQTT OUT
node on the right is what goes to the LED strip - kinda.
if you want an array then
let rgb = msg.payload.split(",");
if(!msg.as_is){
let stored = flow.get("rgb[" + rgb[1] + "]") || `${rgb[0]},${rgb[1]},0,0,0`;
stored = stored.split(",");
msg.payload = `${rgb[0]},${rgb[1]},${Number(rgb[2]) || stored[2]},${Number(rgb[3]) || stored[3]},${Number(rgb[4]) || stored[4]}`;
}
flow.set("rgb[" + rgb[1] + "]", msg.payload);
return msg;
but an object would be better. your choice.
I started with a mess and went to an array as I have used them for other things and it is kind of how I think. It is an array of states of each of the LEDs.
Yeah, an object
may be better, but I don't think I will gain anything at this stage of the game.
Way too much code written now.
I am just wanting to work out a way to allow the R G B values to be altered individually by messages arriving at different times and changing the displayed colour depending on the type of messages.
The ||
option looks like that is more the one as it allows something that &&
didn't that I only realised after starting off down the &&
trail.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.