Sensor for percentage of unavailable devices?

Hey Everyone!

I would like to set up a sensor that would detect if a percentage of a group of devices are “unavailable” so that I can determine if there is a possible system power outage. While my Home Assistant Raspberry Pi and core network equipment are sitting on battery backups, I have a large variety of light bulbs, smart plugs, light switches, and other devices that would suddenly become unavailable during a power outage.

Since any device (ex. a lightbulb) or subset of devices (ex. all Zigbee devices since the Zigbee controller is down) could be unavailable, I would like the sensor to say when more than 75% of [this group] of devices become “unavailable” at the same time, “sensor.outage” goes to “yes”.

CHALLENGE: Is there a way to set up a sensor to change value based on the count of devices with a certain status in a group of devices?

I could then reuse that functionality for other purposes, such as determining if the Zigbee controller is malfunctioning because a large number of Zigbee devices are unavailable even though the Zigbee controller is on and responding to ping.

Thanks for your help!!