Definitely, an excellent and powerful way to do it. Here’s an option to do it using no custom code.
[{"id":"bac602d7.34282","type":"inject","z":"2802ff38.60d4c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":1408,"wires":[["74c0aa4e.973254"]]},{"id":"5a256649.5ced08","type":"debug","z":"2802ff38.60d4c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":738,"y":1408,"wires":[]},{"id":"ad4f2ae5.d6d918","type":"template","z":"2802ff38.60d4c","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.entity_id}}","output":"str","x":476,"y":1408,"wires":[["fad11fab.b7d29"]]},{"id":"fad11fab.b7d29","type":"join","z":"2802ff38.60d4c","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":610,"y":1408,"wires":[["5a256649.5ced08"]]},{"id":"74c0aa4e.973254","type":"ha-get-entities","z":"2802ff38.60d4c","server":"ef067c6f.620e6","name":"","rules":[{"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":310,"y":1408,"wires":[["ad4f2ae5.d6d918"]]}]