Dear All,
I am on a very steep learning curve here. I am experienced in C and .NET (the VB kind), however have now ventured into the world of micro-controllers and over the last few weeks have had to learn:
- Linux/Python
- Arduino IDE/CSharp (+ Libraries)
- ESP8266
- MQTT
- NodeRed
And now JSCRIPT!
I have managed to overcome most hurdles (thank you communities/google/YouTube/etc) but am really struggling with this bit.
Please see the flow I am struggling with below (and attached flow).
I have managed to get the selection list populating correctly in [F:Produce list of Colours], and it is this I am trying to do a better way. I want to setup a Global (or could be Flow) scope JSON array, which is what I have been attempting to do in the two Config nodes:
The end game being to actually define these values within a config file that will be read at startup. However that is another thing to learn about another day. Now I just want to be able to:
- Initialize the Global/Flow JSON array
- Access it from the [F:Produce Global List of Colours] function to produce a msg={"options":colourOptions} message for feeding the Dashboard List box.
Once I can do this, I will then be able to start randomizing the selected list item and sending this out to MQTT.
Very much appreciate any support here, and before anyone says RTFM/Google is your friend, I have and know!
BR,
Stephen
WORKING PART:
[{"id":"1cec7e4b.bebfd2","type":"mqtt in","z":"ed360b01.bc40b8","name":"","topic":"home/office/randomColour","qos":"1","datatype":"auto","broker":"cf483460.015248","x":190,"y":160,"wires":[["55d0e56d.c0702c"]]},{"id":"cc6bdc79.8b812","type":"inject","z":"ed360b01.bc40b8","name":"Force MQTT to initialise RandomColour ","topic":"","payload":"true","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":1180,"y":60,"wires":[["590c62c0.33ec2c","809ccf7f.2b889"]]},{"id":"45bcb1.db45835","type":"ui_button","z":"ed360b01.bc40b8","name":"","group":"2f7f31cd.b5f6fe","order":2,"width":"0","height":"0","passthru":false,"label":"{{payload}}","tooltip":"","color":"","bgcolor":"{{colour}}","icon":"","payload":"randomColour","payloadType":"flow","topic":"","x":890,"y":160,"wires":[["58be382e.fb6c78"]]},{"id":"f91f5b89.0a40b8","type":"change","z":"ed360b01.bc40b8","name":"Random Colour Off State","rules":[{"t":"set","p":"colour","pt":"msg","to":"#C0C0C0","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Random Colour On","tot":"str"},{"t":"set","p":"randomColour","pt":"flow","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":180,"wires":[["45bcb1.db45835"]]},{"id":"1a44efc7.22a3e","type":"change","z":"ed360b01.bc40b8","name":"Random Colour On State","rules":[{"t":"set","p":"colour","pt":"msg","to":"#FFAAAA","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Random Colour Off","tot":"str"},{"t":"set","p":"randomColour","pt":"flow","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":120,"wires":[["45bcb1.db45835"]]},{"id":"55d0e56d.c0702c","type":"switch","z":"ed360b01.bc40b8","name":"Set Switch Status","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"true","vt":"str"},{"t":"eq","v":"false","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":3,"x":450,"y":160,"wires":[["1a44efc7.22a3e"],["f91f5b89.0a40b8"],[]]},{"id":"58be382e.fb6c78","type":"switch","z":"ed360b01.bc40b8","name":"Switch State","property":"randomColour","propertyType":"flow","rules":[{"t":"eq","v":"true","vt":"str"},{"t":"eq","v":"false","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1060,"y":160,"wires":[["d72a11b4.b26a9"],["84072a17.a281b8"]]},{"id":"d72a11b4.b26a9","type":"change","z":"ed360b01.bc40b8","name":"Send false msg","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":120,"wires":[["590c62c0.33ec2c","38b1d1cf.d6988e"]]},{"id":"84072a17.a281b8","type":"change","z":"ed360b01.bc40b8","name":"Send true msg","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":200,"wires":[["590c62c0.33ec2c","809ccf7f.2b889"]]},{"id":"6ef0bc7c.4c6c14","type":"comment","z":"ed360b01.bc40b8","name":"Manage LED Random Colour","info":"","x":200,"y":100,"wires":[]},{"id":"590c62c0.33ec2c","type":"mqtt out","z":"ed360b01.bc40b8","name":"","topic":"home/office/randomColour","qos":"1","retain":"true","broker":"cf483460.015248","x":1820,"y":160,"wires":[]},{"id":"d03f768f.81fa08","type":"ui_dropdown","z":"ed360b01.bc40b8","name":"Office Colour Scheme","label":"Colour Scheme","tooltip":"Select colour scheme","place":"","group":"2f7f31cd.b5f6fe","order":1,"width":0,"height":0,"passthru":false,"options":[],"payload":"","topic":"","x":1800,"y":360,"wires":[["c672e23d.d9fb2"]]},{"id":"d4fab2f1.e61af","type":"function","z":"ed360b01.bc40b8","name":"Produce list of Colours","func":"var colourOptions = [ {\"Warm\":\"red\"},\n {\"Cool\":\"blue\"},\n {\"Earth\":\"green\"},\n {\"Spring\":\"yellow\"},\n {\"Summer\":\"pink\"},\n {\"Autumn\":\"purple\"},\n {\"Winter\":\"white\"},\n {\"GB\":\"red-blue\"},\n {\"Ireland\":\"green-yellow\"},\n {\"Ocean\":\"blue-green\"},\n {\"Rainbow\":\"rainbow\"},\n {\"Pastel\":\"pastel\"}];\n\nmsg={\"options\":colourOptions};\nreturn msg;","outputs":1,"noerr":0,"x":1520,"y":400,"wires":[["d03f768f.81fa08"]]},{"id":"9d9e8fa5.41214","type":"inject","z":"ed360b01.bc40b8","name":"Force the Colour Array to Load","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":1250,"y":400,"wires":[["d4fab2f1.e61af"]]},{"id":"c672e23d.d9fb2","type":"mqtt out","z":"ed360b01.bc40b8","name":"","topic":"home/office/ledColour","qos":"2","retain":"true","broker":"cf483460.015248","x":2040,"y":360,"wires":[]},{"id":"2bb910f0.5c364","type":"mqtt in","z":"ed360b01.bc40b8","name":"","topic":"home/office/ledColour","qos":"1","datatype":"auto","broker":"cf483460.015248","x":180,"y":360,"wires":[["d03f768f.81fa08"]]},{"id":"b8a3e55f.faad48","type":"comment","z":"ed360b01.bc40b8","name":"Manage Loading Colour List","info":"","x":200,"y":240,"wires":[]},{"id":"809ccf7f.2b889","type":"change","z":"ed360b01.bc40b8","name":"Disable the Node","rules":[{"t":"set","p":"enabled","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1510,"y":300,"wires":[["d03f768f.81fa08"]]},{"id":"38b1d1cf.d6988e","type":"change","z":"ed360b01.bc40b8","name":"Enable the Node","rules":[{"t":"set","p":"enabled","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1510,"y":240,"wires":[["d03f768f.81fa08"]]},{"id":"ba4a427a.f2999","type":"function","z":"ed360b01.bc40b8","name":"Produce Global List of Colours","func":"\nvar colourOptions;\nvar myObj = global.colourPallette1;\n\n for (var i in myObj) {\n // colourOptions += myObj.colours[i].desc + \", \"; \n print (i);\n \n }\n\nmsg={\"options\":colourOptions};\nreturn msg;","outputs":1,"noerr":0,"x":750,"y":520,"wires":[["9b387eb1.54905"]]},{"id":"6b7cf263.11766c","type":"config","z":"ed360b01.bc40b8","name":"Setup Global Colour Pallette","properties":[{"p":"colourPallette","pt":"global","to":"{\"colours\":[{\"desc\":\"Warm\",\"col\":\"red\"},{\"desc\":\"Cool\",\"col\":\"blue\"},{\"desc\":\"Earth\",\"col\":\"green\"},{\"desc\":\"Spring\",\"col\":\"yellow\"},{\"desc\":\"Summer\",\"col\":\"pink\"},{\"desc\":\"Autumn\",\"col\":\"purple\"},{\"desc\":\"Winter\",\"col\":\"white\"},{\"desc\":\"GB\",\"col\":\"red-blue\"},{\"desc\":\"Ireland\",\"col\":\"green-yellow\"},{\"desc\":\"Ocean\",\"col\":\"blue-green\"},{\"desc\":\"Rainbow\",\"col\":\"rainbow\"},{\"desc\":\"Pastel\",\"col\":\"pastel\"}]}","tot":"json"}],"active":true,"x":200,"y":520,"wires":[]},{"id":"9b387eb1.54905","type":"ui_dropdown","z":"ed360b01.bc40b8","name":"Office Colour Scheme (JSON)","label":"Colour Scheme (JSON Driven)","tooltip":"Select colour scheme","place":"","group":"2f7f31cd.b5f6fe","order":1,"width":0,"height":0,"passthru":false,"options":[],"payload":"","topic":"","x":1050,"y":520,"wires":[[]]},{"id":"cdc9b1ab.20084","type":"inject","z":"ed360b01.bc40b8","name":"Trigger JSON List Build","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":480,"y":520,"wires":[["ba4a427a.f2999"]]},{"id":"cf483460.015248","type":"mqtt-broker","z":"","name":"piMQTT","broker":"piMQTT","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"piMQTT/status","birthQos":"2","birthPayload":"Online","closeTopic":"piMQTT/status","closeQos":"2","closePayload":"Offline","willTopic":"piMQTT/status","willQos":"1","willPayload":"Disconnected"},{"id":"2f7f31cd.b5f6fe","type":"ui_group","z":"","name":"Office","tab":"bccad758.8b2e98","order":4,"disp":true,"width":"6","collapse":false},{"id":"bccad758.8b2e98","type":"ui_tab","z":"","name":"House","icon":"dashboard","order":1,"disabled":false,"hidden":false}]