What does the HA node help text say about setting service and entity dynamically, can you copy the help text and paste here. If you are able to set service and entity dynamically then you should be able to use my flow.example. Is it possible to use mustache template in the service and entity inputs?
As in this example i set entities/devices in the change node. I added a template node to show how they can be set using mustache template, as i do not have HA.
[{"id":"fb404cdd59999e5d","type":"inject","z":"b7674213daf430ad","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"[true,true,false,false,true]","payloadType":"json","x":590,"y":220,"wires":[["577fe693aa471e6d"]]},{"id":"577fe693aa471e6d","type":"split","z":"b7674213daf430ad","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":750,"y":220,"wires":[["50f2beab50fdfd2e"]]},{"id":"3d6802f944e6197a","type":"inject","z":"b7674213daf430ad","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"[false,false,true,true,false]","payloadType":"json","x":590,"y":280,"wires":[["577fe693aa471e6d"]]},{"id":"50f2beab50fdfd2e","type":"switch","z":"b7674213daf430ad","name":"","property":"devices[msg.parts.index]","propertyType":"flow","rules":[{"t":"neq","v":"payload","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":830,"y":180,"wires":[["0101ea1687e187fa"]]},{"id":"0101ea1687e187fa","type":"change","z":"b7674213daf430ad","name":"","rules":[{"t":"set","p":"devices[msg.parts.index]","pt":"flow","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"$$.payload = true ? \"turn_on\" : \"turn_off\"","tot":"jsonata"},{"t":"set","p":"device","pt":"msg","to":"(\t$devices := [\"one\",\"two\",\"three\",\"four\",\"five\"];\t$devices[$$.parts.index]\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":220,"wires":[["ae9805f858649620"]]},{"id":"ae9805f858649620","type":"template","z":"b7674213daf430ad","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"service - {{payload}} \nentity - {{device}}","output":"str","x":880,"y":300,"wires":[["bde20f24c3bf64e0"]]},{"id":"bde20f24c3bf64e0","type":"debug","z":"b7674213daf430ad","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":300,"wires":[]}]
[edit] Added context storage of state, only changed states are forwarded.