Bed presence % based on people at home

G’day there HASS Community!

Been using HASS since 2022.7 - a freshie!

Apologies if something like this has been asked before, but I couldn’t think of appropriate search terms seeing as I’m not entirely sure what I’m looking for would be called!

I’ve built Eoncire’s Bed Presence detection system and I’d like to create a sensor that outputs a number, similar to how the zone.home sensor works. Noone home = 0, 2 home = 2 etc.

Is it possible (if yes, how) to have the following outputs from a ‘virtual sensor’?
2 People Home, 2 People in bed = 100%
2 People Home, 1 Person in bed = 50%
1 Person Home, 1 Person in bed = 100%

My use case is I’d like to ‘shut the house down’ if 100% of people home are in bed, but if only 50% or 0%, turn things like water cooler & TV smart switches on, so that they have power on standby. My wife and I have very different work & sleep schedules, so I thought the above would be the best solution for this use case.

Thanks all!

You could use a template sensor to calculate the ratio. I’m assuming you have an entity that gives you the total number of people in bed, along the lines of what is described on the webpage I’m guessing you used.

{{ states('sensor.people_in_bed') | int(0) * 100 / states('zone.home') | int(0) 
    if states('zone.home') | int(0) > 0 else 0 }}

Nailed it! Thanks @michaelblight!