You mean Toggle service call toggles individual devices in group?
If so, this requires I believe a static definition for each group (I do not know automations in HA, I use AppDaemon). I have quite a lot of dynamism in my automations and keeping track of one entry per group would quickly be unmaintainable.
All this if i correctly understood the solution of course (if not I would be glad to learn how to make it a template for all groups of switches)