I´m not a professional programmer, so I still need help with my program. My program doesn´t work to change the background color of the ui_switch in OFFLINE state and I have no idea how I should solve it.
jbudd, I think you are very close to a solution for me
[{"id":"8d019ea56be3d90f","type":"delay","z":"b274a3816b2c7716","name":"Delay","pauseType":"delayv","timeout":"7","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":530,"y":620,"wires":[["74fad2df6cfccac7"]],"icon":"node-red-contrib-bigtimer/timer.png"},{"id":"74fad2df6cfccac7","type":"function","z":"b274a3816b2c7716","name":"Test if \"OFFLINE\"-state","func":"// Set OFFLINE\nmsg.bakgrund = \"#808080\";\nmsg.texta = \"#C0C0C0\";\nmsg.enable =false;\nmsg.payload=\"OFFLINE\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":770,"y":620,"wires":[["868716a0e25b62ac"]]},{"id":"99170cbf37c7b996","type":"mqtt in","z":"b274a3816b2c7716","name":"","topic":"tele/DEV1/STATE","qos":"2","datatype":"auto-detect","broker":"ddc04ba7b60af969","nl":false,"rap":true,"rh":0,"inputs":0,"x":140,"y":620,"wires":[["e77587ee8b33c6f2","868716a0e25b62ac"]]},{"id":"868716a0e25b62ac","type":"function","z":"b274a3816b2c7716","name":"Set \"ON\", \"OFF\" or \"OFFLINE\"","func":"var xx;\nxx=msg.payload.POWER1 ;\nmsg.payload=xx;\nmsg.topic=\"stat/DEV1/POWER1\";\nmsg.ikon = \"lightbulb_outline\";\nmsg.my_label = \"Living room\";\n\nif (xx === \"ON\") {\n msg.bg = \"#000050\" ; // set dark blue background color in ONLINE state\n msg.knob = \"#FFFF00\" ; //set knob color in ON state\n msg.enable = true ;\n } \n\nif (xx === \"OFF\") {\n msg.bg = \"#000050\" ; // set dark blue background color in ONLINE state\n msg.knob = \"#FFFF00\" ; //set yellow knob color in ON statet\n msg.enable = true ;\n }\n\nif (xx === \"OFFLINE\") {\n msg.bg = \"#303030\" ; // set gray background color in ONLINE state\n msg.knob = \"#505050\" ; //set gray knob color in OFFLINE state\n msg.enable =false;\n }\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\n//Set to OFFLINE from start until a tele message is sent from the device\n//var msg2 = { payload: msg.payload,topic:msg.topic };\n\n//setTimeout=150;\n//msg2.payload=\"OFFLINE\";\n//msg2.topic=\"stat/DEV2/POWER1\";\n//msg2.ikon = \"lightbulb_outline\";\n//msg2.etikett = \"DEV2 102\";\n//msg2.bakgrund = \"#808080\"; //dark gray background\n//msg2.texta = \"#C0C0C0\"; // gray text\n//msg2.enable =false;\n//return msg2;\n\n//var newMsg = { payload: msg.payload,topic:msg.topic };\n//return newMsg;","finalize":"","libs":[],"x":590,"y":540,"wires":[["4666ef848cd2daeb","53efc1510ee939cc"]]},{"id":"e77587ee8b33c6f2","type":"function","z":"b274a3816b2c7716","name":"Set tele check timer","func":"// check if tele-massage is received from the device every 5 minut\n// teleperiod = 300 seconds = 5 minut\nmsg.delay=360000; // wait 360 seconds \nvar m1 = {reset:true};\nreturn [[m1,msg]];","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":620,"wires":[["8d019ea56be3d90f"]]},{"id":"4666ef848cd2daeb","type":"ui_switch","z":"b274a3816b2c7716","name":"Living room DEV1","label":"{{msg.my_label}}","tooltip":"","group":"b04b273915dc4d79","order":1,"width":5,"height":1,"passthru":false,"decouple":"true","topic":"cmnd/DEV1/POWER1","topicType":"str","style":"","onvalue":"ON","onvalueType":"str","onicon":"fa-3x fa-lightbulb-o","oncolor":"YELLOW","offvalue":"OFF","offvalueType":"str","officon":"fa-2x fa-lightbulb-o","offcolor":"GRAY","animate":true,"className":"<i class=\"fa fa-toggle-off\" aria-hidden=\"true\"></i>","x":870,"y":540,"wires":[[]]},{"id":"030c7c831726a08b","type":"inject","z":"b274a3816b2c7716","name":"Assume device OFFLINE when start NodeRed","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"tele/DEV1/STATE","payload":"OFFLINE","payloadType":"str","x":400,"y":680,"wires":[["74fad2df6cfccac7"]]},{"id":"b0481c44fa76da9c","type":"ui_template","z":"b274a3816b2c7716","group":"9108a547650403e7","name":"sw0","order":4,"width":0,"height":0,"format":"<style id=\"switch-css\">\n .sw0{\n background: #000066 !important;\n }\n .sw0 > md-switch .md-thumb{\n background: gray !important;\n }\n .sw0 > md-switch.md-checked .md-thumb{\n background: yellow !important;\n }\n</style>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":770,"y":680,"wires":[[]]},{"id":"8b210b0f7395cb0e","type":"inject","z":"b274a3816b2c7716","name":"Test the OFFLINE state","props":[{"p":"payload.POWER1","v":"OFFLINE","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":160,"y":540,"wires":[["868716a0e25b62ac"]]},{"id":"0b10468d0f683269","type":"inject","z":"b274a3816b2c7716","name":"Test the OFF state","props":[{"p":"payload.POWER1","v":"OFF","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":500,"wires":[["868716a0e25b62ac"]]},{"id":"c06c1ef19c1e3d68","type":"inject","z":"b274a3816b2c7716","name":"Test the ON state","props":[{"p":"payload.POWER1","v":"ON","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":460,"wires":[["868716a0e25b62ac"]]},{"id":"53efc1510ee939cc","type":"debug","z":"b274a3816b2c7716","name":"debug 47","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":890,"y":460,"wires":[]},{"id":"ddc04ba7b60af969","type":"mqtt-broker","name":"Broker","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""},{"id":"b04b273915dc4d79","type":"ui_group","name":"Datarum","tab":"5e3aeb8c11d16ed6","order":2,"disp":true,"width":5,"collapse":true,"className":""},{"id":"9108a547650403e7","type":"ui_group","name":"Akvarium","tab":"4079a25d2b7273b5","order":9,"disp":true,"width":6,"collapse":false,"className":""},{"id":"5e3aeb8c11d16ed6","type":"ui_tab","name":"Belysning","icon":"fa-2x fa-lightbulb-o","order":1,"disabled":false,"hidden":false},{"id":"4079a25d2b7273b5","type":"ui_tab","name":"Akvarium","icon":"","order":3,"disabled":false,"hidden":false}]