General method to target individual sleepy devices to inhibit sleep mode

Question for the wizards. I use sensors that I put into deep sleep most of the time. I’ve implemented a helper that sets a binary sensor to instruct the device to disable deep sleep so I can do ota updates. The problem is if I have 20 sensors Idon’t want to disable sleep for all of them when I set the disable sleep flag, and I’d like to avoid creating 20 individual helpers. Is there some way to create a generic method to target a device to inhibit sleep mode?

Maybe you could make a input select or input text in Home Assistant, and import that into your ESPHome devices as a Home Assistant Text Sensor, and check some conditions with that?

Maybe there’s something you can do with the device name?

I created a text helper in HA and each device has that as a text sensor and checks it for specific text, the ESPHome device’s friendly name, to see if it should disable sleep in a repeating polling script that launched on_boot . It works very well but the need to poll is “hacky”.

I’d rather have a binary sensor in each device that can be set from the HA device page to control sleep. I’m able to do that to enable sleep, but not disable sleep. There seems to be an issue with a sleepy device not being able to fetch that sensor value when it wakes up. I’ve tried all kinds of things in on_boot but ended up soft-bricking the device and having to perform a USB install with the device in boot
loader mode. Clearly, something is going on that I don’t understand.

Because deep sleep is so vital to using battery power devices efficiently, I think sleep control should be built into ESPHome and be part of each device HA device page