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":[[]]}]