Automation, Is there a way to discover a group using templates?

I am trying to write a “generic” light switch which I hope to do the following with:
When button pressed work out the area/zone where the switch was switched
Using that information work out which light group covers that zone
establish if the light group is on or off and switch the group to the opposite state.
I can see some group status details etc, but I am struggling to find a way to locate a group in a zone.
I know I want a light group from a zone I have a zone ID for, but can not quite find a way to do this.
Any help is much appreciated.