Brightness Automatic

Abhängigkeit / dependence: https://flows.nodered.org/node/node-red-contrib-isonline

[{"id":"39a3f9cb.dd93b6","type":"http request","z":"e3aa70fa.b265f","name":"Get Lux","method":"GET","ret":"txt","url":"http://<PIXEL IT IP>/api/luxsensor","tls":"","x":480,"y":1000,"wires":[["593a5da4.04f414"]]},{"id":"593a5da4.04f414","type":"json","z":"e3aa70fa.b265f","name":"Pars JSON","property":"payload","action":"","pretty":false,"x":630,"y":1000,"wires":[["b5975ee6.d3795"]]},{"id":"a5e2aaf8.5aa2a8","type":"inject","z":"e3aa70fa.b265f","name":"Every 3s","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"0","x":100,"y":1000,"wires":[["3907d87b.1932d8"]]},{"id":"3907d87b.1932d8","type":"is online","z":"e3aa70fa.b265f","name":"check PIXEL IT is online","url":"PIXEL IT IP","action":"1","x":290,"y":1000,"wires":[["39a3f9cb.dd93b6"]]},{"id":"b5975ee6.d3795","type":"function","z":"e3aa70fa.b265f","name":"Brightness Logic","func":"var lux = msg.payload.lux;\nvar brightness = 255;\nvar currentBrightness = context.get(\"currentBrightness\")||-1;\n\nif (lux <= 1)\n{\n    brightness = 20;\n}\nelse if (lux <= 5)\n{\n    brightness = 30;\n}\nelse if (lux <= 10)\n{\n    brightness = 45;\n}\nelse if (lux <= 20)\n{\n    brightness = 60;\n}\nelse if (lux <= 100)\n{\n    brightness = 80;\n}\nelse if (lux <= 250)\n{\n    brightness = 100;\n}\n\nmsg.provider = \"Brightness Logic\";\nmsg.brightness = brightness;\nnode.status({ fill: \"yellow\", shape: \"ring\", text: \"Lux: \" + lux.toFixed(3) +\" | Bri: \" + brightness });\n\nif (currentBrightness != brightness)\n{\n    node.status({ fill: \"green\", shape: \"ring\", text: \"Lux: \" + lux.toFixed(3) +\" | Bri: \" + brightness +\" send!\" });\n    context.set(\"currentBrightness\", brightness);\n    return msg;\n}","outputs":1,"noerr":0,"x":810,"y":1000,"wires":[["253162af.59107e"]]},{"id":"e1c478d2.8d5b28","type":"comment","z":"e3aa70fa.b265f","name":"Brightness Automatic","info":"","x":120,"y":960,"wires":[]},{"id":"253162af.59107e","type":"link out","z":"e3aa70fa.b265f","name":"Brightness Automatic Link","links":["de85246c.e30708"],"x":975,"y":1000,"wires":[]}]