How to update the iconColor of the worldmap location with a Switch?

As per the info tab on the right - the worldmap expect a msg.payload in that contains the correct properties... so you need to move your global object (SS1) to msg.payload .

Secondly, your functions don't actually update the SS1 object at all.

[{"id":"b23ac93d.e59928","type":"ui_switch","z":"7faf16f4.f02bf8","name":"","label":"switch","tooltip":"","group":"20eb736d.1f02ec","order":0,"width":0,"height":0,"passthru":false,"decouple":"false","topic":"emspe3593/SS/status/SS1","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":70,"y":40,"wires":[["4e011ec0.8eb96","95ce1724.802e78"]],"outputLabels":["1"]},{"id":"4e011ec0.8eb96","type":"debug","z":"7faf16f4.f02bf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":210,"y":100,"wires":[]},{"id":"eeb9de6.917d32","type":"debug","z":"7faf16f4.f02bf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":230,"y":140,"wires":[]},{"id":"e78f29e.162a6d8","type":"debug","z":"7faf16f4.f02bf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":140,"wires":[]},{"id":"9bc1813.553228","type":"debug","z":"7faf16f4.f02bf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":230,"y":260,"wires":[]},{"id":"95ce1724.802e78","type":"mqtt out","z":"7faf16f4.f02bf8","name":"pub","topic":"","qos":"0","retain":"","broker":"8f24b48d.99d0f8","x":190,"y":40,"wires":[]},{"id":"8dfc8023.8f859","type":"mqtt in","z":"7faf16f4.f02bf8","name":"sub","topic":"emspe3593/SS/+/SS1","qos":"0","broker":"8f24b48d.99d0f8","x":70,"y":140,"wires":[["eeb9de6.917d32","d4385da2.dbddc"]]},{"id":"82fefb36.15c118","type":"worldmap","z":"7faf16f4.f02bf8","name":"","lat":"","lon":"","zoom":"11","layer":"OSM","cluster":"4","maxage":"","usermenu":"hide","layers":"hide","panit":"true","panlock":"false","path":"","x":590,"y":340,"wires":[]},{"id":"879eaf11.b2089","type":"function","z":"7faf16f4.f02bf8","name":"Add SS1","func":"var SS1 = global.get('SS1');//define global var for SS1\nSS1  =  {\n    name:\"SS1 : Kurunegala\", \n    lat:7.486944, \n    lon:80.365045,\n    icon:\"tag\",\n    iconColor:\"dark\",\n    extrainfo:\"Hello ! this is station 1\"\n};\nmsg.payload= SS1;\nglobal.set('SS1',SS1);\n\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":340,"wires":[["c6c91d2b.18c3d","82fefb36.15c118"]]},{"id":"d4385da2.dbddc","type":"switch","z":"7faf16f4.f02bf8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"true","vt":"str"},{"t":"cont","v":"false","vt":"str"}],"checkall":"true","repair":true,"outputs":2,"x":210,"y":180,"wires":[["e78f29e.162a6d8","bbb39752.ca0988"],["9bc1813.553228","f187557b.a73df8"]]},{"id":"c6c91d2b.18c3d","type":"debug","z":"7faf16f4.f02bf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":450,"y":400,"wires":[]},{"id":"bbb39752.ca0988","type":"function","z":"7faf16f4.f02bf8","name":"ON","func":"var SS1 = global.get('SS1');\nSS1.iconColor=\"green\";\n\nmsg.payload = SS1;\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":180,"wires":[["76542416.e6cdcc","82fefb36.15c118"]]},{"id":"76542416.e6cdcc","type":"debug","z":"7faf16f4.f02bf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":180,"wires":[]},{"id":"3a1f35f0.b7a14a","type":"inject","z":"7faf16f4.f02bf8","name":"","topic":"","payload":"SS1","payloadType":"global","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":340,"wires":[["879eaf11.b2089"]]},{"id":"f187557b.a73df8","type":"function","z":"7faf16f4.f02bf8","name":"OFF","func":"var SS1 = global.get('SS1');\nSS1.iconColor=\"red\";\nmsg.payload = SS1;\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":220,"wires":[["d957b425.c60ac8","82fefb36.15c118"]]},{"id":"d957b425.c60ac8","type":"debug","z":"7faf16f4.f02bf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":610,"y":220,"wires":[]},{"id":"1bda9066.f8f03","type":"inject","z":"7faf16f4.f02bf8","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"","x":90,"y":460,"wires":[["35864007.be8b5"]]},{"id":"2d26c3e0.29e6ec","type":"ui_template","z":"7faf16f4.f02bf8","group":"20eb736d.1f02ec","name":"","order":2,"width":"6","height":"8","format":"<div ng-bind-html=\"msg.payload | trusted\"></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":440,"y":460,"wires":[[]]},{"id":"35864007.be8b5","type":"template","z":"7faf16f4.f02bf8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<iframe src=\"../worldmap\" height=450px width =500px ></iframe>","x":240,"y":460,"wires":[["2d26c3e0.29e6ec"]]},{"id":"20eb736d.1f02ec","type":"ui_group","z":"","name":"ON/OFF","tab":"a3d58218.904ef","disp":false,"width":"6","collapse":false},{"id":"8f24b48d.99d0f8","type":"mqtt-broker","z":"","name":"","broker":"test.mosquitto.org","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"a3d58218.904ef","type":"ui_tab","z":"","name":"Station Status","icon":"dashboard","disabled":false,"hidden":false}]

Though you may not need to use global context at all unless you need to for some reason not stated. The MQTT broker can retain the value of the switch - and that can be used to set the iconColor when it connects and changes.

1 Like