Circadian/Adaptive Lighting NodeRed

Okay, so I’ve been troubleshooting my original logic. Here is where I am at now… I occasionally see a gate incorrectly go closed or queuing when it should have stayed open as I have not made any manual changes to color/brightness. I think I mentioned my office lights almost always are on from early morning to late evening and the hiccups I’m seeing are generally in the evening as color_temp/brightness is reducing. There was an issue with the join node being incorrect and I had to change that and the payloads being passed from the Update module.

[{"id":"e812678d.651e28","type":"subflow","name":"Circadian Calculator","info":"","category":"time and astro","in":[{"x":80,"y":80,"wires":[{"id":"aa4b86d8.b17118"}]}],"out":[{"x":890,"y":100,"wires":[{"id":"40de744.1e2ca8c","port":0}]},{"x":890,"y":160,"wires":[{"id":"15b473ec45fa7fc4","port":0}]},{"x":930,"y":260,"wires":[{"id":"6f365d7d05905955","port":0}]},{"x":930,"y":320,"wires":[{"id":"c26bdcca.eb483","port":0}]}],"env":[],"meta":{},"color":"#FFCC66","inputLabels":["Trigger"],"outputLabels":["Brightness Value","Brightness Percent","Mireds","Kelvin"]},{"id":"5de89261.4fb97c","type":"switch","z":"e812678d.651e28","name":"curve switch","property":"payload.times_of_day.active.name","propertyType":"msg","rules":[{"t":"eq","v":"night","vt":"str"},{"t":"eq","v":"morning","vt":"str"},{"t":"eq","v":"day","vt":"str"},{"t":"eq","v":"evening","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":250,"y":220,"wires":[["ba17c1e6.e6f58","840431b7.eeefc"],["e5bb5a04.a33948","d4d99259.d0d7e"],["7c0f0774.90adf8","6ac1af7.dddb15"],["23b260f9.19f78","a907f5f4.0bf488"]]},{"id":"ba17c1e6.e6f58","type":"spline-curve","z":"e812678d.651e28","name":"night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.3},{"x":0.333,"y":0.037},{"x":0.477,"y":0},{"x":0.783,"y":0},{"x":1,"y":0}],"x":490,"y":80,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"e5bb5a04.a33948","type":"spline-curve","z":"e812678d.651e28","name":"morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.01},{"x":0.132,"y":0.01},{"x":0.269,"y":0.027},{"x":0.449,"y":0.124},{"x":0.676,"y":0.334},{"x":1,"y":0.75}],"x":500,"y":120,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"23b260f9.19f78","type":"spline-curve","z":"e812678d.651e28","name":"evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.036,"y":0.78},{"x":0.176,"y":0.63},{"x":1,"y":0.3}],"x":500,"y":200,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"7c0f0774.90adf8","type":"spline-curve","z":"e812678d.651e28","name":"daylight curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.744},{"x":0.03,"y":0.838},{"x":0.097,"y":0.941},{"x":0.183,"y":1},{"x":0.86,"y":0.995},{"x":0.943,"y":0.931},{"x":1,"y":0.85}],"x":500,"y":160,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"840431b7.eeefc","type":"spline-curve","z":"e812678d.651e28","name":"night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.5},{"x":0.067,"y":0.368},{"x":0.133,"y":0.265},{"x":0.27,"y":0.171},{"x":0.333,"y":0.16},{"x":0.506,"y":0.124},{"x":0.606,"y":0}],"x":490,"y":240,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"d4d99259.d0d7e","type":"spline-curve","z":"e812678d.651e28","name":"morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":0.42,"y":0.018},{"x":0.54,"y":0.051},{"x":0.587,"y":0.101},{"x":0.817,"y":0.675},{"x":1,"y":0.85}],"x":500,"y":280,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"a907f5f4.0bf488","type":"spline-curve","z":"e812678d.651e28","name":"evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.787,"y":0.598},{"x":1,"y":0.5}],"x":500,"y":360,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"6ac1af7.dddb15","type":"spline-curve","z":"e812678d.651e28","name":"daylight curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.123,"y":0.927},{"x":0.5,"y":1},{"x":0.92,"y":0.904},{"x":1,"y":0.85}],"x":500,"y":320,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"a330b219.92e4e","type":"function","z":"e812678d.651e28","name":"Times of Day","func":"var newmsg = JSON.parse(JSON.stringify(msg));\nnewmsg.payload.times_of_day = {};\n\nprocessTimeOfDay = function(nme, obj, name_start, name_end) {\n    var ret = {};\n    ret.name  = nme;\n    ret.start = obj.times[name_start].ts;\n    ret.end   = obj.times[name_end].ts;\n    ret.perc  = (obj.ts - ret.start) / (ret.end - ret.start);\n    \n    \n    // to cover range starting before midnight and ending after it.\n    if (ret.start > ret.end)\n    {\n        var a;\n\n        // before midnight\n        if (ret.start < obj.ts) \n        {\n            a = new Date(ret.end);\n            a.setUTCDate(a.getUTCDate() + 1);\n            ret.end = a.getTime();\n             \n             \n        }\n        else if (ret.end > obj.ts) \n        {\n            a = new Date(ret.start);\n            a.setUTCDate(a.getUTCDate() - 1);\n            ret.start = a.getTime();\n\n        }\n\n    }\n    \n    ret.perc  = (obj.ts - ret.start) / (ret.end - ret.start);\n    \n    obj.times_of_day[nme] = ret;\n    if (ret.start <= obj.ts && obj.ts < ret.end ) obj.times_of_day.active = ret;\n}\n\n\nprocessTimeOfDay('night', newmsg.payload, \"astronomicalDusk\", \"astronomicalDawn\");\nprocessTimeOfDay('morning', newmsg.payload, \"astronomicalDawn\", \"goldenHourDawnEnd\");\nprocessTimeOfDay('day', newmsg.payload, \"goldenHourDawnEnd\", \"sunsetStart\");\nprocessTimeOfDay('evening', newmsg.payload, \"sunsetStart\", \"astronomicalDusk\");\n\n\nreturn newmsg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":140,"wires":[["5de89261.4fb97c"]]},{"id":"40de744.1e2ca8c","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"1","maxout":"254","action":"clamp","round":true,"property":"payload","name":"","x":710,"y":100,"wires":[[]]},{"id":"c26bdcca.eb483","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"2700","maxout":"6500","action":"clamp","round":true,"property":"payload","name":"","x":730,"y":320,"wires":[[]]},{"id":"aa4b86d8.b17118","type":"sun-position","z":"e812678d.651e28","name":"","positionConfig":"31826811.22a458","rules":[],"onlyOnChange":"true","topic":"","outputs":1,"start":"","startType":"none","startOffset":0,"startOffsetType":"num","startOffsetMultiplier":60000,"end":"","endType":"none","endOffset":0,"endOffsetType":"num","endOffsetMultiplier":60000,"x":210,"y":80,"wires":[["a330b219.92e4e"]]},{"id":"15b473ec45fa7fc4","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"1","maxout":"100","action":"clamp","round":true,"property":"payload","name":"","x":710,"y":160,"wires":[[]]},{"id":"6f365d7d05905955","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"370","maxout":"154","action":"clamp","round":true,"property":"payload","name":"","x":720,"y":260,"wires":[[]]},{"id":"31826811.22a458","type":"position-config","name":"Home Location","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":"99","timeZoneDST":"0","stateTimeFormat":"3","stateDateFormat":"12"},{"id":"f5e1d08b.a8cd58","type":"ha-entity","z":"7ea0620.a243ca","name":"kelvin","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nr_circadian_kelvin"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:brightness-6"},{"property":"unit_of_measurement","value":"K"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"nr_circadian_kelvin","stateType":"global","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"msg","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":890,"y":260,"wires":[[]]},{"id":"365094a5.72bb5c","type":"subflow:e812678d.651e28","z":"7ea0620.a243ca","name":"","env":[],"x":480,"y":170,"wires":[["5f4a2fbe.d6b89"],["2bd57efd76cfcedf"],["eb1275669172038f","30bf6ebc.f4da52"],[]]},{"id":"e80bd956.f2e098","type":"ha-entity","z":"7ea0620.a243ca","name":"color_temp","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nr_circadian_color_temp"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:brightness-6"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"nr_circadian_mireds","stateType":"global","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":910,"y":200,"wires":[["53a933a438c1326b"]]},{"id":"476cda43.0f4c94","type":"ha-entity","z":"7ea0620.a243ca","name":"brightness","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nr_circadian_brightness"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:brightness-auto"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"nr_circadian_brightness","stateType":"global","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"block","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":910,"y":80,"wires":[["ba7018086eca537b"]]},{"id":"5f4a2fbe.d6b89","type":"function","z":"7ea0620.a243ca","name":"global brightness","func":"var new_brightness = (msg.payload == 254) ? 255 : msg.payload;\nif (new_brightness != global.get('nr_circadian_brightness')){\n    global.set('nr_circadian_brightness',new_brightness);\n    return {payload: new_brightness}\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":80,"wires":[["476cda43.0f4c94"]]},{"id":"30bf6ebc.f4da52","type":"function","z":"7ea0620.a243ca","name":"global kelvin","func":"/*var new_kelvin = msg.payload;*/\nvar new_kelvin = Math.round(1000000/msg.payload,0);\nvar old_kelvin = global.get('nr_circadian_kelvin');\nif (new_kelvin == old_kelvin) return null;\nglobal.set('nr_circadian_kelvin',new_kelvin);\nreturn {payload: new_kelvin}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":260,"wires":[["f5e1d08b.a8cd58"]]},{"id":"934e0600896a7adb","type":"link out","z":"7ea0620.a243ca","name":"Mireds","mode":"link","links":["9d3d2931ff09f30e","43c2e1ab9d4c3a33","46442d133be6f963","a52970d03d1f30a5","a897dbf21ffb2b4c"],"x":1195,"y":200,"wires":[]},{"id":"b1ee887a5f59e581","type":"link out","z":"7ea0620.a243ca","name":"Brightness","mode":"link","links":["e376d76995dda48c","4c8de271d9d32579","df433767e85260dc","3055458e27486427","4ccd12c7e9fa28f9","d72d56acc2f72b41","b1137e5488a33dda","ffa6896cb76348d5","19af89da0660a8f1"],"x":1195,"y":80,"wires":[]},{"id":"5cd0d7153aaad741","type":"ha-entity","z":"7ea0620.a243ca","name":"brightness_pct","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nr_circadian_brightness_pct"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:brightness-percent"},{"property":"unit_of_measurement","value":"%"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"nr_circadian_brightness_pct","stateType":"global","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"msg","inputOverride":"block","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":920,"y":140,"wires":[[]]},{"id":"eb1275669172038f","type":"function","z":"7ea0620.a243ca","name":"global mireds","func":"var new_mireds = msg.payload\nif (new_mireds != global.get('nr_circadian_mireds')) {\n    global.set('nr_circadian_mireds',new_mireds);\n    return msg;\n}\n\n/*\nvar new_mireds = msg.payload\nvar old_mireds = global.get('nr_circadian_mireds')\nif (new_mireds == old_mireds) return null;\nglobal.set('nr_circadian_mireds',new_mireds);\nreturn msg;\n*/\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":200,"wires":[["e80bd956.f2e098"]]},{"id":"2bd57efd76cfcedf","type":"function","z":"7ea0620.a243ca","name":"global brightness %","func":"var new_brightness_pct = msg.payload;\nvar old_brightness_pct = global.get('nr_circadian_brightness_pct');\nif (new_brightness_pct == old_brightness_pct) return null;\nglobal.set('nr_circadian_brightness_pct',new_brightness_pct);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":140,"wires":[["5cd0d7153aaad741"]]},{"id":"53a933a438c1326b","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"color_temp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":200,"wires":[["934e0600896a7adb"]]},{"id":"ba7018086eca537b","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"brightness","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":80,"wires":[["b1ee887a5f59e581"]]},{"id":"f6a0b62593cc81c1","type":"interval-multiples-timer","z":"7ea0620.a243ca","interval":"60000","payload":"","topic":"","name":"Every minute","x":86,"y":160,"wires":[["f7382c3f63fec06f"]],"outputLabels":["timestamp"]},{"id":"b49e0a964008e7ba","type":"inject","z":"7ea0620.a243ca","name":"At startup","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":96,"y":200,"wires":[["f7382c3f63fec06f"]]},{"id":"f7382c3f63fec06f","type":"api-current-state","z":"7ea0620.a243ca","name":"Circadian On?","server":"c879ac61.99cd1","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.circadian_lighting","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"date"}],"for":0,"forType":"num","forUnits":"minutes","x":280,"y":176,"wires":[["365094a5.72bb5c"],[]]},{"id":"c879ac61.99cd1","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]
1 Like

[{"id":"03454e69d1fb38da","type":"subflow","name":"Color / Brightness","info":"Color / Brightness Control commands for q-gate node","category":"","in":[{"x":340,"y":140,"wires":[{"id":"e9076938078efe18"}]}],"out":[{"x":640,"y":60,"wires":[{"id":"e9076938078efe18","port":0}]},{"x":640,"y":120,"wires":[{"id":"e9076938078efe18","port":1}]},{"x":640,"y":180,"wires":[{"id":"e9076938078efe18","port":2}]}],"env":[],"meta":{},"color":"#DDAA99","status":{"x":640,"y":240,"wires":[]}},{"id":"e9076938078efe18","type":"function","z":"03454e69d1fb38da","name":"","func":"var entity_id = msg.data.entity_id\nvar current_brightness = msg.data.new_state.attributes.brightness;\nvar current_color_temp = msg.data.new_state.attributes.color_temp;\nvar circadian_mireds = global.get(\"nr_circadian_mireds\");\nvar circadian_brightness = global.get(\"nr_circadian_brightness\");\n/*\nvar calculated_brightness_state = Math.round(circadian_brightness * 0.996078431);\nif (calculated_brightness_state == 254) {calculated_brightness_state = 255}\n*/\ncircadian_brightness = Math.round(circadian_brightness * 0.996078431) + Math.floor(circadian_brightness/255);\n\nvar debug =  \n    {\n        \"Entity\": entity_id,\n        \"Old color\": msg.data.old_state.attributes.color_temp,\n        \"New color\": msg.data.new_state.attributes.color_temp,\n        \"Current color_temp\": current_color_temp,\n        \"Circadian mireds\": circadian_mireds,\n        \"Old brightness\": msg.data.old_state.attributes.brightness,\n        \"New brightness\": msg.data.new_state.attributes.brightness,\n        \"Current brightness\": current_brightness,\n        \"Circadian brightness\": circadian_brightness\n    }\n\nif (msg.data.old_state.state == \"on\" && msg.data.new_state.state == \"on\"){\n\n        if (current_color_temp == circadian_mireds &&\n            current_brightness == circadian_brightness){\n            return [{topic: \"control\", payload: \"open\"}, {topic: \"control\", payload: \"open\"}, debug]\n        }\n        if (current_color_temp != circadian_mireds &&\n            current_brightness == circadian_brightness){\n            return [{topic: \"control\", payload: \"queue\"}, {topic: \"control\", payload: \"open\"}, debug]\n        }\n        if (current_color_temp == circadian_mireds &&\n            current_brightness != circadian_brightness){\n            return [{topic: \"control\", payload: \"open\"}, {topic: \"control\", payload: \"queue\"}, debug]\n        }\n        if (current_color_temp != circadian_mireds && \n            current_brightness != circadian_brightness){\n            return [{topic: \"control\", payload: \"queue\"}, {topic: \"control\", payload: \"queue\"}, debug]\n        }\n    }\n    \nif (msg.data.old_state.state == \"off\" && msg.data.new_state.state == \"on\"){\n    return [ { topic: \"control\", payload: \"open\", data: {color_temp: circadian_mireds}},\n             { topic: \"control\", payload: \"open\", data: {brightness: circadian_brightness}},\n             debug ]}\n\n/* payload.brightness */\n\nif (msg.data.old_state.state == \"on\" && msg.data.new_state.state == \"off\"){\n        return [{ topic: \"control\", payload: \"queue\" }, { topic: \"control\", payload: \"queue\"}, debug ]\n    }\n\nreturn [null, null, debug]\n\n","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":140,"wires":[[],[],[]]},{"id":"ae8af5aa195ee960","type":"debug","z":"03454e69d1fb38da","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"$globalContext('nr_circadian_mireds')\t","targetType":"jsonata","statusVal":"","statusType":"auto","x":420,"y":260,"wires":[]},{"id":"15d3ba0a712a2f77","type":"debug","z":"03454e69d1fb38da","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"$globalContext('nr_circadian_brightness')\t","targetType":"jsonata","statusVal":"","statusType":"auto","x":420,"y":220,"wires":[]},{"id":"71e41def.76e254","type":"server-state-changed","z":"7ea0620.a243ca","name":"Cicadian Office","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.circadian_lighting_office","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"$entity().state = \"on\" ? \"open\" : \"queue\"","valueType":"jsonata"},{"property":"topic","propertyType":"msg","value":"control","valueType":"str"}],"x":205,"y":600,"wires":[["a8f21399bc702421"]]},{"id":"60a4dca9.c29d14","type":"api-call-service","z":"7ea0620.a243ca","name":"Light 1","server":"c879ac61.99cd1","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.office_light_1"],"data":"{\t   \"brightness\": payload.brightness,\t   \"color_temp\": payload.color_temp\t}","dataType":"jsonata","mergeContext":"lightOptions","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1330,"y":420,"wires":[[]]},{"id":"3863e49219f2c06c","type":"api-call-service","z":"7ea0620.a243ca","name":"Light 2","server":"c879ac61.99cd1","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.office_light_2"],"data":"{\t   \"brightness\": payload.brightness,\t   \"color_temp\": payload.color_temp}","dataType":"jsonata","mergeContext":"lightOptions","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1335,"y":680,"wires":[[]]},{"id":"c5c6137c20db841c","type":"api-call-service","z":"7ea0620.a243ca","name":"Light 3","server":"c879ac61.99cd1","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.office_light_3"],"data":"{\t   \"brightness\": payload.brightness,\t   \"color_temp\": payload.color_temp\t}","dataType":"jsonata","mergeContext":"lightOptions","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1340,"y":940,"wires":[[]]},{"id":"5953dc0a6a10c314","type":"server-state-changed","z":"7ea0620.a243ca","name":"Office Color","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.circadian_lighting_color_office","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"topic","propertyType":"msg","value":"control","valueType":"str"},{"property":"payload","propertyType":"msg","value":"$entity().state = \"on\" ? \"open\" : \"queue\"","valueType":"jsonata"}],"x":215,"y":540,"wires":[["cd1e6d98e1856bda"]]},{"id":"3728361be31f9153","type":"server-state-changed","z":"7ea0620.a243ca","name":"Office Brightness","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.circadian_lighting_brightness_office","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"$entity().state = \"on\" ? \"open\" : \"queue\"","valueType":"jsonata"},{"property":"topic","propertyType":"msg","value":"control","valueType":"str"}],"x":205,"y":660,"wires":[["f66d24bc98a1e3de"]]},{"id":"5fcdbdfcad60b453","type":"q-gate","z":"7ea0620.a243ca","name":"color_temp 2","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":true,"persist":true,"storeName":"file","x":755,"y":700,"wires":[["b36ec2b3b096f8d6"]]},{"id":"4b80d3dcd0dcb9fa","type":"link in","z":"7ea0620.a243ca","name":"Office Light 3 Color ","links":["a8f21399bc702421","cd1e6d98e1856bda","babbee9d013605d2"],"x":620,"y":900,"wires":[["e847b97612b57cde"]]},{"id":"bb5ea6235f3f465f","type":"link in","z":"7ea0620.a243ca","name":"Office Light 2 Brightness ","links":["a8f21399bc702421","f66d24bc98a1e3de","fe02e119919f1fbf"],"x":620,"y":820,"wires":[["6e90b1ffee7f80b8"]]},{"id":"5731df33e0ef2e56","type":"q-gate","z":"7ea0620.a243ca","name":"brightness 2","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":true,"persist":true,"storeName":"file","x":755,"y":760,"wires":[["b36ec2b3b096f8d6"]]},{"id":"f38eeefba2af67ce","type":"q-gate","z":"7ea0620.a243ca","name":"color_temp 3","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":true,"persist":true,"storeName":"file","x":755,"y":960,"wires":[["1bd0cac097924a72"]]},{"id":"9dfb80638a8e3d73","type":"q-gate","z":"7ea0620.a243ca","name":"color_temp 1","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":true,"persist":true,"storeName":"file","x":750,"y":440,"wires":[["ee6e3c5a8750dbd3"]]},{"id":"22570f7cadf11491","type":"q-gate","z":"7ea0620.a243ca","name":"brightness 3","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":true,"persist":true,"storeName":"file","x":755,"y":1020,"wires":[["1bd0cac097924a72"]]},{"id":"1c0b19f6eaee2844","type":"q-gate","z":"7ea0620.a243ca","name":"brightness 1","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":true,"persist":true,"storeName":"file","x":750,"y":500,"wires":[["ee6e3c5a8750dbd3"]]},{"id":"a8f21399bc702421","type":"link out","z":"7ea0620.a243ca","name":"Circadian Office","mode":"link","links":["2a3d1ccf39330b28","4193dc61304afe65","4b80d3dcd0dcb9fa","4f8d44ef76bac586","bb5ea6235f3f465f","f6f58ab7e35f5688","dcfa43aa5b436092","43c2e1ab9d4c3a33","3055458e27486427","9d3d2931ff09f30e","df433767e85260dc","46442d133be6f963","4ccd12c7e9fa28f9"],"x":330,"y":600,"wires":[]},{"id":"448f5e6c691dccc4","type":"server-state-changed","z":"7ea0620.a243ca","name":"Light 1","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.office_light_1","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"milliseconds","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"}],"x":70,"y":440,"wires":[["9843d42f60a63e30"]]},{"id":"4193dc61304afe65","type":"link in","z":"7ea0620.a243ca","name":"Office Light 3 Brightness ","links":["a8f21399bc702421","f66d24bc98a1e3de","5da1ef5db9218f1e"],"x":620,"y":1080,"wires":[["1489ae336f7022ab"]]},{"id":"2a3d1ccf39330b28","type":"link in","z":"7ea0620.a243ca","name":"Office Light 1 Color","links":["a8f21399bc702421","b05b2fb283191597","cd1e6d98e1856bda"],"x":615,"y":380,"wires":[["11dfa753a1a2cd05"]]},{"id":"f6f58ab7e35f5688","type":"link in","z":"7ea0620.a243ca","name":"Office Light 2 Color","links":["166c734b13052fb7","a8f21399bc702421","cd1e6d98e1856bda"],"x":620,"y":640,"wires":[["7b9a79c482830d5b"]]},{"id":"4f8d44ef76bac586","type":"link in","z":"7ea0620.a243ca","name":"Office Light 1 Brightness","links":["a8f21399bc702421","a92499638df3f0ae","f66d24bc98a1e3de"],"x":615,"y":560,"wires":[["94a02ed09a89725d"]]},{"id":"ae45a60691ab54fc","type":"server-state-changed","z":"7ea0620.a243ca","name":"Light 2","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.office_light_2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"milliseconds","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"}],"x":55,"y":760,"wires":[["5bdc695b13ac08ce"]]},{"id":"900f6d3a6843c9d4","type":"server-state-changed","z":"7ea0620.a243ca","name":"Light 3","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.office_light_3","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"milliseconds","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"data","propertyType":"msg","value":"","valueType":"eventData"}],"x":55,"y":980,"wires":[["360cde2520d4ef73"]]},{"id":"f66d24bc98a1e3de","type":"link out","z":"7ea0620.a243ca","name":"Office Brightness","mode":"link","links":["4193dc61304afe65","4f8d44ef76bac586","bb5ea6235f3f465f","3055458e27486427","df433767e85260dc","4ccd12c7e9fa28f9"],"x":330,"y":660,"wires":[]},{"id":"cd1e6d98e1856bda","type":"link out","z":"7ea0620.a243ca","name":"Office Color","mode":"link","links":["2a3d1ccf39330b28","4b80d3dcd0dcb9fa","f6f58ab7e35f5688","43c2e1ab9d4c3a33","9d3d2931ff09f30e","46442d133be6f963"],"x":330,"y":540,"wires":[]},{"id":"f75a6792daaeb0b4","type":"comment","z":"7ea0620.a243ca","name":"Office","info":"","x":70,"y":340,"wires":[]},{"id":"11dfa753a1a2cd05","type":"ha-entity","z":"7ea0620.a243ca","name":"Light 1 Color Control","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Office Light 1 Color Control"},{"property":"device_class","value":"opening"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload = \"open\" ? \"on\" : \"off\"\t","stateType":"jsonata","attributes":[{"property":"command","value":"payload","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":780,"y":380,"wires":[[]]},{"id":"94a02ed09a89725d","type":"ha-entity","z":"7ea0620.a243ca","name":"Light 1 Brightness Control","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Office Light 1 Brightness Control"},{"property":"device_class","value":"opening"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload = \"open\" ? \"on\" : \"off\"\t","stateType":"jsonata","attributes":[{"property":"command","value":"payload","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":790,"y":560,"wires":[[]]},{"id":"7b9a79c482830d5b","type":"ha-entity","z":"7ea0620.a243ca","name":"Light 2 Color Control","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Office Light 2 Color Control"},{"property":"device_class","value":"opening"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload = \"open\" ? \"on\" : \"off\"\t","stateType":"jsonata","attributes":[{"property":"command","value":"payload","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":785,"y":640,"wires":[[]]},{"id":"6e90b1ffee7f80b8","type":"ha-entity","z":"7ea0620.a243ca","name":"Light 2 Brightness Control","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Office Light 2 Brightness Control"},{"property":"device_class","value":"opening"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload = \"open\" ? \"on\" : \"off\"\t","stateType":"jsonata","attributes":[{"property":"command","value":"payload","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":795,"y":820,"wires":[[]]},{"id":"e847b97612b57cde","type":"ha-entity","z":"7ea0620.a243ca","name":"Light 3 Color Control","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Office Light 3 Color Control"},{"property":"device_class","value":"opening"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload = \"open\" ? \"on\" : \"off\"\t","stateType":"jsonata","attributes":[{"property":"command","value":"payload","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":785,"y":900,"wires":[[]]},{"id":"1489ae336f7022ab","type":"ha-entity","z":"7ea0620.a243ca","name":"Light 3 Brightness Control","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Office Light 3 Brightness Control"},{"property":"device_class","value":"opening"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload = \"open\" ? \"on\" : \"off\"\t","stateType":"jsonata","attributes":[{"property":"command","value":"payload","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":795,"y":1080,"wires":[[]]},{"id":"ee6e3c5a8750dbd3","type":"join","z":"7ea0620.a243ca","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":915,"y":460,"wires":[["ae9faf4f99f5df6b"]]},{"id":"b36ec2b3b096f8d6","type":"join","z":"7ea0620.a243ca","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":920,"y":720,"wires":[["4449a34d85b294de"]]},{"id":"1bd0cac097924a72","type":"join","z":"7ea0620.a243ca","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":920,"y":980,"wires":[["5e4f3934b95b1e9e"]]},{"id":"2758054b03a4112e","type":"subflow:03454e69d1fb38da","z":"7ea0620.a243ca","name":"Office Light 1 Control","x":380,"y":440,"wires":[["b05b2fb283191597"],["a92499638df3f0ae"],[]]},{"id":"6ab4a1291df30475","type":"subflow:03454e69d1fb38da","z":"7ea0620.a243ca","name":"Office Light 2 Control","x":365,"y":760,"wires":[["166c734b13052fb7"],["fe02e119919f1fbf"],[]]},{"id":"5e7dad3531a9ab92","type":"subflow:03454e69d1fb38da","z":"7ea0620.a243ca","name":"Office Light 3 Control","x":365,"y":980,"wires":[["babbee9d013605d2"],["5da1ef5db9218f1e"],[]]},{"id":"5bdc695b13ac08ce","type":"trigger","z":"7ea0620.a243ca","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":185,"y":760,"wires":[["6ab4a1291df30475"]]},{"id":"9843d42f60a63e30","type":"trigger","z":"7ea0620.a243ca","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":200,"y":440,"wires":[["2758054b03a4112e"]]},{"id":"360cde2520d4ef73","type":"trigger","z":"7ea0620.a243ca","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":185,"y":980,"wires":[["5e7dad3531a9ab92"]]},{"id":"668bfd5e97d64c23","type":"trigger","z":"7ea0620.a243ca","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1205,"y":680,"wires":[["3863e49219f2c06c"]]},{"id":"6985e773c83c44f3","type":"trigger","z":"7ea0620.a243ca","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1205,"y":940,"wires":[["c5c6137c20db841c"]]},{"id":"c6387631e23d9171","type":"trigger","z":"7ea0620.a243ca","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1200,"y":420,"wires":[["60a4dca9.c29d14"]]},{"id":"43c2e1ab9d4c3a33","type":"link in","z":"7ea0620.a243ca","name":"Office Light 1 Color Temp q-gate","links":["934e0600896a7adb","a8f21399bc702421","b05b2fb283191597","cd1e6d98e1856bda","9c85a0510c0826d0"],"x":615,"y":440,"wires":[["9dfb80638a8e3d73"]]},{"id":"3055458e27486427","type":"link in","z":"7ea0620.a243ca","name":"Office Light 1 Brightness q-gate","links":["a8f21399bc702421","a92499638df3f0ae","b1ee887a5f59e581","f66d24bc98a1e3de","9c85a0510c0826d0"],"x":615,"y":500,"wires":[["1c0b19f6eaee2844"]]},{"id":"b05b2fb283191597","type":"link out","z":"7ea0620.a243ca","name":"Office Light 1 Color Control","mode":"link","links":["43c2e1ab9d4c3a33","2a3d1ccf39330b28"],"x":525,"y":420,"wires":[]},{"id":"a92499638df3f0ae","type":"link out","z":"7ea0620.a243ca","name":"Office Light 1 Brightness Control","mode":"link","links":["3055458e27486427","4f8d44ef76bac586"],"x":525,"y":460,"wires":[]},{"id":"166c734b13052fb7","type":"link out","z":"7ea0620.a243ca","name":"Office Light 2 Color Control","mode":"link","links":["f6f58ab7e35f5688","9d3d2931ff09f30e"],"x":510,"y":740,"wires":[]},{"id":"fe02e119919f1fbf","type":"link out","z":"7ea0620.a243ca","name":"Office Light 2 Brightness Control","mode":"link","links":["bb5ea6235f3f465f","df433767e85260dc"],"x":510,"y":780,"wires":[]},{"id":"9d3d2931ff09f30e","type":"link in","z":"7ea0620.a243ca","name":"Office Light 2 Color Temp q-gate","links":["166c734b13052fb7","934e0600896a7adb","a8f21399bc702421","cd1e6d98e1856bda","8f139b7a2e1e1072"],"x":620,"y":700,"wires":[["5fcdbdfcad60b453"]]},{"id":"df433767e85260dc","type":"link in","z":"7ea0620.a243ca","name":"Office Light 2 Brightness q-gate","links":["a8f21399bc702421","b1ee887a5f59e581","f66d24bc98a1e3de","fe02e119919f1fbf","8f139b7a2e1e1072"],"x":620,"y":760,"wires":[["5731df33e0ef2e56"]]},{"id":"babbee9d013605d2","type":"link out","z":"7ea0620.a243ca","name":"Office Light 2 Color Control","mode":"link","links":["46442d133be6f963","4b80d3dcd0dcb9fa"],"x":510,"y":960,"wires":[]},{"id":"5da1ef5db9218f1e","type":"link out","z":"7ea0620.a243ca","name":"Office Light 2 Brightness Control","mode":"link","links":["4193dc61304afe65","4ccd12c7e9fa28f9"],"x":510,"y":1000,"wires":[]},{"id":"46442d133be6f963","type":"link in","z":"7ea0620.a243ca","name":"Office Light 3 Color Temp q-gate","links":["934e0600896a7adb","a8f21399bc702421","cd1e6d98e1856bda","babbee9d013605d2","3c70d73a047e84c9"],"x":620,"y":960,"wires":[["f38eeefba2af67ce"]]},{"id":"4ccd12c7e9fa28f9","type":"link in","z":"7ea0620.a243ca","name":"Office Light 3 Brightness q-gate","links":["5da1ef5db9218f1e","a8f21399bc702421","b1ee887a5f59e581","f66d24bc98a1e3de","3c70d73a047e84c9"],"x":620,"y":1020,"wires":[["22570f7cadf11491"]]},{"id":"ae9faf4f99f5df6b","type":"api-current-state","z":"7ea0620.a243ca","name":"On?","server":"c879ac61.99cd1","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.office_light_1","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1035,"y":460,"wires":[["c6387631e23d9171"],["d96a7d6cd4f42087"]]},{"id":"4449a34d85b294de","type":"api-current-state","z":"7ea0620.a243ca","name":"On?","server":"c879ac61.99cd1","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.office_light_2","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1040,"y":720,"wires":[["668bfd5e97d64c23"],["d5a0d787dd0474e6"]]},{"id":"5e4f3934b95b1e9e","type":"api-current-state","z":"7ea0620.a243ca","name":"On?","server":"c879ac61.99cd1","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.office_light_3","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1055,"y":980,"wires":[["6985e773c83c44f3"],["d17fef61a294583d"]]},{"id":"d96a7d6cd4f42087","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"queue","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":500,"wires":[["9c85a0510c0826d0"]]},{"id":"9c85a0510c0826d0","type":"link out","z":"7ea0620.a243ca","name":"Office Light 1 is off","mode":"link","links":["3055458e27486427","43c2e1ab9d4c3a33"],"x":1335,"y":500,"wires":[]},{"id":"d5a0d787dd0474e6","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"queue","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1225,"y":760,"wires":[["8f139b7a2e1e1072"]]},{"id":"8f139b7a2e1e1072","type":"link out","z":"7ea0620.a243ca","name":"Office Light 1 is off","mode":"link","links":["9d3d2931ff09f30e","df433767e85260dc"],"x":1340,"y":760,"wires":[]},{"id":"3c70d73a047e84c9","type":"link out","z":"7ea0620.a243ca","name":"Office Light 1 is off","mode":"link","links":["46442d133be6f963","4ccd12c7e9fa28f9"],"x":1340,"y":1020,"wires":[]},{"id":"d17fef61a294583d","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"queue","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1225,"y":1020,"wires":[["3c70d73a047e84c9"]]},{"id":"911fe5374aa62c8f","type":"debug","z":"7ea0620.a243ca","name":"LIGHT 3 >>","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":475,"y":1040,"wires":[]},{"id":"a7af95da048df2ed","type":"debug","z":"7ea0620.a243ca","name":"JOIN","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1035,"y":940,"wires":[]},{"id":"9752a473fa01a315","type":"debug","z":"7ea0620.a243ca","name":">> LIGHT 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":275,"y":1040,"wires":[]},{"id":"c5e4a35bf6b097fc","type":"debug","z":"7ea0620.a243ca","name":"color control","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1015,"y":900,"wires":[]},{"id":"717f986548852cb7","type":"debug","z":"7ea0620.a243ca","name":"brightness control","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1035,"y":1040,"wires":[]},{"id":"c879ac61.99cd1","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]
1 Like

Brightness only:

[{"id":"072b6cc83f33fb15","type":"subflow","name":"Brightness Control","info":"","category":"","in":[{"x":380,"y":120,"wires":[{"id":"987e20ee59d62bb0"}]}],"out":[{"x":600,"y":80,"wires":[{"id":"987e20ee59d62bb0","port":0}]},{"x":600,"y":120,"wires":[{"id":"987e20ee59d62bb0","port":1}]}],"env":[],"meta":{},"color":"#DDAA99","status":{"x":600,"y":160,"wires":[{"id":"987e20ee59d62bb0","port":2}]}},{"id":"987e20ee59d62bb0","type":"function","z":"072b6cc83f33fb15","name":"","func":"var circadian_brightness = global.get(\"nr_circadian_brightness\");\nvar calculated_brightness_state = Math.round(circadian_brightness * 0.996078431);\nif (calculated_brightness_state == 254) {calculated_brightness_state = 255}\nvar entity_id = msg.data.entity_id\nvar current_brightness = msg.data.new_state.attributes.brightness;\n\n\nvar debug =  \n    {\n        \"Entity\": entity_id,\n        \"Old brightness\": msg.data.old_state.attributes.brightness,\n        \"New brightness\": msg.data.new_state.attributes.brightness,\n        \"Current brightness\": current_brightness,\n        \"Calculated state brightness\": calculated_brightness_state,\n        \"Circadian brightness\": circadian_brightness\n    }\n\nif (msg.data.old_state.state == \"on\" && msg.data.new_state.state == \"on\"){\n        if (current_brightness == calculated_brightness_state){\n            return [{topic: \"control\", payload: \"open\", data: {brightness: circadian_brightness}}, debug]\n        }\n        if (current_brightness != calculated_brightness_state){\n            return [{topic: \"control\", payload: \"close\"}, debug]\n        }\n    }\n    \nif (msg.data.old_state.state == \"off\" && msg.data.new_state.state == \"on\"){\n    return [ { topic: \"control\", payload: \"open\", data: {brightness: circadian_brightness}}, debug ]}\n\n/* payload.brightness */\n\nif (msg.data.old_state.state == \"on\" && msg.data.new_state.state == \"off\"){\n        return [{ topic: \"control\", payload: \"queue\"}, debug ]\n    }\n\nreturn [null, debug]","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":120,"wires":[[],[],[]]},{"id":"d75369b2320f4428","type":"debug","z":"072b6cc83f33fb15","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"$globalContext('nr_circadian_mireds')\t","targetType":"jsonata","statusVal":"","statusType":"auto","x":760,"y":140,"wires":[]},{"id":"8327cd21ef95b941","type":"debug","z":"072b6cc83f33fb15","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"$globalContext('nr_circadian_brightness')\t","targetType":"jsonata","statusVal":"","statusType":"auto","x":760,"y":100,"wires":[]},{"id":"b957873e.b725c8","type":"server-state-changed","z":"7ea0620.a243ca","name":"Circadian Bathroom","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.circadian_lighting_bathroom","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"$entity().state = \"on\" ? \"open\" : \"queue\"","valueType":"jsonata"},{"property":"topic","propertyType":"msg","value":"control","valueType":"str"}],"x":370,"y":1920,"wires":[["128303271cb1130d"]]},{"id":"edb74bee98fc49eb","type":"api-call-service","z":"7ea0620.a243ca","name":"Kitchen","server":"c879ac61.99cd1","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.kitchen_light"],"data":"{\t   \"brightness\": $max(\t       [\t           $number($globalContext('homeassistant.homeAssistant.states[\"input_number.kitchen_minimum\"].state')),\t           msg.payload\t       ]\t   )\t}","dataType":"jsonata","mergeContext":"lightOptions","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1220,"y":1720,"wires":[[]]},{"id":"fc77eb6f5d536827","type":"q-gate","z":"7ea0620.a243ca","name":"brightness","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":true,"persist":true,"storeName":"file","x":750,"y":1760,"wires":[["b22ab8a694b12c60"]]},{"id":"314c2c70ebd4f39a","type":"server-state-changed","z":"7ea0620.a243ca","name":"Kitchen","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.kitchen_light","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"}],"x":55,"y":1760,"wires":[["1322873ff168384d"]]},{"id":"fe41bfcf0ed50cf5","type":"link in","z":"7ea0620.a243ca","name":"Kitchen Brightness Control","links":["dada9119ebbe0596","ff43789985c67c08"],"x":615,"y":1820,"wires":[["0579c2f5b054abe8"]]},{"id":"75b33e99cafd8042","type":"comment","z":"7ea0620.a243ca","name":"Kitchen","info":"","x":70,"y":1700,"wires":[]},{"id":"0579c2f5b054abe8","type":"ha-entity","z":"7ea0620.a243ca","name":"Kitchen Brightness Control","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Kitchen Brightness Control"},{"property":"device_class","value":"opening"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload = \"open\" ? \"on\" : \"off\"\t","stateType":"jsonata","attributes":[{"property":"command","value":"payload","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":800,"y":1820,"wires":[[]]},{"id":"6c9f2202a1fff2d5","type":"server-state-changed","z":"7ea0620.a243ca","name":"Bathroom","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.bathroom_light","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"}],"x":65,"y":2100,"wires":[["94f3524f701742aa"]]},{"id":"2703a86ea0d3038e","type":"server-state-changed","z":"7ea0620.a243ca","name":"Bathroom Brightness","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.circadian_lighting_brightness_bathroom","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"$entity().state = \"on\" ? \"open\" : \"queue\"","valueType":"jsonata"},{"property":"topic","propertyType":"msg","value":"control","valueType":"str"}],"x":360,"y":1980,"wires":[["128303271cb1130d"]]},{"id":"128303271cb1130d","type":"link out","z":"7ea0620.a243ca","name":"Circadian Bathroom ","mode":"link","links":["17fcb852b5d4df73","ffa6896cb76348d5"],"x":525,"y":1980,"wires":[]},{"id":"35ad34b8f96115c9","type":"q-gate","z":"7ea0620.a243ca","name":"brightness","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":true,"persist":true,"storeName":"file","x":750,"y":1980,"wires":[["66276b24fa10ad45"]]},{"id":"17fcb852b5d4df73","type":"link in","z":"7ea0620.a243ca","name":"Bathroom Brightness Control","links":["128303271cb1130d","1d9a557d60b23ece","a95d943d637d7a92"],"x":615,"y":2040,"wires":[["5ba97e1504657679"]]},{"id":"5ba97e1504657679","type":"ha-entity","z":"7ea0620.a243ca","name":"Bathroom Brightness Control","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Bathroom Brightness Control"},{"property":"device_class","value":"opening"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload = \"open\" ? \"on\" : \"off\"\t","stateType":"jsonata","attributes":[{"property":"command","value":"payload","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":800,"y":2040,"wires":[[]]},{"id":"9f996a25e40fb144","type":"comment","z":"7ea0620.a243ca","name":"Bathroom","info":"","x":80,"y":1880,"wires":[]},{"id":"25693f6bb04c3b3a","type":"server-state-changed","z":"7ea0620.a243ca","name":"Sleep Mode","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.sleep_mode","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"ff","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"$entity().state = \"on\" ? \"queue\" : \"default\"","valueType":"jsonata"},{"property":"topic","propertyType":"msg","value":"control","valueType":"str"}],"x":390,"y":2040,"wires":[["128303271cb1130d"],[]]},{"id":"5fb1a55d922a5654","type":"api-current-state","z":"7ea0620.a243ca","name":"Sleep Mode","server":"c879ac61.99cd1","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.sleep_mode","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":0,"forType":"num","forUnits":"minutes","x":1050,"y":1960,"wires":[[],["24502b8b2345bd39"]]},{"id":"1322873ff168384d","type":"trigger","z":"7ea0620.a243ca","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":185,"y":1760,"wires":[["76a4726f666b0555"]]},{"id":"94f3524f701742aa","type":"trigger","z":"7ea0620.a243ca","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":206,"y":2100,"wires":[["3a5334c9c04ac17f"]]},{"id":"2e87f3b04f851720","type":"trigger","z":"7ea0620.a243ca","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"1","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":1060,"y":1720,"wires":[["edb74bee98fc49eb"]]},{"id":"b22ab8a694b12c60","type":"api-current-state","z":"7ea0620.a243ca","name":"On?","server":"c879ac61.99cd1","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.kitchen_light","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":910,"y":1760,"wires":[["2e87f3b04f851720"],["ac49f9c7c3f9feba"]]},{"id":"66276b24fa10ad45","type":"api-current-state","z":"7ea0620.a243ca","name":"On?","server":"c879ac61.99cd1","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.bathroom_light","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":890,"y":1980,"wires":[["5fb1a55d922a5654"],["6b60e2dfc7448ee0"]]},{"id":"ac49f9c7c3f9feba","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"queue","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1080,"y":1800,"wires":[["dada9119ebbe0596"]]},{"id":"dada9119ebbe0596","type":"link out","z":"7ea0620.a243ca","name":"Kitchen Light is off","mode":"link","links":["fe41bfcf0ed50cf5"],"x":1195,"y":1800,"wires":[]},{"id":"6b60e2dfc7448ee0","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"queue","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":2020,"wires":[["1d9a557d60b23ece"]]},{"id":"1d9a557d60b23ece","type":"link out","z":"7ea0620.a243ca","name":"Bathroom Light 1 is off","mode":"link","links":["17fcb852b5d4df73"],"x":1175,"y":2020,"wires":[]},{"id":"19af89da0660a8f1","type":"link in","z":"7ea0620.a243ca","name":"Kitchen Brightness","links":["b1ee887a5f59e581","ff43789985c67c08"],"x":615,"y":1760,"wires":[["fc77eb6f5d536827"]]},{"id":"ff43789985c67c08","type":"link out","z":"7ea0620.a243ca","name":"Kitchen Light","mode":"link","links":["fe41bfcf0ed50cf5","19af89da0660a8f1"],"x":525,"y":1760,"wires":[]},{"id":"ffa6896cb76348d5","type":"link in","z":"7ea0620.a243ca","name":"Bathroom Brightness","links":["128303271cb1130d","a95d943d637d7a92","b1ee887a5f59e581"],"x":615,"y":1980,"wires":[["35ad34b8f96115c9"]]},{"id":"a95d943d637d7a92","type":"link out","z":"7ea0620.a243ca","name":"Bathroom Light","mode":"link","links":["17fcb852b5d4df73","ffa6896cb76348d5"],"x":525,"y":2040,"wires":[]},{"id":"24502b8b2345bd39","type":"api-call-service","z":"7ea0620.a243ca","name":"Bathroom","server":"c879ac61.99cd1","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.bathroom_light"],"data":"{\t   \"brightness\": $max(\t       [\t           $number($globalContext('homeassistant.homeAssistant.states[\"input_number.bathroom_minimum\"].state')),\t           msg.payload\t       ]\t   )\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1220,"y":1960,"wires":[[]]},{"id":"76a4726f666b0555","type":"subflow:072b6cc83f33fb15","z":"7ea0620.a243ca","name":"Kitchen Control","x":380,"y":1760,"wires":[["ff43789985c67c08"],[]]},{"id":"3a5334c9c04ac17f","type":"subflow:072b6cc83f33fb15","z":"7ea0620.a243ca","name":"Bathrrom Control","x":380,"y":2100,"wires":[["a95d943d637d7a92"],[]]},{"id":"c879ac61.99cd1","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

I added the HA entities which reflect the state of the q-gates to this panel so I can quickly see the state of the q-gates without having to open Node-Red:

2 Likes

Hi, thank you for your work!

So I set one light up and try to understand whats going on. The color gate does indeed go closed every now and then.

My question ist: if I have every gate open, getting correct values for brightness/color from calculator and switch my light on with very different values, why does it take so long to adjust (had around 15 minutes)? What triggers it to change? The light.turn_on? But then it should change immediately, what it never does. What’s the interval behind it to adjust? Can you explain that to me?

My latest flow…

[{"id":"03454e69d1fb38da","type":"subflow","name":"Color / Brightness","info":"Color / Brightness Control commands for q-gate node","category":"","in":[{"x":340,"y":140,"wires":[{"id":"e9076938078efe18"}]}],"out":[{"x":640,"y":60,"wires":[{"id":"e9076938078efe18","port":0}]},{"x":640,"y":120,"wires":[{"id":"e9076938078efe18","port":1}]},{"x":640,"y":180,"wires":[{"id":"e9076938078efe18","port":2}]}],"env":[],"meta":{},"color":"#DDAA99","status":{"x":640,"y":240,"wires":[]}},{"id":"e9076938078efe18","type":"function","z":"03454e69d1fb38da","name":"","func":"var entity_id = msg.data.entity_id\nvar current_brightness = msg.data.new_state.attributes.brightness;\nvar current_color_temp = msg.data.new_state.attributes.color_temp;\nvar circadian_mireds = global.get(\"nr_circadian_mireds\");\nvar circadian_brightness = global.get(\"nr_circadian_brightness\");\n/*\nvar calculated_brightness_state = Math.round(circadian_brightness * 0.996078431);\nif (calculated_brightness_state == 254) {calculated_brightness_state = 255}\n*/\ncircadian_brightness = Math.round(circadian_brightness * 0.996078431) + Math.floor(circadian_brightness/255);\n\nvar debug =  \n    {\n        \"Entity\": entity_id,\n        \"Old color\": msg.data.old_state.attributes.color_temp,\n        \"New color\": msg.data.new_state.attributes.color_temp,\n        \"Current color_temp\": current_color_temp,\n        \"Circadian mireds\": circadian_mireds,\n        \"Old brightness\": msg.data.old_state.attributes.brightness,\n        \"New brightness\": msg.data.new_state.attributes.brightness,\n        \"Current brightness\": current_brightness,\n        \"Circadian brightness\": circadian_brightness\n    }\n\nif (msg.data.old_state.state == \"on\" && msg.data.new_state.state == \"on\"){\n\n        if (current_color_temp == circadian_mireds &&\n            current_brightness == circadian_brightness){\n            return [{topic: \"control\", payload: \"open\"}, {topic: \"control\", payload: \"open\"}, debug]\n        }\n        if (current_color_temp != circadian_mireds &&\n            current_brightness == circadian_brightness){\n            return [{topic: \"control\", payload: \"queue\"}, {topic: \"control\", payload: \"open\"}, debug]\n        }\n        if (current_color_temp == circadian_mireds &&\n            current_brightness != circadian_brightness){\n            return [{topic: \"control\", payload: \"open\"}, {topic: \"control\", payload: \"queue\"}, debug]\n        }\n        if (current_color_temp != circadian_mireds && \n            current_brightness != circadian_brightness){\n            return [{topic: \"control\", payload: \"queue\"}, {topic: \"control\", payload: \"queue\"}, debug]\n        }\n    }\n    \nif (msg.data.old_state.state == \"off\" && msg.data.new_state.state == \"on\"){\n    return [ { topic: \"control\", payload: \"open\", data: {color_temp: circadian_mireds}},\n             { topic: \"control\", payload: \"open\", data: {brightness: circadian_brightness}},\n             debug ]}\n\n/* payload.brightness */\n\nif (msg.data.old_state.state == \"on\" && msg.data.new_state.state == \"off\"){\n        return [{ topic: \"control\", payload: \"queue\" }, { topic: \"control\", payload: \"queue\"}, debug ]\n    }\n\nreturn [null, null, debug]\n\n","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":140,"wires":[[],[],[]]},{"id":"ae8af5aa195ee960","type":"debug","z":"03454e69d1fb38da","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"$globalContext('nr_circadian_mireds')\t","targetType":"jsonata","statusVal":"","statusType":"auto","x":420,"y":260,"wires":[]},{"id":"15d3ba0a712a2f77","type":"debug","z":"03454e69d1fb38da","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"$globalContext('nr_circadian_brightness')\t","targetType":"jsonata","statusVal":"","statusType":"auto","x":420,"y":220,"wires":[]},{"id":"e812678d.651e28","type":"subflow","name":"Circadian Calculator","info":"","category":"time and astro","in":[{"x":80,"y":80,"wires":[{"id":"aa4b86d8.b17118"}]}],"out":[{"x":890,"y":100,"wires":[{"id":"40de744.1e2ca8c","port":0}]},{"x":890,"y":160,"wires":[{"id":"15b473ec45fa7fc4","port":0}]},{"x":930,"y":260,"wires":[{"id":"6f365d7d05905955","port":0}]},{"x":930,"y":320,"wires":[{"id":"c26bdcca.eb483","port":0}]}],"env":[],"meta":{},"color":"#FFCC66","inputLabels":["Trigger"],"outputLabels":["Brightness Value","Brightness Percent","Mireds","Kelvin"]},{"id":"5de89261.4fb97c","type":"switch","z":"e812678d.651e28","name":"curve switch","property":"payload.times_of_day.active.name","propertyType":"msg","rules":[{"t":"eq","v":"night","vt":"str"},{"t":"eq","v":"morning","vt":"str"},{"t":"eq","v":"day","vt":"str"},{"t":"eq","v":"evening","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":250,"y":220,"wires":[["ba17c1e6.e6f58","840431b7.eeefc"],["e5bb5a04.a33948","d4d99259.d0d7e"],["7c0f0774.90adf8","6ac1af7.dddb15"],["23b260f9.19f78","a907f5f4.0bf488"]]},{"id":"ba17c1e6.e6f58","type":"spline-curve","z":"e812678d.651e28","name":"night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.3},{"x":0.333,"y":0.037},{"x":0.477,"y":0},{"x":0.783,"y":0},{"x":1,"y":0}],"x":490,"y":80,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"e5bb5a04.a33948","type":"spline-curve","z":"e812678d.651e28","name":"morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.01},{"x":0.132,"y":0.01},{"x":0.269,"y":0.027},{"x":0.449,"y":0.124},{"x":0.676,"y":0.334},{"x":1,"y":0.75}],"x":500,"y":120,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"23b260f9.19f78","type":"spline-curve","z":"e812678d.651e28","name":"evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.036,"y":0.78},{"x":0.176,"y":0.63},{"x":1,"y":0.3}],"x":500,"y":200,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"7c0f0774.90adf8","type":"spline-curve","z":"e812678d.651e28","name":"daylight curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.744},{"x":0.03,"y":0.838},{"x":0.097,"y":0.941},{"x":0.183,"y":1},{"x":0.86,"y":0.995},{"x":0.943,"y":0.931},{"x":1,"y":0.85}],"x":500,"y":160,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"840431b7.eeefc","type":"spline-curve","z":"e812678d.651e28","name":"night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.5},{"x":0.067,"y":0.368},{"x":0.133,"y":0.265},{"x":0.27,"y":0.171},{"x":0.333,"y":0.16},{"x":0.506,"y":0.124},{"x":0.606,"y":0}],"x":490,"y":240,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"d4d99259.d0d7e","type":"spline-curve","z":"e812678d.651e28","name":"morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":0.42,"y":0.018},{"x":0.54,"y":0.051},{"x":0.587,"y":0.101},{"x":0.817,"y":0.675},{"x":1,"y":0.85}],"x":500,"y":280,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"a907f5f4.0bf488","type":"spline-curve","z":"e812678d.651e28","name":"evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.787,"y":0.598},{"x":1,"y":0.5}],"x":500,"y":360,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"6ac1af7.dddb15","type":"spline-curve","z":"e812678d.651e28","name":"daylight curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.123,"y":0.927},{"x":0.5,"y":1},{"x":0.92,"y":0.904},{"x":1,"y":0.85}],"x":500,"y":320,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"a330b219.92e4e","type":"function","z":"e812678d.651e28","name":"Times of Day","func":"var newmsg = JSON.parse(JSON.stringify(msg));\nnewmsg.payload.times_of_day = {};\n\nprocessTimeOfDay = function(nme, obj, name_start, name_end) {\n    var ret = {};\n    ret.name  = nme;\n    ret.start = obj.times[name_start].ts;\n    ret.end   = obj.times[name_end].ts;\n    ret.perc  = (obj.ts - ret.start) / (ret.end - ret.start);\n    \n    \n    // to cover range starting before midnight and ending after it.\n    if (ret.start > ret.end)\n    {\n        var a;\n\n        // before midnight\n        if (ret.start < obj.ts) \n        {\n            a = new Date(ret.end);\n            a.setUTCDate(a.getUTCDate() + 1);\n            ret.end = a.getTime();\n             \n             \n        }\n        else if (ret.end > obj.ts) \n        {\n            a = new Date(ret.start);\n            a.setUTCDate(a.getUTCDate() - 1);\n            ret.start = a.getTime();\n\n        }\n\n    }\n    \n    ret.perc  = (obj.ts - ret.start) / (ret.end - ret.start);\n    \n    obj.times_of_day[nme] = ret;\n    if (ret.start <= obj.ts && obj.ts < ret.end ) obj.times_of_day.active = ret;\n}\n\n\nprocessTimeOfDay('night', newmsg.payload, \"astronomicalDusk\", \"astronomicalDawn\");\nprocessTimeOfDay('morning', newmsg.payload, \"astronomicalDawn\", \"goldenHourDawnEnd\");\nprocessTimeOfDay('day', newmsg.payload, \"goldenHourDawnEnd\", \"sunsetStart\");\nprocessTimeOfDay('evening', newmsg.payload, \"sunsetStart\", \"astronomicalDusk\");\n\n\nreturn newmsg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":140,"wires":[["5de89261.4fb97c"]]},{"id":"40de744.1e2ca8c","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"1","maxout":"254","action":"clamp","round":true,"property":"payload","name":"","x":710,"y":100,"wires":[[]]},{"id":"c26bdcca.eb483","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"2700","maxout":"6500","action":"clamp","round":true,"property":"payload","name":"","x":730,"y":320,"wires":[[]]},{"id":"aa4b86d8.b17118","type":"sun-position","z":"e812678d.651e28","name":"","positionConfig":"31826811.22a458","rules":[],"onlyOnChange":"true","topic":"","outputs":1,"start":"","startType":"none","startOffset":0,"startOffsetType":"num","startOffsetMultiplier":60000,"end":"","endType":"none","endOffset":0,"endOffsetType":"num","endOffsetMultiplier":60000,"x":210,"y":80,"wires":[["a330b219.92e4e"]]},{"id":"15b473ec45fa7fc4","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"1","maxout":"100","action":"clamp","round":true,"property":"payload","name":"","x":710,"y":160,"wires":[[]]},{"id":"6f365d7d05905955","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"370","maxout":"154","action":"clamp","round":true,"property":"payload","name":"","x":720,"y":260,"wires":[[]]},{"id":"31826811.22a458","type":"position-config","name":"Home Location","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":"99","timeZoneDST":"0","stateTimeFormat":"3","stateDateFormat":"12"},{"id":"f5e1d08b.a8cd58","type":"ha-entity","z":"7ea0620.a243ca","name":"kelvin","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nr_circadian_kelvin"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:brightness-6"},{"property":"unit_of_measurement","value":"K"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"nr_circadian_kelvin","stateType":"global","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"msg","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":890,"y":220,"wires":[[]]},{"id":"365094a5.72bb5c","type":"subflow:e812678d.651e28","z":"7ea0620.a243ca","name":"","env":[],"x":480,"y":130,"wires":[["5f4a2fbe.d6b89"],["2bd57efd76cfcedf"],["eb1275669172038f","30bf6ebc.f4da52"],[]]},{"id":"e80bd956.f2e098","type":"ha-entity","z":"7ea0620.a243ca","name":"color_temp","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nr_circadian_color_temp"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:brightness-6"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"nr_circadian_mireds","stateType":"global","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":910,"y":160,"wires":[["53a933a438c1326b"]]},{"id":"476cda43.0f4c94","type":"ha-entity","z":"7ea0620.a243ca","name":"brightness","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nr_circadian_brightness"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:brightness-auto"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"nr_circadian_brightness","stateType":"global","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"block","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":910,"y":40,"wires":[["ba7018086eca537b"]]},{"id":"71e41def.76e254","type":"server-state-changed","z":"7ea0620.a243ca","name":"Cicadian Office","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.circadian_lighting_office","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"$entity().state = \"on\" ? \"open\" : \"queue\"","valueType":"jsonata"},{"property":"topic","propertyType":"msg","value":"control","valueType":"str"}],"x":120,"y":320,"wires":[["a8f21399bc702421"]]},{"id":"a7bca137.c0d2f","type":"comment","z":"7ea0620.a243ca","name":"Update","info":"","x":90,"y":40,"wires":[]},{"id":"60a4dca9.c29d14","type":"api-call-service","z":"7ea0620.a243ca","name":"Light 1","server":"c879ac61.99cd1","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.office_light_1"],"data":"{\t   \"brightness\": payload.brightness,\t   \"color_temp\": payload.color_temp\t}","dataType":"jsonata","mergeContext":"lightOptions","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1250,"y":460,"wires":[[]]},{"id":"5f4a2fbe.d6b89","type":"function","z":"7ea0620.a243ca","name":"global brightness","func":"var new_brightness = (msg.payload == 254) ? 255 : msg.payload;\nif (new_brightness != global.get('nr_circadian_brightness')){\n    global.set('nr_circadian_brightness',new_brightness);\n    return {payload: new_brightness}\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":40,"wires":[["476cda43.0f4c94"]]},{"id":"30bf6ebc.f4da52","type":"function","z":"7ea0620.a243ca","name":"global kelvin","func":"var new_kelvin = Math.round(1000000/msg.payload,0);\nif (new_kelvin != global.get('nr_circadian_kelvin')) {\n    global.set('nr_circadian_kelvin',new_kelvin);\n    return {payload: new_kelvin}\n    }\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":220,"wires":[["f5e1d08b.a8cd58"]]},{"id":"5953dc0a6a10c314","type":"server-state-changed","z":"7ea0620.a243ca","name":"Office Color","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.circadian_lighting_color_office","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"topic","propertyType":"msg","value":"control","valueType":"str"},{"property":"payload","propertyType":"msg","value":"$entity().state = \"on\" ? \"open\" : \"queue\"","valueType":"jsonata"}],"x":110,"y":380,"wires":[["cd1e6d98e1856bda"]]},{"id":"3728361be31f9153","type":"server-state-changed","z":"7ea0620.a243ca","name":"Office Brightness","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.circadian_lighting_brightness_office","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":true,"ignorePrevStateUnknown":true,"ignorePrevStateUnavailable":true,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"$entity().state = \"on\" ? \"open\" : \"queue\"","valueType":"jsonata"},{"property":"topic","propertyType":"msg","value":"control","valueType":"str"}],"x":120,"y":440,"wires":[["f66d24bc98a1e3de"]]},{"id":"934e0600896a7adb","type":"link out","z":"7ea0620.a243ca","name":"Mireds","mode":"link","links":["9d3d2931ff09f30e","43c2e1ab9d4c3a33","46442d133be6f963","a52970d03d1f30a5","a897dbf21ffb2b4c"],"x":1195,"y":160,"wires":[]},{"id":"b1ee887a5f59e581","type":"link out","z":"7ea0620.a243ca","name":"Brightness","mode":"link","links":["e376d76995dda48c","4c8de271d9d32579","df433767e85260dc","3055458e27486427","4ccd12c7e9fa28f9","d72d56acc2f72b41","b1137e5488a33dda","ffa6896cb76348d5","19af89da0660a8f1"],"x":1195,"y":40,"wires":[]},{"id":"9dfb80638a8e3d73","type":"q-gate","z":"7ea0620.a243ca","name":"color_temp 1","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":true,"persist":true,"storeName":"file","x":810,"y":460,"wires":[["ee6e3c5a8750dbd3"]]},{"id":"1c0b19f6eaee2844","type":"q-gate","z":"7ea0620.a243ca","name":"brightness 1","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","peekCmd":"","dropCmd":"","statusCmd":"","maxQueueLength":"1","keepNewest":true,"qToggle":true,"persist":true,"storeName":"file","x":810,"y":520,"wires":[["ee6e3c5a8750dbd3"]]},{"id":"a8f21399bc702421","type":"link out","z":"7ea0620.a243ca","name":"Circadian Office","mode":"link","links":["2a3d1ccf39330b28","4193dc61304afe65","4b80d3dcd0dcb9fa","4f8d44ef76bac586","bb5ea6235f3f465f","f6f58ab7e35f5688","dcfa43aa5b436092"],"x":255,"y":320,"wires":[]},{"id":"448f5e6c691dccc4","type":"server-state-changed","z":"7ea0620.a243ca","name":"Light 1","server":"c879ac61.99cd1","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.office_light_1","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"}],"x":90,"y":496,"wires":[["9843d42f60a63e30"]]},{"id":"5cd0d7153aaad741","type":"ha-entity","z":"7ea0620.a243ca","name":"brightness_pct","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nr_circadian_brightness_pct"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:brightness-percent"},{"property":"unit_of_measurement","value":"%"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"nr_circadian_brightness_pct","stateType":"global","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"msg","inputOverride":"block","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":920,"y":100,"wires":[[]]},{"id":"2a3d1ccf39330b28","type":"link in","z":"7ea0620.a243ca","name":"Office Light 1 Color","links":["9c85a0510c0826d0","a8f21399bc702421","b05b2fb283191597","cd1e6d98e1856bda"],"x":675,"y":400,"wires":[["afacf51113b59757"]]},{"id":"4f8d44ef76bac586","type":"link in","z":"7ea0620.a243ca","name":"Office Light 1 Brightness","links":["9c85a0510c0826d0","a8f21399bc702421","a92499638df3f0ae","f66d24bc98a1e3de"],"x":675,"y":580,"wires":[["6b84a041a8d0dacb"]]},{"id":"f66d24bc98a1e3de","type":"link out","z":"7ea0620.a243ca","name":"Office Brightness","mode":"link","links":["4193dc61304afe65","4f8d44ef76bac586","bb5ea6235f3f465f"],"x":255,"y":440,"wires":[]},{"id":"cd1e6d98e1856bda","type":"link out","z":"7ea0620.a243ca","name":"Office Color","mode":"link","links":["2a3d1ccf39330b28","4b80d3dcd0dcb9fa","f6f58ab7e35f5688"],"x":255,"y":380,"wires":[]},{"id":"f75a6792daaeb0b4","type":"comment","z":"7ea0620.a243ca","name":"Office","info":"","x":70,"y":280,"wires":[]},{"id":"eb1275669172038f","type":"function","z":"7ea0620.a243ca","name":"global mireds","func":"var new_mireds = msg.payload\nif (new_mireds != global.get('nr_circadian_mireds')) {\n    global.set('nr_circadian_mireds',new_mireds);\n    return {payload: new_mireds}\n    }\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":160,"wires":[["e80bd956.f2e098"]]},{"id":"2bd57efd76cfcedf","type":"function","z":"7ea0620.a243ca","name":"global brightness %","func":"var new_brightness_pct = msg.payload;\nif (new_brightness_pct != global.get('nr_circadian_brightness_pct')) {\n    global.set('nr_circadian_brightness_pct',new_brightness_pct);\n    return {payload: new_brightness_pct}\n    }","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":100,"wires":[["5cd0d7153aaad741"]]},{"id":"11dfa753a1a2cd05","type":"ha-entity","z":"7ea0620.a243ca","name":"Light 1 Color Control","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Office Light 1 Color Control"},{"property":"device_class","value":"opening"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload = \"open\" ? \"on\" : \"off\"\t","stateType":"jsonata","attributes":[{"property":"command","value":"payload","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":1020,"y":420,"wires":[[]]},{"id":"94a02ed09a89725d","type":"ha-entity","z":"7ea0620.a243ca","name":"Light 1 Brightness Control","server":"c879ac61.99cd1","version":2,"debugenabled":false,"outputs":1,"entityType":"binary_sensor","config":[{"property":"name","value":"Office Light 1 Brightness Control"},{"property":"device_class","value":"opening"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload = \"open\" ? \"on\" : \"off\"\t","stateType":"jsonata","attributes":[{"property":"command","value":"payload","valueType":"msg"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":1030,"y":540,"wires":[[]]},{"id":"ee6e3c5a8750dbd3","type":"join","z":"7ea0620.a243ca","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"2","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":970,"y":480,"wires":[["ae9faf4f99f5df6b"]]},{"id":"53a933a438c1326b","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"color_temp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":160,"wires":[["934e0600896a7adb"]]},{"id":"ba7018086eca537b","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"brightness","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":40,"wires":[["b1ee887a5f59e581"]]},{"id":"f6a0b62593cc81c1","type":"interval-multiples-timer","z":"7ea0620.a243ca","interval":"60000","payload":"","topic":"","name":"Every minute","x":86,"y":120,"wires":[["f7382c3f63fec06f"]],"outputLabels":["timestamp"]},{"id":"b49e0a964008e7ba","type":"inject","z":"7ea0620.a243ca","name":"At startup","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":96,"y":160,"wires":[["f7382c3f63fec06f"]]},{"id":"2758054b03a4112e","type":"subflow:03454e69d1fb38da","z":"7ea0620.a243ca","name":"Office Light 1 Control","x":400,"y":496,"wires":[["b05b2fb283191597"],["a92499638df3f0ae"],[]]},{"id":"9843d42f60a63e30","type":"trigger","z":"7ea0620.a243ca","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"2","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":220,"y":496,"wires":[["2758054b03a4112e"]]},{"id":"43c2e1ab9d4c3a33","type":"link in","z":"7ea0620.a243ca","name":"Office Light 1 Color Temp q-gate","links":["934e0600896a7adb","14e63aec201e0a1d"],"x":675,"y":460,"wires":[["9dfb80638a8e3d73"]]},{"id":"3055458e27486427","type":"link in","z":"7ea0620.a243ca","name":"Office Light 1 Brightness q-gate","links":["b1ee887a5f59e581","a05475178f653842"],"x":675,"y":520,"wires":[["1c0b19f6eaee2844"]]},{"id":"b05b2fb283191597","type":"link out","z":"7ea0620.a243ca","name":"Office Light 1 Color Control","mode":"link","links":["2a3d1ccf39330b28"],"x":575,"y":460,"wires":[]},{"id":"a92499638df3f0ae","type":"link out","z":"7ea0620.a243ca","name":"Office Light 1 Brightness Control","mode":"link","links":["4f8d44ef76bac586"],"x":575,"y":522,"wires":[]},{"id":"ae9faf4f99f5df6b","type":"api-current-state","z":"7ea0620.a243ca","name":"On?","server":"c879ac61.99cd1","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.office_light_1","state_type":"str","blockInputOverrides":false,"outputProperties":[],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1110,"y":480,"wires":[["60a4dca9.c29d14"],["d96a7d6cd4f42087"]]},{"id":"f7382c3f63fec06f","type":"api-current-state","z":"7ea0620.a243ca","name":"Circadian On?","server":"c879ac61.99cd1","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.circadian_lighting","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"date"}],"for":0,"forType":"num","forUnits":"minutes","x":280,"y":136,"wires":[["365094a5.72bb5c"],[]]},{"id":"d96a7d6cd4f42087","type":"change","z":"7ea0620.a243ca","name":"close gate","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"queue","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1270,"y":520,"wires":[["9c85a0510c0826d0"]]},{"id":"9c85a0510c0826d0","type":"link out","z":"7ea0620.a243ca","name":"Office Light 1 is off","mode":"link","links":["2a3d1ccf39330b28","4f8d44ef76bac586"],"x":1405,"y":520,"wires":[]},{"id":"e0f5e85efbbf544d","type":"ha-device","z":"7ea0620.a243ca","name":"Light 1 Brightness","server":"c879ac61.99cd1","version":0,"debugenabled":false,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"inputs":0,"deviceType":"trigger","device":"f0dde411d2a72e45f369f769d636826d","event":{"platform":"device","type":"turned_on","device_id":"f0dde411d2a72e45f369f769d636826d","entity_id":"light.office_light_1","domain":"light"},"capabilities":[{"name":"for","type":"positive_time_period_dict","value":1,"unit":"seconds"}],"outputProperties":[{"property":"topic","propertyType":"msg","value":"brightness","valueType":"str"},{"property":"payload","propertyType":"msg","value":"nr_circadian_brightness","valueType":"global"}],"x":410,"y":580,"wires":[["a05475178f653842"]]},{"id":"6a9242f61c13b1ba","type":"ha-device","z":"7ea0620.a243ca","name":"Light 1 Color Temp","server":"c879ac61.99cd1","version":0,"debugenabled":false,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"inputs":0,"deviceType":"trigger","device":"f0dde411d2a72e45f369f769d636826d","event":{"platform":"device","type":"turned_on","device_id":"f0dde411d2a72e45f369f769d636826d","entity_id":"light.office_light_1","domain":"light"},"capabilities":[{"name":"for","type":"positive_time_period_dict","value":1,"unit":"seconds"}],"outputProperties":[{"property":"topic","propertyType":"msg","value":"color_temp","valueType":"str"},{"property":"payload","propertyType":"msg","value":"nr_circadian_mireds","valueType":"global"}],"x":410,"y":400,"wires":[["14e63aec201e0a1d"]]},{"id":"afacf51113b59757","type":"rbe","z":"7ea0620.a243ca","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":790,"y":400,"wires":[["9dfb80638a8e3d73","11dfa753a1a2cd05"]]},{"id":"6b84a041a8d0dacb","type":"rbe","z":"7ea0620.a243ca","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":790,"y":580,"wires":[["1c0b19f6eaee2844","94a02ed09a89725d"]]},{"id":"14e63aec201e0a1d","type":"link out","z":"7ea0620.a243ca","name":"Office Light 1 Color Temp Payload","mode":"link","links":["43c2e1ab9d4c3a33"],"x":575,"y":400,"wires":[]},{"id":"a05475178f653842","type":"link out","z":"7ea0620.a243ca","name":"Office Light 1 Brightness Payload","mode":"link","links":["3055458e27486427"],"x":575,"y":580,"wires":[]},{"id":"c879ac61.99cd1","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]
2 Likes

I’ve been reading with interest this thread and I found it amazing. That’s a great job on using the correct tools for doing the job right. Spline curves and day subdivision.

I’m also a lover for node-red, but In this case, shouldn’t be better to bring up the rest of the logic, from the OPs code ahead to the apply on the lights, in Home Assistant?

Having the brightness and temperature in HA it should be only a matter of picking it for selected lights. There’s a Circadian implementation using an automation (blueprint). It should only be a matter of replacing it’s internal calculation with the correct entities. Isn’t it?

I guess it should be possible to integrate all the logic as an integration, but I don’t know nothing about python.

@maxym Would you mind to share your “day simulator” flow?
I still haven’t touched the curves, but in my node-red the curves have spikes and steps.
imagen

here is my whole subflow:

[{"id":"26c6c4d5.3a01e4","type":"subflow","name":"Sub Circadian NR","info":"","category":"","in":[{"x":60,"y":160,"wires":[{"id":"7d4ca80d.e23468"}]}],"out":[{"x":1120,"y":140,"wires":[{"id":"e64dbfa.021204","port":0}]},{"x":1120,"y":340,"wires":[{"id":"d9f0035a.28956","port":0}]},{"x":500,"y":500,"wires":[{"id":"667d6dd.334db94","port":0}]}],"env":[],"color":"#DDAA99","inputLabels":["any message"],"outputLabels":["Brightness","Warmth","Debug"],"icon":"node-red-contrib-sun-position/sun-white.png"},{"id":"dc97f68a.35ea2","type":"switch","z":"26c6c4d5.3a01e4","name":"curve switch","property":"payload.times_of_day.active.name","propertyType":"msg","rules":[{"t":"eq","v":"night","vt":"str"},{"t":"eq","v":"morning","vt":"str"},{"t":"eq","v":"day","vt":"str"},{"t":"eq","v":"evening","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":510,"y":240,"wires":[["ce91189c.8bc7d8","bd8db343.5462f8"],["ad9966f3.3fced","4db18fbe.9ffb6"],["c2d43d53.d7ddf8","838233f4.7ffed"],["eef1dc11.39342","2e9ef8a9.d7fd88"]]},{"id":"ce91189c.8bc7d8","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.3},{"x":0.333,"y":0.037},{"x":0.477,"y":0},{"x":0.783,"y":0},{"x":1,"y":0}],"x":750,"y":80,"wires":[["e64dbfa.021204"]]},{"id":"ad9966f3.3fced","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.01},{"x":0.132,"y":0.01},{"x":0.269,"y":0.027},{"x":0.449,"y":0.124},{"x":0.676,"y":0.334},{"x":1,"y":0.75}],"x":760,"y":120,"wires":[["e64dbfa.021204"]]},{"id":"eef1dc11.39342","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.036,"y":0.78},{"x":0.176,"y":0.63},{"x":1,"y":0.3}],"x":760,"y":200,"wires":[["e64dbfa.021204"]]},{"id":"c2d43d53.d7ddf8","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"daylight curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.744},{"x":0.03,"y":0.838},{"x":0.097,"y":0.941},{"x":0.183,"y":1},{"x":0.86,"y":0.995},{"x":0.943,"y":0.931},{"x":1,"y":0.85}],"x":760,"y":160,"wires":[["e64dbfa.021204"]]},{"id":"bd8db343.5462f8","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.5},{"x":0.067,"y":0.368},{"x":0.133,"y":0.265},{"x":0.27,"y":0.171},{"x":0.333,"y":0.16},{"x":0.506,"y":0.124},{"x":0.606,"y":0}],"x":750,"y":280,"wires":[["d9f0035a.28956"]]},{"id":"4db18fbe.9ffb6","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":0.42,"y":0.018},{"x":0.54,"y":0.051},{"x":0.587,"y":0.101},{"x":0.817,"y":0.675},{"x":1,"y":0.85}],"x":760,"y":320,"wires":[["d9f0035a.28956"]]},{"id":"2e9ef8a9.d7fd88","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.787,"y":0.598},{"x":1,"y":0.5}],"x":760,"y":400,"wires":[["d9f0035a.28956"]]},{"id":"838233f4.7ffed","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"daylight curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.123,"y":0.927},{"x":0.5,"y":1},{"x":0.92,"y":0.904},{"x":1,"y":0.85}],"x":760,"y":360,"wires":[["d9f0035a.28956"]]},{"id":"667d6dd.334db94","type":"function","z":"26c6c4d5.3a01e4","name":"Times of Day","func":"var newmsg = JSON.parse(JSON.stringify(msg));\nnewmsg.payload.times_of_day = {};\n\nprocessTimeOfDay = function(nme, obj, name_start, name_end) {\n    var ret = {};\n    ret.name  = nme;\n    ret.start = obj.times[name_start].ts;\n    ret.end   = obj.times[name_end].ts;\n    ret.perc  = (obj.ts - ret.start) / (ret.end - ret.start);\n    \n    \n    // to cover range starting before midnight and ending after it.\n    if (ret.start > ret.end)\n    {\n        var a;\n\n        // before midnight\n        if (ret.start < obj.ts) \n        {\n            a = new Date(ret.end);\n            a.setUTCDate(a.getUTCDate() + 1);\n            ret.end = a.getTime();\n             \n             \n        }\n        else if (ret.end > obj.ts) \n        {\n            a = new Date(ret.start);\n            a.setUTCDate(a.getUTCDate() - 1);\n            ret.start = a.getTime();\n\n        }\n\n    }\n    \n    ret.perc  = (obj.ts - ret.start) / (ret.end - ret.start);\n    \n    obj.times_of_day[nme] = ret;\n    if (ret.start <= obj.ts && obj.ts < ret.end ) obj.times_of_day.active = ret;\n}\n\n\nprocessTimeOfDay('night', newmsg.payload, \"astronomicalDusk\", \"civilDawn\");\nprocessTimeOfDay('morning', newmsg.payload, \"civilDawn\", \"goldenHourDawnEnd\");\nprocessTimeOfDay('day', newmsg.payload, \"goldenHourDawnEnd\", \"sunsetStart\");\nprocessTimeOfDay('evening', newmsg.payload, \"sunsetStart\", \"astronomicalDusk\");\n\n\nreturn newmsg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":240,"wires":[["dc97f68a.35ea2"]]},{"id":"e64dbfa.021204","type":"range","z":"26c6c4d5.3a01e4","minin":"0","maxin":"1","minout":"1","maxout":"100","action":"scale","round":true,"property":"payload","name":"","x":980,"y":140,"wires":[[]]},{"id":"d9f0035a.28956","type":"range","z":"26c6c4d5.3a01e4","minin":"0","maxin":"1","minout":"2000","maxout":"5500","action":"scale","round":true,"property":"payload","name":"","x":990,"y":340,"wires":[[]]},{"id":"7d4ca80d.e23468","type":"sun-position","z":"26c6c4d5.3a01e4","name":"","positionConfig":"26f98e1b.bd1812","rules":[],"onlyOnChange":"true","topic":"","outputs":1,"start":"","startType":"none","startOffset":0,"startOffsetType":"num","startOffsetMultiplier":60000,"end":"","endType":"none","endOffset":0,"endOffsetType":"num","endOffsetMultiplier":60000,"x":190,"y":160,"wires":[["667d6dd.334db94"]]},{"id":"26f98e1b.bd1812","type":"position-config","name":"","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":99,"timeZoneDST":0,"stateTimeFormat":"3","stateDateFormat":"12"},{"id":"7c36779e.82d778","type":"subflow:26c6c4d5.3a01e4","z":"98a83ef1.1c6e2","name":"","env":[],"x":350,"y":240,"wires":[["f5dfa977.44ef5"],["2dee4f11.beb6e"],["73ce5946.a872a"]],"outputLabels":["Bigthness [%]","Warmth [K]","Debug"],"icon":"node-red-node-suncalc/sun.png"}]
2 Likes

Thanks maxym. But this is the subflow node. I asked for the curve testing flow that you mentioned on your first post, if it’s still possible.

I’m on holidays. Will be back on wed evening. If I still have the generator I will publish the code.

Well follwowing this topic I decided to give it a go and while I only spent a day on this so far I think some might like some of my additions to name a few:

  • Reorganized message with extra info
  • Combined output to a single message
  • Added offset to time period
  • Master & Indivual room control
  • Auto deactivate when a user changes brightness or temperature
  • Auto reactivate when the light off
  • Removed Day/Night curve in favor of extended dawn/dusk period

[{"id":"09e8f85672b69e6e","type":"group","z":"76d268b99378117f","name":"Flux","style":{"label":true},"nodes":["7c36779e.82d778","c17fcdbf5c1601ca","96c46a37c4c1d229","b2de534c9548128e","1f338bb84eea05a6","87212c336e7a404e","e03358fbb0d58292","221d625268d9d855","4ad115d03bf1bcc7","5075f9dec136e667","d48847fecb73ea12","9ea0ef28bf1e7c2d","28b68907a6c1c3bd","9a8c4b9aa821571a","ad73ab52dfc9464c","fc891a29a6a02cf6","65e26660fdb518f7","68dc351f6676efdf","f50f5dda01a96a73"],"x":74,"y":439,"w":1012,"h":242},{"id":"b62e4b55.b6e888","type":"subflow","name":"Sub User","info":"","category":"","in":[{"x":280,"y":140,"wires":[{"id":"3e282b34a50bc378"}]}],"out":[{"x":1080,"y":140,"wires":[{"id":"86c52c65d7f47c12","port":0}]}],"env":[],"meta":{},"color":"#DDAA99","icon":"font-awesome/fa-user-circle-o"},{"id":"71513b70.d07824","type":"file in","z":"b62e4b55.b6e888","name":"auth","filename":"/config/.storage/auth","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":550,"y":140,"wires":[["833cfa89.049518"]]},{"id":"833cfa89.049518","type":"json","z":"b62e4b55.b6e888","name":"","property":"payload","action":"obj","pretty":false,"x":670,"y":140,"wires":[["2bd011b4.4f829e"]]},{"id":"2bd011b4.4f829e","type":"function","z":"b62e4b55.b6e888","name":"","func":"var user_id = msg.data.context.user_id;\n//var user_id = data.event.new_state.context.user_id;\nvar user_name = \"\";\nvar user_system = null;\n\nfor (var i = 0; i < msg.payload.data.users.length; i++) {\n    \n    var user = msg.payload.data.users[i];\n    \n    console.log(user.id);\n    \n    if (user.id == user_id) {\n        user_name = user.name;\n        user_system = user.system_generated;\n        break;\n    }\n}\nmsg.data.context.user_name = user_name == \"Hass.io\" ? \"Home Assistant\" : user_name;\nmsg.data.context.user_system = user_system;\n\ndelete msg.filename; \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":140,"wires":[["86c52c65d7f47c12"]]},{"id":"3e282b34a50bc378","type":"change","z":"b62e4b55.b6e888","name":"Move","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"flow","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":140,"wires":[["71513b70.d07824"]]},{"id":"86c52c65d7f47c12","type":"change","z":"b62e4b55.b6e888","name":"Move","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"flow","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":140,"wires":[[]]},{"id":"26c6c4d5.3a01e4","type":"subflow","name":"Sub Flux","info":"","category":"","in":[{"x":40,"y":60,"wires":[{"id":"7d4ca80d.e23468"}]}],"out":[{"x":1440,"y":60,"wires":[{"id":"7af30c5b46b6cb83","port":0}]}],"env":[],"meta":{},"color":"#DDAA99","inputLabels":["any message"],"outputLabels":["Info","Brightness","Temperature"],"icon":"node-red-contrib-sun-position/sun-white.png"},{"id":"dc97f68a.35ea2","type":"switch","z":"26c6c4d5.3a01e4","name":"Times","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"night","vt":"str"},{"t":"eq","v":"dusk","vt":"str"},{"t":"eq","v":"dawn","vt":"str"},{"t":"eq","v":"day","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":470,"y":200,"wires":[["57eb916940622fad"],["eef1dc11.39342","2e9ef8a9.d7fd88"],["ad9966f3.3fced","4db18fbe.9ffb6"],["87ef978514c3b115"]]},{"id":"ad9966f3.3fced","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"dawn brightness","output_key":"payload","input_key":"payload","points":[{"x":0,"y":0},{"x":0.071,"y":0.02},{"x":0.254,"y":0.297},{"x":0.654,"y":0.877},{"x":1,"y":1}],"x":700,"y":220,"wires":[["e64dbfa.021204"]]},{"id":"eef1dc11.39342","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"dusk brightness","output_key":"payload","input_key":"payload","points":[{"x":0,"y":1},{"x":0.25,"y":0.8},{"x":0.75,"y":0.1},{"x":1,"y":0}],"x":700,"y":140,"wires":[["e64dbfa.021204"]]},{"id":"4db18fbe.9ffb6","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"dawn temperature","output_key":"payload","input_key":"payload","points":[{"x":0,"y":0},{"x":0.1,"y":0.01},{"x":0.25,"y":0.05},{"x":0.4,"y":0.2},{"x":0.573,"y":0.6},{"x":1,"y":1}],"x":710,"y":260,"wires":[["d9f0035a.28956"]]},{"id":"2e9ef8a9.d7fd88","type":"spline-curve","z":"26c6c4d5.3a01e4","name":"dusk temperature","output_key":"payload","input_key":"payload","points":[{"x":0,"y":1},{"x":0.019,"y":0.918},{"x":0.162,"y":0.541},{"x":0.536,"y":0.121},{"x":1,"y":0}],"x":710,"y":180,"wires":[["d9f0035a.28956"]]},{"id":"667d6dd.334db94","type":"function","z":"26c6c4d5.3a01e4","name":"Times of Day","func":"var newmsg = { topic: \"flux\", current: {}, times: {} };\nnewmsg.sunpos = JSON.parse(JSON.stringify(msg)).payload;\n\n//https://github.com/rdmtc/node-red-contrib-sun-position/wiki/Base-Functions#sun-times\nevalPeriod('night', newmsg, \"astronomicalDusk\",   \"amateurDawn\",3600000);\nevalPeriod('dawn',  newmsg, \"amateurDawn\",        \"goldenHourDawnEnd\");\nevalPeriod('day', newmsg, \"goldenHourDawnEnd\", \"sunsetStart\", 0, -1800000);\nevalPeriod('dusk', newmsg, \"sunsetStart\", \"astronomicalDusk\", -1800000,3600000);\n\nreturn [newmsg,\n    { \n        topic:      newmsg.current.name,\n        payload:    newmsg.current.perc\n    }\n    ];\n\nfunction Epoch2Human(epoch) {\n    var myDate = new Date(epoch);\n    return myDate.toLocaleString(\"fr-FR\");\n}\nfunction Epoch2iso(epoch) {\n    var myDate = new Date(epoch);\n    return myDate.toISOString();\n}\nfunction Epoch2Duration(epoch) {\n    var sec_num = Math.floor(epoch / 1000)\n    var hours = Math.floor(sec_num / 3600);\n    var minutes = Math.floor((sec_num - (hours * 3600)) / 60);\n    var seconds = sec_num - (hours * 3600) - (minutes * 60);\n\n    if (hours < 10) { hours = \"0\" + hours; }\n    if (minutes < 10) { minutes = \"0\" + minutes; }\n    if (seconds < 10) { seconds = \"0\" + seconds; }\n    return hours + ':' + minutes + ':' + seconds;\n}\nfunction evalPeriod(nme, obj, name_start, name_end, offset_start=0, offset_end=0) {\n    var ret         = { \n        name: nme, \n        hm_delta: null, \n        hm_start: null, \n        hm_end: null,\n        ts_start: null,\n        ts_end: null\n        };\n    ret.start       = obj.sunpos.times[name_start].ts + offset_start;\n    ret.end         = obj.sunpos.times[name_end].ts + offset_end;\n\n    // to cover range starting before midnight and ending after it.\n    if (ret.start > ret.end) {\n        var a;\n\n        // before midnight\n        if (ret.start < obj.sunpos.ts) {\n            a = new Date(ret.end);\n            a.setUTCDate(a.getUTCDate() + 1);\n            ret.end = a.getTime();\n\n\n        }\n        else if (ret.end > obj.sunpos.ts) {\n            a = new Date(ret.start);\n            a.setUTCDate(a.getUTCDate() - 1);\n            ret.start = a.getTime();\n\n        }\n    }\n\n    ret.delta       = ret.end - ret.start;\n    ret.hm_delta    = Epoch2Duration(ret.delta);\n    ret.hm_start    = Epoch2Human(ret.start);\n    ret.hm_end      = Epoch2Human(ret.end);\n    ret.ts_start    = Epoch2iso(ret.start);\n    ret.ts_end      = Epoch2iso(ret.end);\n\n    obj.times[nme]  = ret;\n    if (ret.start <= obj.sunpos.ts && obj.sunpos.ts < ret.end) {\n        obj.current = ret;\n        obj.current.perc = (obj.sunpos.ts - ret.start) / ret.delta;\n    }\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":60,"wires":[["7af30c5b46b6cb83"],["dc97f68a.35ea2"]]},{"id":"e64dbfa.021204","type":"range","z":"26c6c4d5.3a01e4","minin":"0","maxin":"1","minout":"15","maxout":"100","action":"clamp","round":true,"property":"payload","name":"","x":960,"y":100,"wires":[["97d34f99252ec79b"]]},{"id":"d9f0035a.28956","type":"range","z":"26c6c4d5.3a01e4","minin":"0","maxin":"1","minout":"2700","maxout":"6500","action":"clamp","round":true,"property":"payload","name":"","x":970,"y":300,"wires":[["794d74c2affe32dd"]]},{"id":"7d4ca80d.e23468","type":"sun-position","z":"26c6c4d5.3a01e4","name":"","positionConfig":"72018d9177e1240e","rules":[],"onlyOnChange":"true","topic":"","outputs":1,"start":"","startType":"none","startOffset":0,"startOffsetType":"num","startOffsetMultiplier":60000,"end":"","endType":"none","endOffset":0,"endOffsetType":"num","endOffsetMultiplier":60000,"x":150,"y":60,"wires":[["667d6dd.334db94"]]},{"id":"87ef978514c3b115","type":"change","z":"26c6c4d5.3a01e4","name":"Day","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":300,"wires":[["8b303ac065606ebf"]]},{"id":"57eb916940622fad","type":"change","z":"26c6c4d5.3a01e4","name":"Night","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":100,"wires":[["211969df4553409a"]]},{"id":"794d74c2affe32dd","type":"change","z":"26c6c4d5.3a01e4","name":"Move","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"move","p":"payload","pt":"msg","to":"current.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":300,"wires":[["7af30c5b46b6cb83"]]},{"id":"97d34f99252ec79b","type":"change","z":"26c6c4d5.3a01e4","name":"Move","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"move","p":"payload","pt":"msg","to":"current.brightness","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":100,"wires":[["7af30c5b46b6cb83"]]},{"id":"7af30c5b46b6cb83","type":"join","z":"26c6c4d5.3a01e4","name":"","mode":"custom","build":"merged","property":"current","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"12","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1310,"y":60,"wires":[[]]},{"id":"72018d9177e1240e","type":"position-config","name":"","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":99,"timeZoneDST":0,"stateTimeFormat":"3","stateDateFormat":"12","contextStore":""},{"id":"7c36779e.82d778","type":"subflow:26c6c4d5.3a01e4","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Flux","env":[],"x":330,"y":480,"wires":[["e03358fbb0d58292","1f338bb84eea05a6"]],"icon":"node-red-node-suncalc/sun.png"},{"id":"c17fcdbf5c1601ca","type":"inject","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"","props":[],"repeat":"300","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":170,"y":480,"wires":[["7c36779e.82d778"]]},{"id":"96c46a37c4c1d229","type":"ha-entity","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Brightness","server":"8093ca4.46eb138","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Flux Brightness"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:brightness-percent"},{"property":"unit_of_measurement","value":" %"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"current.brightness","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":650,"y":560,"wires":[["b2de534c9548128e"]]},{"id":"b2de534c9548128e","type":"ha-entity","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Temperature","server":"8093ca4.46eb138","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Flux Kelvin"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:temperature-kelvin"},{"property":"unit_of_measurement","value":" K"},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"current.temperature","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":830,"y":560,"wires":[[]]},{"id":"1f338bb84eea05a6","type":"ha-entity","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Period","server":"8093ca4.46eb138","version":2,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Flux Period"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:chart-timeline"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"current.name","stateType":"msg","attributes":[{"property":"start","value":"current.ts_start","valueType":"msg"},{"property":"end","value":"current.ts_end","valueType":"msg"},{"property":"duration","value":"current.hm_delta","valueType":"msg"},{"property":"perc","value":"current.perc","valueType":"msg"}],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":490,"y":560,"wires":[["96c46a37c4c1d229"]]},{"id":"87212c336e7a404e","type":"api-call-service","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Light","server":"8093ca4.46eb138","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["{{payload.entity_id}}"],"data":"{\t   \"brightness_pct\": current.brightness,\t   \"kelvin\": current.temperature,\t   \"transition\": payload.timeSinceChangedMs>30000?15:1\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1010,"y":480,"wires":[[]]},{"id":"e03358fbb0d58292","type":"api-current-state","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Master","server":"8093ca4.46eb138","version":3,"outputs":2,"halt_if":"true","halt_if_type":"bool","halt_if_compare":"is","entity_id":"input_boolean.flux_master","state_type":"habool","blockInputOverrides":true,"outputProperties":[],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":490,"y":480,"wires":[["4ad115d03bf1bcc7"],[]]},{"id":"221d625268d9d855","type":"server-state-changed","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Lights","server":"8093ca4.46eb138","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":["light.bedroom","light.closet","light.guest","light.hallway","light.office"],"entityidfiltertype":"list","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":170,"y":560,"wires":[["7c36779e.82d778"],["ad73ab52dfc9464c"]]},{"id":"4ad115d03bf1bcc7","type":"ha-get-entities","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Auto","server":"8093ca4.46eb138","version":0,"rules":[{"property":"entity_id","logic":"includes","value":"light.office,light.bedroom,light.guest,light.hallway,light.closet","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":630,"y":480,"wires":[["65e26660fdb518f7"]]},{"id":"5075f9dec136e667","type":"trigger-state","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Evt","server":"8093ca4.46eb138","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":["light.bedroom","light.closet","light.guest","light.hallway","light.office"],"entityidfiltertype":"list","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":false,"x":170,"y":640,"wires":[["f50f5dda01a96a73"],[]]},{"id":"d48847fecb73ea12","type":"subflow:b62e4b55.b6e888","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Who","env":[],"x":490,"y":640,"wires":[["9ea0ef28bf1e7c2d"]]},{"id":"9ea0ef28bf1e7c2d","type":"switch","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"User","property":"data.context.user_system","propertyType":"msg","rules":[{"t":"false"},{"t":"null"}],"checkall":"false","repair":false,"outputs":2,"x":630,"y":640,"wires":[["28b68907a6c1c3bd"],["28b68907a6c1c3bd"]]},{"id":"28b68907a6c1c3bd","type":"change","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Lkp","rules":[{"t":"change","p":"topic","pt":"msg","from":"light.","fromt":"str","to":"input_boolean.flux_","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":640,"wires":[["9a8c4b9aa821571a"]]},{"id":"9a8c4b9aa821571a","type":"api-call-service","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Status","server":"8093ca4.46eb138","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["{{topic}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1010,"y":640,"wires":[[]]},{"id":"ad73ab52dfc9464c","type":"change","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Reset","rules":[{"t":"set","p":"payload.service","pt":"msg","to":"turn_on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":580,"wires":[["28b68907a6c1c3bd"]]},{"id":"fc891a29a6a02cf6","type":"api-current-state","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Enabled","server":"8093ca4.46eb138","version":3,"outputs":2,"halt_if":"true","halt_if_type":"bool","halt_if_compare":"is","entity_id":"{{id_flux}}","state_type":"habool","blockInputOverrides":true,"outputProperties":[],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":880,"y":480,"wires":[["87212c336e7a404e"],[]]},{"id":"65e26660fdb518f7","type":"change","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Lkp","rules":[{"t":"set","p":"id_flux","pt":"msg","to":"payload.entity_id","tot":"msg"},{"t":"change","p":"id_flux","pt":"msg","from":"light.","fromt":"re","to":"input_boolean.flux_","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":480,"wires":[["fc891a29a6a02cf6"]]},{"id":"68dc351f6676efdf","type":"server-state-changed","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Enabled","server":"8093ca4.46eb138","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.flux_","entityidfiltertype":"substring","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"x":180,"y":520,"wires":[["7c36779e.82d778"],[]]},{"id":"f50f5dda01a96a73","type":"switch","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Changed","property":"data.event","propertyType":"msg","rules":[{"t":"jsonata_exp","v":"data.event.old_state.attributes.brightness != data.event.new_state.attributes.brightness","vt":"jsonata"},{"t":"jsonata_exp","v":"data.event.old_state.attributes.color_temp != data.event.new_state.attributes.color_temp","vt":"jsonata"}],"checkall":"false","repair":false,"outputs":2,"x":340,"y":640,"wires":[["d48847fecb73ea12"],["d48847fecb73ea12"]],"outputLabels":["Brightness","Temperature"]},{"id":"8093ca4.46eb138","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]

The following nodes could also be added to update only once when lights turn on :

[{"id":"ad9d46948c536056","type":"switch","z":"76d268b99378117f","name":"Init","property":"msg.payload.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"lt","v":"10000","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1030,"y":820,"wires":[[],[]]},{"id":"ea4ca17a545569ee","type":"ha-get-entities","z":"76d268b99378117f","name":"Manual","server":"8093ca4.46eb138","version":0,"rules":[{"property":"entity_id","logic":"includes","value":"light.bedroom,light.guest,light.hallway,light.closet","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":880,"y":820,"wires":[["ad9d46948c536056"]]},{"id":"8093ca4.46eb138","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}] 

2 Likes

I am trying to set this up based on the latest flow from @TEF2one. I added location and input boolean flux and flux_master. But how is it then working on the lights? I do not get errors except for a ‘no connection’ in the most left status node. If use the inject the brightness and temperature are changed but the lights them self do not change.

edit: when using a couple of debug nodes I see that there is an error:

“Entity could not be found in cache for entity_id: input_boolean.flux_light”

I see that this error occurs more frequent and has to do with connection with HA. I checked Delay connection attempts in the HA server. But still same error. I also tried a delay of 5 seconds between nodes but did not help either
Anyone has an idea?

edit: for anyone else. You have to make input booleans for every light separately. I thought it was a cache entity

Whow - this is awesome.
Thank you @maximm for the initial idea and setup, and @dbrunt for the revised flows, d thank you @TEF2one for the nice addons.

I actually prefer @fishertimj’s idea on using global variables wherever you set the lights, as I really hate it when a light turns on very bright at night, and then dims down after a second. The downside is, that I have to move all light on/off logic to NR, and won’t be able to use Toggle anymore (probably have to add a toggle-subflow of my own.

There are some “bugs” in the Version of TEF2one, that might be of interest:
during day or night, there is no brightness/temperature output defined. This is probably not a problem once the setup is running, as there shouldn’t be a change during day, but if you try to debug it during the night/day you will get some error messages.

I’m currently trying to combine all three versions, and figure out a way where I don’t need to enter all my light id’s manually, and maybe move the input-toggles to “area” based instead of “light” based, as I have way to many lights to add them all.

Would you be OK, if I put this on a node-red-contrib github, so others can import it easily into there NR, once I’m done?

1 Like

Yes, please do!

1 Like

Thanks, @elfstone, looks like I simply forgot to wire the day and nigh output in the subflow.

Here is the updated version:

[{"id":"e2f79ea771014cac","type":"subflow","name":"Flux","info":"","category":"","in":[{"x":40,"y":60,"wires":[{"id":"d0d248ff9c3c9cdf"}]}],"out":[{"x":1440,"y":60,"wires":[{"id":"355aab77a1f28f1b","port":0}]}],"env":[],"meta":{},"color":"#DDAA99","inputLabels":["any message"],"outputLabels":["Info"],"icon":"node-red-contrib-sun-position/sun-white.png"},{"id":"0962fbe8cc6ef7bd","type":"switch","z":"e2f79ea771014cac","name":"Times","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"night","vt":"str"},{"t":"eq","v":"dusk","vt":"str"},{"t":"eq","v":"dawn","vt":"str"},{"t":"eq","v":"day","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":490,"y":180,"wires":[["9f45b66901c4535e"],["ec545b23a267c011","b8d8297010775689"],["1fd17b9f356de574","8f412a5f3bd9ab17"],["8ddd9d8ea3158cf4"]]},{"id":"1fd17b9f356de574","type":"spline-curve","z":"e2f79ea771014cac","name":"dawn brightness","output_key":"payload","input_key":"payload","points":[{"x":0,"y":0},{"x":0.071,"y":0.02},{"x":0.254,"y":0.297},{"x":0.654,"y":0.877},{"x":1,"y":1}],"x":720,"y":200,"wires":[["8dd7b7cc157b67c5"]]},{"id":"ec545b23a267c011","type":"spline-curve","z":"e2f79ea771014cac","name":"dusk brightness","output_key":"payload","input_key":"payload","points":[{"x":0,"y":1},{"x":0.25,"y":0.8},{"x":0.75,"y":0.1},{"x":1,"y":0}],"x":720,"y":120,"wires":[["8dd7b7cc157b67c5"]]},{"id":"8f412a5f3bd9ab17","type":"spline-curve","z":"e2f79ea771014cac","name":"dawn temperature","output_key":"payload","input_key":"payload","points":[{"x":0,"y":0},{"x":0.1,"y":0.01},{"x":0.25,"y":0.05},{"x":0.4,"y":0.2},{"x":0.573,"y":0.6},{"x":1,"y":1}],"x":730,"y":240,"wires":[["904e1e2afcc897c1"]]},{"id":"b8d8297010775689","type":"spline-curve","z":"e2f79ea771014cac","name":"dusk temperature","output_key":"payload","input_key":"payload","points":[{"x":0,"y":1},{"x":0.019,"y":0.918},{"x":0.162,"y":0.541},{"x":0.536,"y":0.121},{"x":1,"y":0}],"x":730,"y":160,"wires":[["904e1e2afcc897c1"]]},{"id":"6c8eec59a8ad5310","type":"function","z":"e2f79ea771014cac","name":"Times of Day","func":"var newmsg = { topic: \"flux\", current: {}, times: {} };\nnewmsg.sunpos = JSON.parse(JSON.stringify(msg)).payload;\n\n//https://github.com/rdmtc/node-red-contrib-sun-position/wiki/Base-Functions#sun-times\nevalPeriod('night', newmsg, \"astronomicalDusk\",   \"amateurDawn\",3600000);\nevalPeriod('dawn',  newmsg, \"amateurDawn\",        \"goldenHourDawnEnd\");\nevalPeriod('day', newmsg, \"goldenHourDawnEnd\", \"sunsetStart\", 0, -1800000);\nevalPeriod('dusk', newmsg, \"sunsetStart\", \"astronomicalDusk\", -1800000,3600000);\n\nreturn [newmsg,\n    { \n        topic:      newmsg.current.name,\n        payload:    newmsg.current.perc\n    }\n    ];\n\nfunction Epoch2Human(epoch) {\n    var myDate = new Date(epoch);\n    return myDate.toLocaleString(\"fr-FR\");\n}\nfunction Epoch2iso(epoch) {\n    var myDate = new Date(epoch);\n    return myDate.toISOString();\n}\nfunction Epoch2Duration(epoch) {\n    var sec_num = Math.floor(epoch / 1000)\n    var hours = Math.floor(sec_num / 3600);\n    var minutes = Math.floor((sec_num - (hours * 3600)) / 60);\n    var seconds = sec_num - (hours * 3600) - (minutes * 60);\n\n    if (hours < 10) { hours = \"0\" + hours; }\n    if (minutes < 10) { minutes = \"0\" + minutes; }\n    if (seconds < 10) { seconds = \"0\" + seconds; }\n    return hours + ':' + minutes + ':' + seconds;\n}\nfunction evalPeriod(nme, obj, name_start, name_end, offset_start=0, offset_end=0) {\n    var ret         = { \n        name: nme, \n        hm_delta: null, \n        hm_start: null, \n        hm_end: null,\n        ts_start: null,\n        ts_end: null\n        };\n    ret.start       = obj.sunpos.times[name_start].ts + offset_start;\n    ret.end         = obj.sunpos.times[name_end].ts + offset_end;\n\n    // to cover range starting before midnight and ending after it.\n    if (ret.start > ret.end) {\n        var a;\n\n        // before midnight\n        if (ret.start < obj.sunpos.ts) {\n            a = new Date(ret.end);\n            a.setUTCDate(a.getUTCDate() + 1);\n            ret.end = a.getTime();\n\n\n        }\n        else if (ret.end > obj.sunpos.ts) {\n            a = new Date(ret.start);\n            a.setUTCDate(a.getUTCDate() - 1);\n            ret.start = a.getTime();\n\n        }\n    }\n\n    ret.delta       = ret.end - ret.start;\n    ret.hm_delta    = Epoch2Duration(ret.delta);\n    ret.hm_start    = Epoch2Human(ret.start);\n    ret.hm_end      = Epoch2Human(ret.end);\n    ret.ts_start    = Epoch2iso(ret.start);\n    ret.ts_end      = Epoch2iso(ret.end);\n\n    obj.times[nme]  = ret;\n    if (ret.start <= obj.sunpos.ts && obj.sunpos.ts < ret.end) {\n        obj.current = ret;\n        obj.current.perc = (obj.sunpos.ts - ret.start) / ret.delta;\n    }\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":60,"wires":[["355aab77a1f28f1b"],["0962fbe8cc6ef7bd"]]},{"id":"8dd7b7cc157b67c5","type":"range","z":"e2f79ea771014cac","minin":"0","maxin":"1","minout":"15","maxout":"100","action":"clamp","round":true,"property":"payload","name":"","x":980,"y":160,"wires":[["3091475fc030904a"]]},{"id":"904e1e2afcc897c1","type":"range","z":"e2f79ea771014cac","minin":"0","maxin":"1","minout":"2700","maxout":"6500","action":"clamp","round":true,"property":"payload","name":"","x":990,"y":200,"wires":[["2a2604373b10dddb"]]},{"id":"d0d248ff9c3c9cdf","type":"sun-position","z":"e2f79ea771014cac","name":"","positionConfig":"72018d9177e1240e","rules":[],"onlyOnChange":"true","topic":"","outputs":1,"start":"","startType":"none","startOffset":0,"startOffsetType":"num","startOffsetMultiplier":60000,"end":"","endType":"none","endOffset":0,"endOffsetType":"num","endOffsetMultiplier":60000,"x":150,"y":60,"wires":[["6c8eec59a8ad5310"]]},{"id":"8ddd9d8ea3158cf4","type":"change","z":"e2f79ea771014cac","name":"Day","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":280,"wires":[["9db8ab7a3a8ee31c"]]},{"id":"9f45b66901c4535e","type":"change","z":"e2f79ea771014cac","name":"Night","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":80,"wires":[["e07d1484bd27c46d"]]},{"id":"2a2604373b10dddb","type":"change","z":"e2f79ea771014cac","name":"Move","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"move","p":"payload","pt":"msg","to":"current.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":200,"wires":[["355aab77a1f28f1b"]]},{"id":"3091475fc030904a","type":"change","z":"e2f79ea771014cac","name":"Move","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"move","p":"payload","pt":"msg","to":"current.brightness","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":160,"wires":[["355aab77a1f28f1b"]]},{"id":"355aab77a1f28f1b","type":"join","z":"e2f79ea771014cac","name":"","mode":"custom","build":"merged","property":"current","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"12","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1330,"y":60,"wires":[[]]},{"id":"9db8ab7a3a8ee31c","type":"junction","z":"e2f79ea771014cac","x":840,"y":280,"wires":[["904e1e2afcc897c1","8dd7b7cc157b67c5"]]},{"id":"e07d1484bd27c46d","type":"junction","z":"e2f79ea771014cac","x":840,"y":80,"wires":[["8dd7b7cc157b67c5","904e1e2afcc897c1"]]},{"id":"72018d9177e1240e","type":"position-config","name":"","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":99,"timeZoneDST":0,"stateTimeFormat":"3","stateDateFormat":"12","contextStore":""},{"id":"7e118ca8606a48b2","type":"subflow:e2f79ea771014cac","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Flux","env":[],"x":330,"y":80,"wires":[["e03358fbb0d58292","9ef36a6101fdccfa"]],"icon":"node-red-node-suncalc/sun.png"}]
2 Likes

Here is a new version of the flux subflow with an updated script allowing for fixed time specification.
For example while I want to follow more or less the circadian circle to adjust the lights, I want to specify a fixed hour for the night such as 23:00 so my light slowly fade from dusk to that specified time, instead of the actuall sunset wihich during winter is way too early for me…

[{"id":"e2f79ea771014cac","type":"subflow","name":"Flux","info":"","category":"","in":[{"x":40,"y":60,"wires":[{"id":"d0d248ff9c3c9cdf"}]}],"out":[{"x":1440,"y":60,"wires":[{"id":"355aab77a1f28f1b","port":0}]}],"env":[],"meta":{},"color":"#DDAA99","inputLabels":["any message"],"outputLabels":["Info"],"icon":"node-red-contrib-sun-position/sun-white.png"},{"id":"0962fbe8cc6ef7bd","type":"switch","z":"e2f79ea771014cac","name":"Times","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"night","vt":"str"},{"t":"eq","v":"dusk","vt":"str"},{"t":"eq","v":"dawn","vt":"str"},{"t":"eq","v":"day","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":490,"y":180,"wires":[["9f45b66901c4535e"],["ec545b23a267c011","b8d8297010775689"],["1fd17b9f356de574","8f412a5f3bd9ab17"],["8ddd9d8ea3158cf4"]]},{"id":"1fd17b9f356de574","type":"spline-curve","z":"e2f79ea771014cac","name":"dawn brightness","output_key":"payload","input_key":"payload","points":[{"x":0,"y":0},{"x":0.071,"y":0.02},{"x":0.254,"y":0.297},{"x":0.654,"y":0.877},{"x":1,"y":1}],"x":720,"y":200,"wires":[["8dd7b7cc157b67c5"]]},{"id":"ec545b23a267c011","type":"spline-curve","z":"e2f79ea771014cac","name":"dusk brightness","output_key":"payload","input_key":"payload","points":[{"x":0,"y":1},{"x":0.25,"y":0.8},{"x":0.75,"y":0.1},{"x":1,"y":0}],"x":720,"y":120,"wires":[["8dd7b7cc157b67c5"]]},{"id":"8f412a5f3bd9ab17","type":"spline-curve","z":"e2f79ea771014cac","name":"dawn temperature","output_key":"payload","input_key":"payload","points":[{"x":0,"y":0},{"x":0.1,"y":0.01},{"x":0.25,"y":0.05},{"x":0.4,"y":0.2},{"x":0.573,"y":0.6},{"x":1,"y":1}],"x":730,"y":240,"wires":[["904e1e2afcc897c1"]]},{"id":"b8d8297010775689","type":"spline-curve","z":"e2f79ea771014cac","name":"dusk temperature","output_key":"payload","input_key":"payload","points":[{"x":0,"y":1},{"x":0.019,"y":0.918},{"x":0.162,"y":0.541},{"x":0.536,"y":0.121},{"x":1,"y":0}],"x":730,"y":160,"wires":[["904e1e2afcc897c1"]]},{"id":"6c8eec59a8ad5310","type":"function","z":"e2f79ea771014cac","name":"Times of Day","func":"var newmsg = { topic: \"flux\", current: {}, times: {} };\nnewmsg.sunpos = JSON.parse(JSON.stringify(msg)).payload;\n\n//https://github.com/rdmtc/node-red-contrib-sun-position/wiki/Base-Functions#sun-times\nevalPeriod('dawn', newmsg, \"goldenHourDawnEnd\", \"amateurDawn\");\nevalPeriod('day', newmsg, \"sunsetStart\"); //sunsetStart\nevalPeriod('dusk', newmsg, \"23:00\"); //astronomicalDusk\nevalPeriod('night', newmsg);        //amateurDawn\n\nreturn [newmsg,\n    {\n        topic: newmsg.current.name,\n        payload: newmsg.current.perc\n    }\n];\n\nfunction evalPeriod(nme, obj, end = null, start = null) {\n    let d;\n    let ret = {\n        name: nme,\n        hm_delta:   null,\n        hm_start:   null,\n        hm_end:     null,\n        ts_start:   null,\n        ts_end:     null\n    };\n    ret.start = start ? ( obj.sunpos.times[start] === undefined ? Human2Epoch(start) : obj.sunpos.times[start].ts ) : Object.values(obj.times).at(-1).end;\n    ret.end   = end   ? ( obj.sunpos.times[end]   === undefined ? Human2Epoch(end)   : obj.sunpos.times[end].ts   ) : Object.values(obj.times).at(0).start;\n    \n    // to cover range starting before midnight and ending after it.\n    if (ret.start > ret.end) {\n        if (ret.start < obj.sunpos.ts) {\n            d = new Date(ret.end);\n            d.setUTCDate(d.getUTCDate() + 1);\n            ret.end = d.getTime();\n        } \n        else if (ret.end > obj.sunpos.ts) {\n            d = new Date(ret.start);\n            d.setUTCDate(d.getUTCDate() - 1);\n            ret.start = d.getTime();\n        }\n    }\n\n\n    ret.delta = ret.end - ret.start;\n    ret.hm_delta = Epoch2Duration(ret.delta);\n    ret.hm_start = Epoch2Human(ret.start);\n    ret.hm_end = Epoch2Human(ret.end);\n    ret.ts_start = Epoch2iso(ret.start);\n    ret.ts_end = Epoch2iso(ret.end);\n\n    obj.times[nme] = ret;\n    if (ret.start <= obj.sunpos.ts && obj.sunpos.ts < ret.end) {\n        obj.current = ret;\n        obj.current.perc = (obj.sunpos.ts - ret.start) / ret.delta;\n    }\n}\nfunction Human2Epoch(human) {\n    let d1 = new Date();\n    let d2 = new Date(d1.toLocaleDateString() + \" \" + human);\n    return d2.getTime();\n}\nfunction Epoch2Human(epoch) {\n    var myDate = new Date(epoch);\n    return myDate.toLocaleString(\"fr-FR\");\n}\nfunction Epoch2iso(epoch) {\n    let d = new Date(epoch);\n    return d.toISOString();\n}\nfunction Epoch2Duration(epoch) {\n    let sec_num = Math.floor(epoch / 1000)\n    let hours = Math.floor(sec_num / 3600);\n    let minutes = Math.floor((sec_num - (hours * 3600)) / 60);\n    let seconds = sec_num - (hours * 3600) - (minutes * 60);\n\n    if (hours < 10) { hours = \"0\" + hours; }\n    if (minutes < 10) { minutes = \"0\" + minutes; }\n    if (seconds < 10) { seconds = \"0\" + seconds; }\n    return hours + ':' + minutes + ':' + seconds;\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":310,"y":60,"wires":[["355aab77a1f28f1b"],["0962fbe8cc6ef7bd"]]},{"id":"8dd7b7cc157b67c5","type":"range","z":"e2f79ea771014cac","minin":"0","maxin":"1","minout":"15","maxout":"100","action":"clamp","round":true,"property":"payload","name":"","x":980,"y":160,"wires":[["3091475fc030904a"]]},{"id":"904e1e2afcc897c1","type":"range","z":"e2f79ea771014cac","minin":"0","maxin":"1","minout":"2700","maxout":"6500","action":"clamp","round":true,"property":"payload","name":"","x":990,"y":200,"wires":[["2a2604373b10dddb"]]},{"id":"d0d248ff9c3c9cdf","type":"sun-position","z":"e2f79ea771014cac","name":"","positionConfig":"72018d9177e1240e","rules":[],"onlyOnChange":"true","topic":"","outputs":1,"start":"","startType":"none","startOffset":0,"startOffsetType":"num","startOffsetMultiplier":60000,"end":"","endType":"none","endOffset":0,"endOffsetType":"num","endOffsetMultiplier":60000,"x":150,"y":60,"wires":[["6c8eec59a8ad5310"]]},{"id":"8ddd9d8ea3158cf4","type":"change","z":"e2f79ea771014cac","name":"Day","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":280,"wires":[["9db8ab7a3a8ee31c"]]},{"id":"9f45b66901c4535e","type":"change","z":"e2f79ea771014cac","name":"Night","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":80,"wires":[["e07d1484bd27c46d"]]},{"id":"2a2604373b10dddb","type":"change","z":"e2f79ea771014cac","name":"Move","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"move","p":"payload","pt":"msg","to":"current.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":200,"wires":[["355aab77a1f28f1b"]]},{"id":"3091475fc030904a","type":"change","z":"e2f79ea771014cac","name":"Move","rules":[{"t":"delete","p":"topic","pt":"msg"},{"t":"move","p":"payload","pt":"msg","to":"current.brightness","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":160,"wires":[["355aab77a1f28f1b"]]},{"id":"355aab77a1f28f1b","type":"join","z":"e2f79ea771014cac","name":"","mode":"custom","build":"merged","property":"current","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"1","count":"12","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1330,"y":60,"wires":[[]]},{"id":"9db8ab7a3a8ee31c","type":"junction","z":"e2f79ea771014cac","x":840,"y":280,"wires":[["904e1e2afcc897c1","8dd7b7cc157b67c5"]]},{"id":"e07d1484bd27c46d","type":"junction","z":"e2f79ea771014cac","x":840,"y":80,"wires":[["8dd7b7cc157b67c5","904e1e2afcc897c1"]]},{"id":"72018d9177e1240e","type":"position-config","name":"","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":99,"timeZoneDST":0,"stateTimeFormat":"3","stateDateFormat":"12","contextStore":""},{"id":"7e118ca8606a48b2","type":"subflow:e2f79ea771014cac","z":"76d268b99378117f","g":"09e8f85672b69e6e","name":"Flux","env":[],"x":330,"y":80,"wires":[["e03358fbb0d58292","9ef36a6101fdccfa"]],"icon":"node-red-node-suncalc/sun.png"}]

Nice!

I have just about finished an adaptation of this for my H801 WiFi RGBW aquarium lighting controller flashed with ESPHome. I’ve got the blue working the way I want during the night but still have to fine tune the red/green/blue curves for the morning/day/evening…

[{"id":"f0d97d577f05a92c","type":"switch","z":"43b31753070e19b0","name":"curve switch","property":"payload.times_of_day.active.name","propertyType":"msg","rules":[{"t":"eq","v":"night","vt":"str"},{"t":"eq","v":"morning","vt":"str"},{"t":"eq","v":"day","vt":"str"},{"t":"eq","v":"evening","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":195,"y":420,"wires":[["979e46fdd727e5d2"],["9e9035cf8099234b"],["d1e83c5e73f88951"],["8e5598c9d6c60136"]]},{"id":"66ae2ab586f841f2","type":"spline-curve","z":"43b31753070e19b0","name":"night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.1},{"x":0.25,"y":0.2},{"x":0.5,"y":0.4},{"x":0.75,"y":0.2},{"x":1,"y":0.1}],"x":590,"y":40,"wires":[["68f3c71879fc1d85"]]},{"id":"ac14849c57a5e83c","type":"spline-curve","z":"43b31753070e19b0","name":"morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.1},{"x":0.25,"y":0.2},{"x":0.5,"y":0.3},{"x":0.75,"y":0.4},{"x":1,"y":0.5}],"x":580,"y":80,"wires":[["68f3c71879fc1d85"]]},{"id":"d476ee5350fd3b39","type":"spline-curve","z":"43b31753070e19b0","name":"evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.4},{"x":0.333,"y":0.3},{"x":0.666,"y":0.2},{"x":1,"y":0.1}],"x":580,"y":160,"wires":[["68f3c71879fc1d85"]]},{"id":"4853a4c4103f38f7","type":"spline-curve","z":"43b31753070e19b0","name":"day curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.5},{"x":0.18,"y":0.55},{"x":0.33,"y":0.6},{"x":0.5,"y":0.7},{"x":0.67,"y":0.6},{"x":0.821,"y":0.55},{"x":1,"y":0.5}],"x":600,"y":120,"wires":[["68f3c71879fc1d85"]]},{"id":"68f3c71879fc1d85","type":"range","z":"43b31753070e19b0","minin":"0","maxin":"1","minout":"1","maxout":"255","action":"clamp","round":true,"property":"payload","name":"","x":780,"y":100,"wires":[["7b7d05b4b9f34f8b"]]},{"id":"bcf93a8aa7d30bc5","type":"sun-position","z":"43b31753070e19b0","name":"","positionConfig":"31826811.22a458","rules":[],"onlyOnChange":"true","topic":"","outputs":1,"start":"","startType":"none","startOffset":0,"startOffsetType":"num","startOffsetMultiplier":60000,"end":"","endType":"none","endOffset":0,"endOffsetType":"num","endOffsetMultiplier":60000,"x":150,"y":240,"wires":[["f6609b5cd420ca76"]]},{"id":"29a098afbb90bf8d","type":"range","z":"43b31753070e19b0","minin":"0","maxin":"1","minout":"0","maxout":"255","action":"clamp","round":true,"property":"payload","name":"","x":780,"y":420,"wires":[["73cb286d5b8b58c6"]]},{"id":"8fbd23f48cc0e20d","type":"range","z":"43b31753070e19b0","minin":"0","maxin":"1","minout":"0","maxout":"255","action":"clamp","round":true,"property":"payload","name":"","x":780,"y":580,"wires":[["5b72ab3f62d72eb8"]]},{"id":"67012d69669e4bbb","type":"spline-curve","z":"43b31753070e19b0","name":"green night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":1,"y":0}],"x":570,"y":360,"wires":[["29a098afbb90bf8d"]]},{"id":"701a9cb2f37a5561","type":"spline-curve","z":"43b31753070e19b0","name":"green morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":0.42,"y":0.018},{"x":0.54,"y":0.051},{"x":0.587,"y":0.101},{"x":0.817,"y":0.675},{"x":1,"y":0.85}],"x":560,"y":400,"wires":[["29a098afbb90bf8d"]]},{"id":"6c348849966d8edc","type":"spline-curve","z":"43b31753070e19b0","name":"green day curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":0.4,"y":0.973},{"x":0.5,"y":0.87},{"x":0.616,"y":0.983},{"x":1,"y":0}],"x":580,"y":440,"wires":[["29a098afbb90bf8d"]]},{"id":"4c4f2a8d9687c561","type":"spline-curve","z":"43b31753070e19b0","name":"green evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.75},{"x":0.5,"y":0.63},{"x":1,"y":0}],"x":560,"y":480,"wires":[["29a098afbb90bf8d"]]},{"id":"b41fd29cf8fe6b96","type":"spline-curve","z":"43b31753070e19b0","name":"blue night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.25},{"x":0.098,"y":0.243},{"x":0.25,"y":0.503},{"x":0.41,"y":0.753},{"x":0.593,"y":0.75},{"x":0.746,"y":0.5},{"x":0.864,"y":0.26},{"x":0.978,"y":0.25}],"x":580,"y":520,"wires":[["8fbd23f48cc0e20d"]]},{"id":"cd298379b74a0981","type":"spline-curve","z":"43b31753070e19b0","name":"blue morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":0.42,"y":0.018},{"x":0.54,"y":0.051},{"x":0.587,"y":0.101},{"x":0.817,"y":0.675},{"x":1,"y":0.85}],"x":570,"y":560,"wires":[["8fbd23f48cc0e20d"]]},{"id":"698a18314fd6d894","type":"spline-curve","z":"43b31753070e19b0","name":"blue day curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0.003,"y":0},{"x":0.25,"y":0.7},{"x":0.5,"y":0.993},{"x":0.75,"y":0.703},{"x":0.986,"y":0}],"x":580,"y":600,"wires":[["8fbd23f48cc0e20d"]]},{"id":"b92dfe56ebec0bf9","type":"spline-curve","z":"43b31753070e19b0","name":"blue evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.503,"y":0.403},{"x":0.983,"y":0.25}],"x":570,"y":640,"wires":[["8fbd23f48cc0e20d"]]},{"id":"3f86cc2e1f80d99f","type":"spline-curve","z":"43b31753070e19b0","name":"red night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":1,"y":0}],"x":580,"y":200,"wires":[["b024f6a02860eddc"]]},{"id":"d66171ee1ee1d623","type":"spline-curve","z":"43b31753070e19b0","name":"red morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":0.42,"y":0.018},{"x":0.54,"y":0.051},{"x":0.587,"y":0.101},{"x":0.817,"y":0.675},{"x":1,"y":0.85}],"x":570,"y":240,"wires":[["b024f6a02860eddc"]]},{"id":"12207795dc1f0a73","type":"spline-curve","z":"43b31753070e19b0","name":"red evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.75},{"x":0.5,"y":0.637},{"x":1,"y":0}],"x":570,"y":320,"wires":[["b024f6a02860eddc"]]},{"id":"4bc29c58a1d9107a","type":"spline-curve","z":"43b31753070e19b0","name":"red day curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":1},{"x":0.33,"y":1},{"x":0.66,"y":1},{"x":1,"y":1}],"x":580,"y":280,"wires":[["b024f6a02860eddc"]]},{"id":"b024f6a02860eddc","type":"range","z":"43b31753070e19b0","minin":"0","maxin":"1","minout":"0","maxout":"255","action":"clamp","round":true,"property":"payload","name":"","x":780,"y":260,"wires":[["ceaa91580b5e254e"]]},{"id":"e35665db7818a5bf","type":"range","z":"43b31753070e19b0","minin":"0","maxin":"1","minout":"0","maxout":"255","action":"clamp","round":true,"property":"payload","name":"","x":780,"y":740,"wires":[["327d15b9e8acc8b8"]]},{"id":"2e05a56a4b427a6a","type":"link in","z":"43b31753070e19b0","name":"Night Brightness","links":["979e46fdd727e5d2"],"x":425,"y":40,"wires":[["66ae2ab586f841f2"]]},{"id":"56b24d0edd0179cd","type":"link in","z":"43b31753070e19b0","name":"Morning Brightness","links":["9e9035cf8099234b"],"x":425,"y":80,"wires":[["ac14849c57a5e83c"]]},{"id":"7e6e54dc69b56b7d","type":"link in","z":"43b31753070e19b0","name":"Daylight Brightness","links":["d1e83c5e73f88951"],"x":425,"y":120,"wires":[["4853a4c4103f38f7"]]},{"id":"2bbd921dad6c2e6d","type":"link in","z":"43b31753070e19b0","name":"Evening Brightness","links":["8e5598c9d6c60136"],"x":425,"y":160,"wires":[["d476ee5350fd3b39"]]},{"id":"b37f50802bb36d2b","type":"link in","z":"43b31753070e19b0","name":"Night White","links":["979e46fdd727e5d2"],"x":425,"y":680,"wires":[["07a93e2506a56bf4"]]},{"id":"c79eac155c9f5885","type":"link in","z":"43b31753070e19b0","name":"Morning White","links":["9e9035cf8099234b"],"x":425,"y":720,"wires":[["7e089ec04a10ee1d"]]},{"id":"74741eaeb6f44a43","type":"link in","z":"43b31753070e19b0","name":"Daylight White","links":["d1e83c5e73f88951"],"x":425,"y":760,"wires":[["8a0e55ccb2eb515a"]]},{"id":"394249689def1e9c","type":"link in","z":"43b31753070e19b0","name":"Evening White","links":["8e5598c9d6c60136"],"x":445,"y":800,"wires":[["b5ec31986b77721e"]]},{"id":"548c688944e2ff36","type":"link in","z":"43b31753070e19b0","name":"Night Red","links":["979e46fdd727e5d2"],"x":425,"y":200,"wires":[["3f86cc2e1f80d99f"]]},{"id":"d8b1d281255232a2","type":"link in","z":"43b31753070e19b0","name":"Morning Red","links":["9e9035cf8099234b"],"x":425,"y":240,"wires":[["d66171ee1ee1d623"]]},{"id":"6061974c84f92423","type":"link in","z":"43b31753070e19b0","name":"Daylight Red","links":["d1e83c5e73f88951"],"x":425,"y":280,"wires":[["4bc29c58a1d9107a"]]},{"id":"c0b215245a19aaf9","type":"link in","z":"43b31753070e19b0","name":"Evening Red","links":["8e5598c9d6c60136"],"x":425,"y":320,"wires":[["12207795dc1f0a73"]]},{"id":"aec9c78a3fe08029","type":"link in","z":"43b31753070e19b0","name":"Night Green","links":["979e46fdd727e5d2"],"x":425,"y":360,"wires":[["67012d69669e4bbb"]]},{"id":"76b17055d5724e42","type":"link in","z":"43b31753070e19b0","name":"Morning Green","links":["9e9035cf8099234b"],"x":425,"y":400,"wires":[["701a9cb2f37a5561"]]},{"id":"3f51c6245a0dd3cb","type":"link in","z":"43b31753070e19b0","name":"Daylight Green","links":["d1e83c5e73f88951"],"x":425,"y":440,"wires":[["6c348849966d8edc"]]},{"id":"6b1d3103fddafb33","type":"link in","z":"43b31753070e19b0","name":"Evening Green","links":["8e5598c9d6c60136"],"x":425,"y":480,"wires":[["4c4f2a8d9687c561"]]},{"id":"2bc4e6effb057af2","type":"link in","z":"43b31753070e19b0","name":"Night Green","links":["979e46fdd727e5d2"],"x":425,"y":520,"wires":[["b41fd29cf8fe6b96"]]},{"id":"d220fb70f771e1bb","type":"link in","z":"43b31753070e19b0","name":"Morning Green","links":["9e9035cf8099234b"],"x":425,"y":560,"wires":[["cd298379b74a0981"]]},{"id":"642dcd9eaa082558","type":"link in","z":"43b31753070e19b0","name":"Daylight Green","links":["d1e83c5e73f88951"],"x":425,"y":600,"wires":[["698a18314fd6d894"]]},{"id":"c75046571506c876","type":"link in","z":"43b31753070e19b0","name":"Evening Green","links":["8e5598c9d6c60136"],"x":425,"y":640,"wires":[["b92dfe56ebec0bf9"]]},{"id":"979e46fdd727e5d2","type":"link out","z":"43b31753070e19b0","name":"Night","mode":"link","links":["2bc4e6effb057af2","2e05a56a4b427a6a","548c688944e2ff36","aec9c78a3fe08029","b37f50802bb36d2b","f8f4b51755c994bf"],"x":360,"y":360,"wires":[]},{"id":"9e9035cf8099234b","type":"link out","z":"43b31753070e19b0","name":"Morning","mode":"link","links":["56b24d0edd0179cd","76b17055d5724e42","c79eac155c9f5885","d220fb70f771e1bb","d8b1d281255232a2","de761f2e526df026"],"x":360,"y":400,"wires":[]},{"id":"d1e83c5e73f88951","type":"link out","z":"43b31753070e19b0","name":"Daylight","mode":"link","links":["3f51c6245a0dd3cb","6061974c84f92423","642dcd9eaa082558","74741eaeb6f44a43","7e6e54dc69b56b7d","c08c40b6d7354435"],"x":360,"y":440,"wires":[]},{"id":"8e5598c9d6c60136","type":"link out","z":"43b31753070e19b0","name":"Evening","mode":"link","links":["2bbd921dad6c2e6d","394249689def1e9c","6b1d3103fddafb33","ac3c673ef5dd46ad","c0b215245a19aaf9","c75046571506c876"],"x":360,"y":480,"wires":[]},{"id":"a7cfb606.aecfc","type":"change","z":"43b31753070e19b0","name":"Ordered array","rules":[{"t":"set","p":"payload","pt":"msg","to":"$keys($$.payload)^($).$lookup($$.payload, $)","tot":"jsonata"},{"t":"set","p":"topic","pt":"msg","to":"rgbw_color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1160,"y":540,"wires":[["77654077b21096c8"]]},{"id":"ceaa91580b5e254e","type":"change","z":"43b31753070e19b0","name":"Red","rules":[{"t":"set","p":"topic","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":260,"wires":[["2b1f7419.779bc4","ff16a2542e8d4193"]]},{"id":"73cb286d5b8b58c6","type":"change","z":"43b31753070e19b0","name":"Green","rules":[{"t":"set","p":"topic","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":420,"wires":[["2b1f7419.779bc4","ff16a2542e8d4193"]]},{"id":"5b72ab3f62d72eb8","type":"change","z":"43b31753070e19b0","name":"Blue","rules":[{"t":"set","p":"topic","pt":"msg","to":"2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":580,"wires":[["2b1f7419.779bc4","ff16a2542e8d4193"]]},{"id":"327d15b9e8acc8b8","type":"change","z":"43b31753070e19b0","name":"White","rules":[{"t":"set","p":"topic","pt":"msg","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":850,"y":680,"wires":[["798575a0e711f26e"]]},{"id":"07a93e2506a56bf4","type":"spline-curve","z":"43b31753070e19b0","name":"white night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":0.251,"y":0},{"x":0.744,"y":0},{"x":1,"y":0}],"x":570,"y":680,"wires":[["e35665db7818a5bf"]]},{"id":"7e089ec04a10ee1d","type":"spline-curve","z":"43b31753070e19b0","name":"white morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":0.42,"y":0.018},{"x":0.54,"y":0.051},{"x":0.587,"y":0.101},{"x":0.817,"y":0.675},{"x":1,"y":0.85}],"x":560,"y":720,"wires":[["e35665db7818a5bf"]]},{"id":"8a0e55ccb2eb515a","type":"spline-curve","z":"43b31753070e19b0","name":"white day curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.123,"y":0.927},{"x":0.5,"y":1},{"x":0.92,"y":0.904},{"x":1,"y":0.85}],"x":580,"y":760,"wires":[["e35665db7818a5bf"]]},{"id":"b5ec31986b77721e","type":"spline-curve","z":"43b31753070e19b0","name":"white evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.363,"y":0.29},{"x":1,"y":0}],"x":580,"y":800,"wires":[["e35665db7818a5bf"]]},{"id":"d461185209d0d5c5","type":"node-red-contrib-colorspace","z":"43b31753070e19b0","name":"","target":"payload","x":1260,"y":400,"wires":[["4eba4b2103bf1483"]]},{"id":"02edc8b9fbf90580","type":"change","z":"43b31753070e19b0","name":"rgb payload to convert","rules":[{"t":"set","p":"topic","pt":"msg","to":"rgb_color","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"{\t    \"rgb\": {\t        \"red\": payload[0].\"0\",\t        \"green\": payload[0].\"1\",\t        \"blue\": payload[0].\"2\"\t    }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":340,"wires":[["d461185209d0d5c5"]]},{"id":"2b1f7419.779bc4","type":"join","z":"43b31753070e19b0","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1070,"y":480,"wires":[["a7cfb606.aecfc"]]},{"id":"f6609b5cd420ca76","type":"function","z":"43b31753070e19b0","name":"Times of Day","func":"var newmsg = JSON.parse(JSON.stringify(msg));\nnewmsg.payload.times_of_day = {};\n\nconst processTimeOfDay = function(nme, obj, name_start, name_end) {\n    var ret = {};\n    ret.name  = nme;\n    ret.start = obj.times[name_start].ts;\n    ret.end   = obj.times[name_end].ts;\n    ret.perc  = (obj.ts - ret.start) / (ret.end - ret.start);\n    \n    \n    // to cover range starting before midnight and ending after it.\n    if (ret.start > ret.end)\n    {\n        var a;\n\n        // before midnight\n        if (ret.start < obj.ts) \n        {\n            a = new Date(ret.end);\n            a.setUTCDate(a.getUTCDate() + 1);\n            ret.end = a.getTime();\n             \n             \n        }\n        else if (ret.end > obj.ts) \n        {\n            a = new Date(ret.start);\n            a.setUTCDate(a.getUTCDate() - 1);\n            ret.start = a.getTime();\n\n        }\n\n    }\n    \n    ret.perc  = (obj.ts - ret.start) / (ret.end - ret.start);\n    \n    obj.times_of_day[nme] = ret;\n    if (ret.start <= obj.ts && obj.ts < ret.end ) obj.times_of_day.active = ret;\n}\n\nprocessTimeOfDay('night', newmsg.payload, \"blueHourDuskStart\", \"blueHourDawnEnd\");\nprocessTimeOfDay('morning', newmsg.payload, \"blueHourDawnEnd\", \"goldenHourDawnEnd\");\nprocessTimeOfDay('day', newmsg.payload, \"goldenHourDawnEnd\", \"goldenHourDuskStart\");\nprocessTimeOfDay('evening', newmsg.payload, \"goldenHourDuskStart\", \"blueHourDuskStart\");\n\nreturn newmsg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":170,"y":320,"wires":[["f0d97d577f05a92c"]]},{"id":"7b7d05b4b9f34f8b","type":"ha-sensor","z":"43b31753070e19b0","name":"Brightness","entityConfig":"6fe522b12d05f493","version":0,"state":"payload","stateType":"msg","attributes":[],"inputOverride":"block","outputProperties":[],"x":850,"y":160,"wires":[[]]},{"id":"4eba4b2103bf1483","type":"ha-sensor","z":"43b31753070e19b0","name":"Kelvin","entityConfig":"2cae8b2454f146ca","version":0,"state":"payload.temperature","stateType":"msg","attributes":[],"inputOverride":"block","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"x":1270,"y":460,"wires":[[]]},{"id":"798575a0e711f26e","type":"ha-sensor","z":"43b31753070e19b0","name":"White","entityConfig":"50c76bf3077ab54f","version":0,"state":"payload","stateType":"msg","attributes":[],"inputOverride":"block","outputProperties":[],"x":910,"y":620,"wires":[["2b1f7419.779bc4"]]},{"id":"77654077b21096c8","type":"function","z":"43b31753070e19b0","name":"Array to String","func":"const arr = msg.payload;\nconst myJSON = JSON.stringify(arr);\nmsg.payload = myJSON\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1240,"y":600,"wires":[["e1985b888f2d4735"]]},{"id":"e1985b888f2d4735","type":"ha-sensor","z":"43b31753070e19b0","name":"Aquarium RGBW","entityConfig":"874a3e4cd4ef8db7","version":0,"state":"payload","stateType":"msg","attributes":[],"inputOverride":"allow","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"x":1290,"y":660,"wires":[[]]},{"id":"ff16a2542e8d4193","type":"join","z":"43b31753070e19b0","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1070,"y":360,"wires":[["02edc8b9fbf90580"]]},{"id":"31826811.22a458","type":"position-config","name":"Home Location","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":"99","timeZoneDST":"0","stateTimeFormat":"3","stateDateFormat":"12"},{"id":"6fe522b12d05f493","type":"ha-entity-config","server":"c879ac61.99cd1","deviceConfig":"13be9f2f7ff837e4","name":"Aquarium Brightness","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Aquarium Brightness"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"2cae8b2454f146ca","type":"ha-entity-config","server":"c879ac61.99cd1","deviceConfig":"f69a208bb19d2c8d","name":"Aquarium Kelvin","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Aquarium Kelvin"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"50c76bf3077ab54f","type":"ha-entity-config","server":"c879ac61.99cd1","deviceConfig":"1212bb856f65626c","name":"Aquarium White","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Aquarium White"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"874a3e4cd4ef8db7","type":"ha-entity-config","server":"c879ac61.99cd1","deviceConfig":"4f4083b8e900272d","name":"Aquarium RGBW","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Aquarium RGBW"},{"property":"icon","value":"mdi:palette"},{"property":"entity_category","value":"config"},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":false,"debugEnabled":false},{"id":"c879ac61.99cd1","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"13be9f2f7ff837e4","type":"ha-device-config","name":"Aquarium Brightness","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""},{"id":"f69a208bb19d2c8d","type":"ha-device-config","name":"Aquarium Kelvin","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""},{"id":"1212bb856f65626c","type":"ha-device-config","name":"Aquarium White","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""},{"id":"4f4083b8e900272d","type":"ha-device-config","name":"Aquarium RGBW","hwVersion":"","manufacturer":"Node-RED","model":"H801 WiFi","swVersion":"ESPHome"}]

I am also using global variables but I also export those to sensors in HA and I use those sensors in templates in automations…

[{"id":"e812678d.651e28","type":"subflow","name":"Circadian Calculator","info":"","category":"time and astro","in":[{"x":80,"y":80,"wires":[{"id":"aa4b86d8.b17118"}]}],"out":[{"x":890,"y":100,"wires":[{"id":"40de744.1e2ca8c","port":0}]},{"x":890,"y":160,"wires":[{"id":"15b473ec45fa7fc4","port":0}]},{"x":930,"y":260,"wires":[{"id":"6f365d7d05905955","port":0}]},{"x":930,"y":320,"wires":[{"id":"c26bdcca.eb483","port":0}]}],"env":[],"meta":{},"color":"#FFCC66","inputLabels":["Trigger"],"outputLabels":["Brightness Value","Brightness Percent","Mireds","Kelvin"]},{"id":"5de89261.4fb97c","type":"switch","z":"e812678d.651e28","name":"curve switch","property":"payload.times_of_day.active.name","propertyType":"msg","rules":[{"t":"eq","v":"night","vt":"str"},{"t":"eq","v":"morning","vt":"str"},{"t":"eq","v":"day","vt":"str"},{"t":"eq","v":"evening","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":250,"y":220,"wires":[["ba17c1e6.e6f58","840431b7.eeefc"],["e5bb5a04.a33948","d4d99259.d0d7e"],["7c0f0774.90adf8","6ac1af7.dddb15"],["23b260f9.19f78","a907f5f4.0bf488"]]},{"id":"ba17c1e6.e6f58","type":"spline-curve","z":"e812678d.651e28","name":"night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.3},{"x":0.333,"y":0.037},{"x":0.477,"y":0},{"x":0.783,"y":0},{"x":1,"y":0}],"x":490,"y":80,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"e5bb5a04.a33948","type":"spline-curve","z":"e812678d.651e28","name":"morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.01},{"x":0.132,"y":0.01},{"x":0.269,"y":0.027},{"x":0.449,"y":0.124},{"x":0.676,"y":0.334},{"x":1,"y":0.75}],"x":500,"y":120,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"23b260f9.19f78","type":"spline-curve","z":"e812678d.651e28","name":"evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.036,"y":0.78},{"x":0.176,"y":0.63},{"x":1,"y":0.3}],"x":500,"y":200,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"7c0f0774.90adf8","type":"spline-curve","z":"e812678d.651e28","name":"daylight curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.744},{"x":0.03,"y":0.838},{"x":0.097,"y":0.941},{"x":0.183,"y":1},{"x":0.86,"y":0.995},{"x":0.943,"y":0.931},{"x":1,"y":0.85}],"x":500,"y":160,"wires":[["40de744.1e2ca8c","15b473ec45fa7fc4"]]},{"id":"840431b7.eeefc","type":"spline-curve","z":"e812678d.651e28","name":"night curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.5},{"x":0.067,"y":0.368},{"x":0.133,"y":0.265},{"x":0.27,"y":0.171},{"x":0.333,"y":0.16},{"x":0.506,"y":0.124},{"x":0.606,"y":0}],"x":490,"y":240,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"d4d99259.d0d7e","type":"spline-curve","z":"e812678d.651e28","name":"morning curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0},{"x":0.42,"y":0.018},{"x":0.54,"y":0.051},{"x":0.587,"y":0.101},{"x":0.817,"y":0.675},{"x":1,"y":0.85}],"x":500,"y":280,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"a907f5f4.0bf488","type":"spline-curve","z":"e812678d.651e28","name":"evening curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.787,"y":0.598},{"x":1,"y":0.5}],"x":500,"y":360,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"6ac1af7.dddb15","type":"spline-curve","z":"e812678d.651e28","name":"daylight curve","output_key":"","input_key":"payload.times_of_day.active.perc","points":[{"x":0,"y":0.85},{"x":0.123,"y":0.927},{"x":0.5,"y":1},{"x":0.92,"y":0.904},{"x":1,"y":0.85}],"x":500,"y":320,"wires":[["c26bdcca.eb483","6f365d7d05905955"]]},{"id":"40de744.1e2ca8c","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"1","maxout":"254","action":"clamp","round":true,"property":"payload","name":"","x":710,"y":100,"wires":[[]]},{"id":"c26bdcca.eb483","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"2700","maxout":"6500","action":"clamp","round":true,"property":"payload","name":"","x":730,"y":320,"wires":[[]]},{"id":"aa4b86d8.b17118","type":"sun-position","z":"e812678d.651e28","name":"","positionConfig":"31826811.22a458","rules":[],"onlyOnChange":"true","topic":"","outputs":1,"start":"","startType":"none","startOffset":0,"startOffsetType":"num","startOffsetMultiplier":60000,"end":"","endType":"none","endOffset":0,"endOffsetType":"num","endOffsetMultiplier":60000,"x":210,"y":80,"wires":[["717191f7a71b0df4"]]},{"id":"15b473ec45fa7fc4","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"1","maxout":"100","action":"clamp","round":true,"property":"payload","name":"","x":710,"y":160,"wires":[[]]},{"id":"6f365d7d05905955","type":"range","z":"e812678d.651e28","minin":"0","maxin":"1","minout":"370","maxout":"154","action":"clamp","round":true,"property":"payload","name":"","x":720,"y":260,"wires":[[]]},{"id":"717191f7a71b0df4","type":"function","z":"e812678d.651e28","name":"Times of Day","func":"var newmsg = JSON.parse(JSON.stringify(msg));\nnewmsg.payload.times_of_day = {};\n\nconst processTimeOfDay = function(nme, obj, name_start, name_end) {\n    var ret = {};\n    ret.name  = nme;\n    ret.start = obj.times[name_start].ts;\n    ret.end   = obj.times[name_end].ts;\n    ret.perc  = (obj.ts - ret.start) / (ret.end - ret.start);\n    \n    \n    // to cover range starting before midnight and ending after it.\n    if (ret.start > ret.end)\n    {\n        var a;\n\n        // before midnight\n        if (ret.start < obj.ts) \n        {\n            a = new Date(ret.end);\n            a.setUTCDate(a.getUTCDate() + 1);\n            ret.end = a.getTime();\n             \n             \n        }\n        else if (ret.end > obj.ts) \n        {\n            a = new Date(ret.start);\n            a.setUTCDate(a.getUTCDate() - 1);\n            ret.start = a.getTime();\n\n        }\n\n    }\n    \n    ret.perc  = (obj.ts - ret.start) / (ret.end - ret.start);\n    \n    obj.times_of_day[nme] = ret;\n    if (ret.start <= obj.ts && obj.ts < ret.end ) obj.times_of_day.active = ret;\n}\n\n\nprocessTimeOfDay('night', newmsg.payload, \"astronomicalDusk\", \"astronomicalDawn\");\nprocessTimeOfDay('morning', newmsg.payload, \"astronomicalDawn\", \"goldenHourDawnEnd\");\nprocessTimeOfDay('day', newmsg.payload, \"goldenHourDawnEnd\", \"sunsetStart\");\nprocessTimeOfDay('evening', newmsg.payload, \"sunsetStart\", \"astronomicalDusk\");\n\n\nreturn newmsg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":140,"wires":[["5de89261.4fb97c"]]},{"id":"31826811.22a458","type":"position-config","name":"Home Location","isValide":"true","longitude":"0","latitude":"0","angleType":"deg","timeZoneOffset":"99","timeZoneDST":"0","stateTimeFormat":"3","stateDateFormat":"12"},{"id":"365094a5.72bb5c","type":"subflow:e812678d.651e28","z":"7ea0620.a243ca","name":"","env":[],"x":480,"y":130,"wires":[["5f4a2fbe.d6b89"],["2bd57efd76cfcedf"],["eb1275669172038f","30bf6ebc.f4da52","e54896f13be9148d"],[]]},{"id":"a7bca137.c0d2f","type":"comment","z":"7ea0620.a243ca","name":"Update","info":"","x":90,"y":40,"wires":[]},{"id":"5f4a2fbe.d6b89","type":"function","z":"7ea0620.a243ca","name":"global brightness","func":"var new_brightness = (msg.payload == 254) ? 255 : msg.payload;\nif (new_brightness != global.get('nr_circadian_brightness')){\n    global.set('nr_circadian_brightness',new_brightness);\n//     return { payload: new_brightness }\n}\nreturn { payload: new_brightness }\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":40,"wires":[["2a30dc124d3af143"]]},{"id":"30bf6ebc.f4da52","type":"function","z":"7ea0620.a243ca","name":"global kelvin","func":"var new_kelvin = Math.round(1000000/msg.payload)\nif (new_kelvin != global.get('nr_circadian_kelvin')) {\n    global.set('nr_circadian_kelvin',new_kelvin);\n    return {payload: new_kelvin}\n    }\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":220,"wires":[["3c129db64c31287f"]]},{"id":"934e0600896a7adb","type":"link out","z":"7ea0620.a243ca","name":"Mireds","mode":"link","links":["43c2e1ab9d4c3a33","46442d133be6f963","9d3d2931ff09f30e","a52970d03d1f30a5","a897dbf21ffb2b4c"],"x":1195,"y":160,"wires":[]},{"id":"b1ee887a5f59e581","type":"link out","z":"7ea0620.a243ca","name":"Brightness","mode":"link","links":["e376d76995dda48c","4c8de271d9d32579","df433767e85260dc","3055458e27486427","4ccd12c7e9fa28f9","d72d56acc2f72b41","b1137e5488a33dda","ffa6896cb76348d5","19af89da0660a8f1","5c549b4f7506d662"],"x":1195,"y":40,"wires":[]},{"id":"eb1275669172038f","type":"function","z":"7ea0620.a243ca","name":"global mireds","func":"var new_mireds = msg.payload\nif (new_mireds != global.get('nr_circadian_mireds')) {\n    global.set('nr_circadian_mireds',new_mireds);\n    return {payload: new_mireds}\n    }\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":710,"y":160,"wires":[["720badcc22d0246e"]]},{"id":"2bd57efd76cfcedf","type":"function","z":"7ea0620.a243ca","name":"global brightness %","func":"var new_brightness_pct = msg.payload;\nif (new_brightness_pct != global.get('nr_circadian_brightness_pct')) {\n    global.set('nr_circadian_brightness_pct',new_brightness_pct);\n    return {payload: new_brightness_pct}\n    }","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":100,"wires":[["e2ac2146b3a99484"]]},{"id":"53a933a438c1326b","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"color_temp","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":160,"wires":[["934e0600896a7adb"]]},{"id":"ba7018086eca537b","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"brightness","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":40,"wires":[["b1ee887a5f59e581"]]},{"id":"f6a0b62593cc81c1","type":"interval-multiples-timer","z":"7ea0620.a243ca","interval":"60000","payload":"","topic":"","name":"Every minute","x":86,"y":120,"wires":[["f7382c3f63fec06f"]],"outputLabels":["timestamp"]},{"id":"b49e0a964008e7ba","type":"inject","z":"7ea0620.a243ca","name":"At startup","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"","payloadType":"date","x":96,"y":160,"wires":[["f7382c3f63fec06f"]]},{"id":"f7382c3f63fec06f","type":"api-current-state","z":"7ea0620.a243ca","name":"Circadian On?","server":"c879ac61.99cd1","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.circadian_lighting","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"date"}],"for":0,"forType":"num","forUnits":"minutes","x":280,"y":136,"wires":[["365094a5.72bb5c"],[]]},{"id":"3c129db64c31287f","type":"ha-sensor","z":"7ea0620.a243ca","name":"Kelvin","entityConfig":"f5e1d08b.a8cd58","version":0,"state":"nr_circadian_kelvin","stateType":"global","attributes":[],"inputOverride":"allow","outputProperties":[],"x":890,"y":220,"wires":[[]]},{"id":"720badcc22d0246e","type":"ha-sensor","z":"7ea0620.a243ca","name":"color_temp","entityConfig":"e80bd956.f2e098","version":0,"state":"nr_circadian_mireds","stateType":"global","attributes":[],"inputOverride":"allow","outputProperties":[],"x":910,"y":160,"wires":[["53a933a438c1326b"]]},{"id":"2a30dc124d3af143","type":"ha-sensor","z":"7ea0620.a243ca","name":"brightness","entityConfig":"476cda43.0f4c94","version":0,"state":"nr_circadian_brightness","stateType":"global","attributes":[],"inputOverride":"block","outputProperties":[],"x":910,"y":40,"wires":[["ba7018086eca537b"]]},{"id":"e2ac2146b3a99484","type":"ha-sensor","z":"7ea0620.a243ca","name":"brightness_pct","entityConfig":"5cd0d7153aaad741","version":0,"state":"nr_circadian_brightness_pct","stateType":"global","attributes":[],"inputOverride":"block","outputProperties":[],"x":920,"y":100,"wires":[[]]},{"id":"e54896f13be9148d","type":"function","z":"7ea0620.a243ca","name":"Kelvin to RGB","func":"var tmpKelvin = Math.round(1000000 / msg.payload)\n\nif (tmpKelvin < 1000) {tmpKelvin = 1000}\nif (tmpKelvin > 40000) {tmpKelvin = 40000}\ntmpKelvin = tmpKelvin / 100\n\n// First: red\nif (tmpKelvin <= 66)\n    { r = 255 }\nelse\n{\n    // Note: the R-squared value for this approximation is .988\n    var tmpCalc = tmpKelvin - 60\n    tmpCalc = 329.698727446 * (tmpCalc ^ -0.1332047592)\n    var r = Math.round(tmpCalc)\n    if (r < 0) {r = 0}\n    if (r > 255) {r = 255}\n}\n\n// Second: green\nif (tmpKelvin <= 66) \n{\n    // Note: the R-squared value for this approximation is .996\n    tmpCalc = tmpKelvin\n    tmpCalc = 99.4708025861 * Math.log(tmpCalc) - 161.1195681661\n    var g = Math.round(tmpCalc)\n    if (g < 0) {g = 0}\n    if (g > 255) {g = 255}\n} else\n{\n    // Note: the R-squared value for this approximation is .987\n    tmpCalc = tmpKelvin - 60\n    tmpCalc = 288.1221695283 * (tmpCalc ^ -0.0755148492)\n    g = Math.round(tmpCalc)\n    if (g < 0) { g = 0 }\n    if (g > 255) { g = 255 }\n}\n\n// Third: blue\nif (tmpKelvin >= 66)\n    { var b = 255 }\nelse if (tmpKelvin <= 19)\n    { b = 0 }\nelse \n    {\n    // Note: the R-squared value for this approximation is .998\n        tmpCalc = tmpKelvin - 10\n        tmpCalc = 138.5177312231 * Math.log(tmpCalc) - 305.0447927307\n    }\nb = Math.round(tmpCalc)\nif (b < 0) { b = 0 }\nif (b > 255) { b = 255 }\n\nif ([r,g,b] != global.get('nr_circadian_rgb')) {\n    global.set('nr_circadian_rgb', [r,g,b]);\n    return { payload: [r, g, b] }\n    }\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":280,"wires":[["412288630f9120b7"]]},{"id":"be1c8e1a66aec806","type":"change","z":"7ea0620.a243ca","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"rgb_color","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":280,"wires":[["eb72c612dcb6c962"]]},{"id":"eb72c612dcb6c962","type":"link out","z":"7ea0620.a243ca","name":"RGB","mode":"link","links":["c1cff865a0ee9d10"],"x":1195,"y":280,"wires":[]},{"id":"412288630f9120b7","type":"ha-sensor","z":"7ea0620.a243ca","name":"RGB","entityConfig":"10179c1c0d06ea3c","version":0,"state":" ","stateType":"str","attributes":[{"property":"rgb_color","value":"payload","valueType":"msg"}],"inputOverride":"allow","outputProperties":[],"x":890,"y":280,"wires":[["be1c8e1a66aec806"]]},{"id":"c879ac61.99cd1","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"f5e1d08b.a8cd58","type":"ha-entity-config","server":"c879ac61.99cd1","deviceConfig":"7e438167417be2db","name":"Circadian kelvin","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Circadian Kelvin"},{"property":"icon","value":"mdi:brightness-6"},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":"K"},{"property":"state_class","value":""}],"resend":true,"debugEnabled":false},{"id":"e80bd956.f2e098","type":"ha-entity-config","server":"c879ac61.99cd1","deviceConfig":"f5ff2695a5677b41","name":"Circadian color_temp","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Circadian color_temp"},{"property":"icon","value":"mdi:brightness-6"},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":true,"debugEnabled":false},{"id":"476cda43.0f4c94","type":"ha-entity-config","server":"c879ac61.99cd1","deviceConfig":"d03039723c3f87fe","name":"Circadian brightness","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Circadian Brightness"},{"property":"icon","value":"mdi:brightness-auto"},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":true,"debugEnabled":false},{"id":"5cd0d7153aaad741","type":"ha-entity-config","server":"c879ac61.99cd1","deviceConfig":"c260472dc44e142d","name":"Circadian brightness_pct","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Circadian Brightness %"},{"property":"icon","value":"mdi:brightness-percent"},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":"%"},{"property":"state_class","value":""}],"resend":true,"debugEnabled":false},{"id":"10179c1c0d06ea3c","type":"ha-entity-config","server":"c879ac61.99cd1","deviceConfig":"3619f11c08848aa5","name":"Circadian RGB","version":"6","entityType":"sensor","haConfig":[{"property":"name","value":"Circadian RGB"},{"property":"icon","value":""},{"property":"entity_category","value":""},{"property":"device_class","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""}],"resend":true,"debugEnabled":false},{"id":"7e438167417be2db","type":"ha-device-config","name":"nr_circadian_kelvin","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""},{"id":"f5ff2695a5677b41","type":"ha-device-config","name":"nr_circadian_color_temp","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""},{"id":"d03039723c3f87fe","type":"ha-device-config","name":"nr_circadian_brightness","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""},{"id":"c260472dc44e142d","type":"ha-device-config","name":"nr_circadian_brightness_pct","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""},{"id":"3619f11c08848aa5","type":"ha-device-config","name":"nr_circadian_rgb","hwVersion":"","manufacturer":"Node-RED","model":"","swVersion":""}]

alias: Automatic Lighting - Office
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.my_pc_is_active
    id: PC Active
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.office_occupancy
    id: Motion on
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.my_pc_is_active
    id: PC Idle
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: state
    entity_id:
      - binary_sensor.office_occupancy
    to: "off"
    id: Motion off
    for:
      seconds: "{{ states('input_number.office_lights_auto_off_time') }}"
condition: []
action:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: trigger
                id: PC Active
              - condition: trigger
                id: Motion on
        sequence:
          - if:
              - condition: not
                conditions:
                  - condition: state
                    entity_id: sensor.windows_11_monitorpowerstate
                    state: PowerOn
            then:
              - service: light.turn_on
                data: {}
                target:
                  entity_id: light.pc_monitor
          - if:
              - condition: state
                entity_id: light.office_lights
                state: "off"
            then:
              - service: light.turn_on
                data:
                  brightness: "{{ states('sensor.circadian_brightness') }}"
                  color_temp: "{{ states('sensor.circadian_color_temp') }}"
                target:
                  entity_id: light.office_lights
      - conditions:
          - condition: and
            conditions:
              - condition: state
                entity_id: binary_sensor.my_pc_is_active
                state: "off"
              - condition: state
                entity_id: binary_sensor.office_occupancy
                state: "off"
        sequence:
          - service: light.turn_off
            data: {}
            target:
              area_id: office
    default: []
mode: restart

First of all, thank you very much for this!! I’m having some issues with the “Who” subflow, specially the “auth” read file node, not sure what I should be setting mine to, I run HA on Unraid, docker.

I was about to comment that as long as you can provide read access to the auth file from HA to nodered you should be fine.
However it may not be wise security wise.
As the document is only used as a lookup table, if your users don’t change you may simply copy/paste the user blob in the function and remove the preceeeding nodes…