Hi all,
I just thought I would update this thread with my latest flow. This flow also averages out lux level from multiple sensors. My sensors are Philips Hue. Im using Hue Magic in Node Red to get the quickest possible readings from the sensors.
Prerequisites:
- Hue Magic palette installed and configured (not strictly required if your using HA native Hue integration however there will be a delay between the sensor changing and those values being fed back to HA - Hue Magic is virtually instant.
- Node Red Companion Component installed in HACS and then the integration enabled.
Once the ‘Entity Node’ is added to Node Red, a restart of Node Red is required. This is because Node Red then creates the new entity in HA.
This workflow creates an average lux value between all Hue motion sensors. The average lux is then stored to a variable. The variable only updates the new average sensor when all lights are off (this catches the age old problem of low lux, light comes on, lux value goes up, lights go off because lux is to high).
On motion, the workflow steps through its normal process of making sure the flow should turn on lights if the average of all lux sensors is below the threshold.
[{"id":"47f7d8d3.4386d8","type":"tab","label":"Downstairs Hall","disabled":false,"info":""},{"id":"f4802a18.263ca8","type":"comment","z":"47f7d8d3.4386d8","name":"Front Door Lux","info":"Store lux values when hall light is off","x":160,"y":700,"wires":[]},{"id":"f2c7b46c.b9daa8","type":"comment","z":"47f7d8d3.4386d8","name":"Turn off automation","info":"","x":250,"y":440,"wires":[]},{"id":"7a5c79f4.dc31f8","type":"server-state-changed","z":"47f7d8d3.4386d8","name":"Downstairs hall automation off","server":"9ee46d87.3f71d","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.downstairs_hall_automation","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":280,"y":480,"wires":[["816ce214.6d6ad"],[]]},{"id":"816ce214.6d6ad","type":"change","z":"47f7d8d3.4386d8","name":"Stop timer","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":550,"y":480,"wires":[["743f811e.aa8f"]]},{"id":"743f811e.aa8f","type":"link out","z":"47f7d8d3.4386d8","name":"Cancel Timer","links":["ffb00bfc.08da28","2ea7789b.b69f2"],"x":715,"y":480,"wires":[]},{"id":"5a8b0b60.559ab4","type":"comment","z":"47f7d8d3.4386d8","name":"Turn on automation","info":"","x":250,"y":540,"wires":[]},{"id":"661dca91.ec9164","type":"server-state-changed","z":"47f7d8d3.4386d8","name":"Downstairs hall automation on","server":"9ee46d87.3f71d","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.downstairs_hall_automation","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":280,"y":580,"wires":[["67a984b7.170ccc"],[]]},{"id":"67a984b7.170ccc","type":"link out","z":"47f7d8d3.4386d8","name":"Resume timer","links":["ffb00bfc.08da28","2ea7789b.b69f2","d48a7fa7.972"],"x":495,"y":580,"wires":[]},{"id":"19f6983d.eb356","type":"api-current-state","z":"47f7d8d3.4386d8","name":"light on?","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.downstairs_hall_lights","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1120,"y":200,"wires":[[],["8385cec7.df26c"]]},{"id":"517c4afd.4d4c94","type":"api-current-state","z":"47f7d8d3.4386d8","name":"All Away?","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.ha_mode_away","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":720,"y":200,"wires":[[],["96433344.43d7d8"]]},{"id":"96433344.43d7d8","type":"api-current-state","z":"47f7d8d3.4386d8","name":"Automation enabled?","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.downstairs_hall_automation","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":920,"y":200,"wires":[["19f6983d.eb356"],[]]},{"id":"2f9a2c23.81220c","type":"api-current-state","z":"47f7d8d3.4386d8","name":"Automation enabled?","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.downstairs_hall_automation","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1580,"y":460,"wires":[["f89d452a.b4a1b"],[]]},{"id":"fc1e6d9a.dd4ff8","type":"hue-motion","z":"47f7d8d3.4386d8","name":"Front Door Motion Sensor","bridge":"e81e9b.75df5168","sensorid":"116","skipevents":false,"x":270,"y":240,"wires":[["d5ae3276.9866e"]]},{"id":"d5ae3276.9866e","type":"change","z":"47f7d8d3.4386d8","name":"Motion","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.motion","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":300,"wires":[["ab6258cc.3d8448"]]},{"id":"ab6258cc.3d8448","type":"function","z":"47f7d8d3.4386d8","name":"Motion","func":"switch (msg.payload)\n{\n case false:\n msg.payload = \"OFF\";\n break;\n case true:\n msg.payload = \"ON\";\n break;\n default:\n break;\n}\nreturn msg;","outputs":1,"noerr":0,"x":560,"y":300,"wires":[["517c4afd.4d4c94","ed8d7089.c4f96"]]},{"id":"ed8d7089.c4f96","type":"trigger","z":"47f7d8d3.4386d8","op1":"","op2":"off","op1type":"nul","op2type":"str","duration":"30","extend":false,"units":"s","reset":"ON","bytopic":"all","name":"","x":730,"y":340,"wires":[["2f9a2c23.81220c"]]},{"id":"5c0c4f63.8b4cb8","type":"hue-bridge-node","z":"47f7d8d3.4386d8","name":"","bridge":"e81e9b.75df5168","autoupdates":true,"x":140,"y":180,"wires":[["fc1e6d9a.dd4ff8"]]},{"id":"b042e490.e6892","type":"hue-motion","z":"47f7d8d3.4386d8","name":"Downstairs Hall Morion Sensor","bridge":"e81e9b.75df5168","sensorid":"119","skipevents":false,"x":290,"y":360,"wires":[["d5ae3276.9866e"]]},{"id":"823173b7.27b67","type":"api-call-service","z":"47f7d8d3.4386d8","name":"ON","server":"9ee46d87.3f71d","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.downstairs_hall_lights","data":"{\"brightness_pct\":60,\"kelvin\":3200,\"transition\":0.1}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1790,"y":60,"wires":[[]]},{"id":"f2b15aa3.377d08","type":"api-current-state","z":"47f7d8d3.4386d8","name":"Evening?","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.ha_mode_evening","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1540,"y":60,"wires":[["823173b7.27b67"],[]]},{"id":"65a19ae5.e74a54","type":"api-current-state","z":"47f7d8d3.4386d8","name":"Midweek?","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.ha_mode_midweek","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1550,"y":120,"wires":[["91607cff.b855a8"],[]]},{"id":"c85452d1.3cad8","type":"api-current-state","z":"47f7d8d3.4386d8","name":"Midweek morning?","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.ha_mode_midweek_morning","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1570,"y":300,"wires":[["835c3a10.ce25"],[]]},{"id":"246625ce.3a1302","type":"api-current-state","z":"47f7d8d3.4386d8","name":"Weekend?","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.ha_mode_weekend","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1550,"y":180,"wires":[["91607cff.b855a8"],[]]},{"id":"8ef95740.c9056","type":"api-current-state","z":"47f7d8d3.4386d8","name":"Weekend morning?","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.ha_mode_weekend_morning","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1570,"y":240,"wires":[["e29d6c76.7b0b88"],[]]},{"id":"91607cff.b855a8","type":"api-call-service","z":"47f7d8d3.4386d8","name":"ON","server":"9ee46d87.3f71d","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.downstairs_hall_lights","data":"{\"brightness_pct\":100,\"kelvin\":3200,\"transition\":0.1}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1790,"y":140,"wires":[[]]},{"id":"e29d6c76.7b0b88","type":"api-call-service","z":"47f7d8d3.4386d8","name":"ON","server":"9ee46d87.3f71d","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.downstairs_hall_lights","data":"{\"brightness_pct\":50,\"kelvin\":3200,\"transition\":0.1}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1790,"y":240,"wires":[[]]},{"id":"aa889a4e.d6b8","type":"api-current-state","z":"47f7d8d3.4386d8","name":"Night??","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.ha_mode_night","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1540,"y":360,"wires":[["835c3a10.ce25"],[]]},{"id":"835c3a10.ce25","type":"api-call-service","z":"47f7d8d3.4386d8","name":"ON","server":"9ee46d87.3f71d","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.downstairs_hall_lights","data":"{\"brightness_pct\":10,\"kelvin\":3200,\"transition\":0.1}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1790,"y":320,"wires":[[]]},{"id":"f89d452a.b4a1b","type":"api-call-service","z":"47f7d8d3.4386d8","name":"OFF","server":"9ee46d87.3f71d","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.downstairs_hall_lights","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1790,"y":460,"wires":[[]]},{"id":"2ea7789b.b69f2","type":"link in","z":"47f7d8d3.4386d8","name":"Downstairs hall continued","links":["67a984b7.170ccc","743f811e.aa8f"],"x":606,"y":380,"wires":[["ed8d7089.c4f96"]]},{"id":"8926c811.c4378","type":"change","z":"47f7d8d3.4386d8","name":"Set lux variable","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.lux","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":740,"wires":[["69a2a435.b929e4"]]},{"id":"add50a7.89cb0f8","type":"hue-brightness","z":"47f7d8d3.4386d8","name":"Front Door","bridge":"e81e9b.75df5168","sensorid":"117","skipevents":false,"x":140,"y":740,"wires":[["8926c811.c4378"]]},{"id":"998026d4.d93298","type":"api-current-state","z":"47f7d8d3.4386d8","name":"Hall lights off?","server":"9ee46d87.3f71d","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.downstairs_hall_lights","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":900,"y":800,"wires":[["df9da15e.49c67"],[]]},{"id":"87947e4.30b3f","type":"switch","z":"47f7d8d3.4386d8","name":"Lux threshold 30 or less","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"30","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1670,"y":800,"wires":[["545316f.dc4c268"],["d6fc1a7.89ddae8"]]},{"id":"545316f.dc4c268","type":"change","z":"47f7d8d3.4386d8","name":"Enable light","rules":[{"t":"set","p":"light_enabled","pt":"flow","to":"yes","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1890,"y":780,"wires":[["fe139faa.e5d838"]]},{"id":"d6fc1a7.89ddae8","type":"change","z":"47f7d8d3.4386d8","name":"Disable light","rules":[{"t":"set","p":"light_enabled","pt":"flow","to":"no","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1890,"y":820,"wires":[["a0e2887b.f59c28"]]},{"id":"fe139faa.e5d838","type":"debug","z":"47f7d8d3.4386d8","name":"Enable Light","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":2080,"y":780,"wires":[]},{"id":"a0e2887b.f59c28","type":"debug","z":"47f7d8d3.4386d8","name":"Disable light","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":2082,"y":820,"wires":[]},{"id":"8385cec7.df26c","type":"switch","z":"47f7d8d3.4386d8","name":"Light enabled?","property":"light_enabled","propertyType":"flow","rules":[{"t":"eq","v":"yes","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1300,"y":200,"wires":[["f2b15aa3.377d08","65a19ae5.e74a54","246625ce.3a1302","8ef95740.c9056","c85452d1.3cad8","aa889a4e.d6b8"]]},{"id":"320ef1a1.5d188e","type":"comment","z":"47f7d8d3.4386d8","name":"Downstairs Hall Lux","info":"Store lux values when hall light is off","x":170,"y":820,"wires":[]},{"id":"e0059f.49a4426","type":"change","z":"47f7d8d3.4386d8","name":"Set lux variable","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.lux","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":860,"wires":[["69a2a435.b929e4"]]},{"id":"bdfc4ae9.9538b","type":"hue-brightness","z":"47f7d8d3.4386d8","name":"D Hall","bridge":"e81e9b.75df5168","sensorid":"120","skipevents":false,"x":130,"y":860,"wires":[["e0059f.49a4426"]]},{"id":"69a2a435.b929e4","type":"smooth","z":"47f7d8d3.4386d8","name":"average","property":"payload","action":"mean","count":"2","round":"1","mult":"single","reduce":false,"x":480,"y":800,"wires":[["57faa830.c8753"]]},{"id":"57faa830.c8753","type":"change","z":"47f7d8d3.4386d8","name":"Set average variable","rules":[{"t":"set","p":"dhaverage","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":800,"wires":[["998026d4.d93298"]]},{"id":"df9da15e.49c67","type":"change","z":"47f7d8d3.4386d8","name":"Payload back to variable","rules":[{"t":"set","p":"payload","pt":"msg","to":"dhaverage","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":800,"wires":[["6c6d12a6.86a514"]]},{"id":"6c6d12a6.86a514","type":"ha-entity","z":"47f7d8d3.4386d8","name":"Downstairs Hall Average","server":"9ee46d87.3f71d","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"downstairs_hall_average"},{"property":"device_class","value":""},{"property":"icon","value":"weather-sunny"},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":1390,"y":800,"wires":[["87947e4.30b3f"]]},{"id":"9ee46d87.3f71d","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"e81e9b.75df5168","type":"hue-bridge","z":"","name":"Philips hue","bridge":"192.168.1.5","key":"bzebqVHBEwYSOrxKTGL1Rk2rdHI3O3r3hsatCvJF","interval":"500","disableupdates":false}]