Nodered home assistant challenge

Tags: #<Tag:0x00007f77fd9e4518>

I have a number of lights inside and outside my house that is integrated to home assistant. I am looking for a different aspect with turning all these lights on. i have created a group to switch on all the lights and it works perfectly but the problem is with switching off. During night time some of the lights will already be ON when i toggle group on switch but when i switch off its turns off all the lights including ones which were previously on too. that is not good. so can anybody suggest me a mechanism which would only switch off lights that was in off condition during when the group on switch was activated, leaving rest on.

can anybody help me build a nodered flow which will when on calling an input Boolean on will trigger all lights on and when the same input Boolean is called off will only switch off lights which was having previous state as Off.

Inspiration for a solution can be found here:

You’ll want to make use of status checks to do this.

I have a similar situation with a HDMI splitter and did the following:

Yours will be much more complicated.

Something Else I’ve done is “Turn Off” only clicks on my Xiaomi switches. A long hold turns off all lights no matter their status.

It’s actually relative pretty straight forward.

When the input boolean is turned on use get-entities to record the entities in a certain group with state equal to off and save it to a flow variable. Then when it’s turned off grab the saved states and format the ids to pass to the call-service node.

[{"id":"37ed5605.3d760a","type":"server-state-changed","z":"5eb3594f.d294b8","name":"event","server":"ef067c6f.620e6","entityidfilter":"input_boolean.lights","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is_not","outputs":2,"output_only_on_state_change":true,"x":306,"y":1312,"wires":[["3f113a71.c64756"],["85ae5169.065e1"]]},{"id":"4283af5d.5a84c","type":"api-call-service","z":"5eb3594f.d294b8","name":"","server":"ef067c6f.620e6","service_domain":"homeassistant","service":"turn_on","data":"{\"entity_id\":\"group.lights\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":664,"y":1296,"wires":[[]]},{"id":"3f113a71.c64756","type":"ha-get-entities","z":"5eb3594f.d294b8","server":"ef067c6f.620e6","name":"","rules":[{"property":"entity_id","logic":"in_group","value":"group.lights","valueType":"str"},{"property":"state","logic":"is","value":"off","valueType":"str"}],"output_type":"array","output_empty_results":true,"output_location_type":"flow","output_location":"stateOfLights","output_results_count":1,"x":454,"y":1296,"wires":[["4283af5d.5a84c"]]},{"id":"1a2025e6.4f8dba","type":"split","z":"5eb3594f.d294b8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":642,"y":1344,"wires":[["8f8474ef.413728"]]},{"id":"85ae5169.065e1","type":"change","z":"5eb3594f.d294b8","name":"Get stateOfLights","rules":[{"t":"set","p":"payload","pt":"msg","to":"stateOfLights","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":474,"y":1344,"wires":[["1a2025e6.4f8dba"]]},{"id":"8f8474ef.413728","type":"template","z":"5eb3594f.d294b8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.entity_id}}","output":"str","x":780,"y":1344,"wires":[["e4f4cc9d.4827a"]]},{"id":"e4f4cc9d.4827a","type":"join","z":"5eb3594f.d294b8","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":914,"y":1344,"wires":[["fdfd7b2d.1df038"]]},{"id":"fdfd7b2d.1df038","type":"api-call-service","z":"5eb3594f.d294b8","name":"","server":"ef067c6f.620e6","service_domain":"homeassistant","service":"turn_off","data":"{\"entity_id\":\"{{payload}}\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":1112,"y":1344,"wires":[[]]}]