Detecting power cycles

I’ve got a few esp tuya bulbs running esphome quite successfully.

These devices have a built in bootloader where you power cycles the bulb X times “fast enough” and it’s detected and goes to bootloader. This means there’s enough hardware support for the esp to stay running for xy milliseconds after power cut and can keep track of the number of power cuts that have happened recently.

Does esphome happen to support detection / reporting of this feature? I’d love it if could have the bulb come on “normally” when you first turn it on, but if you quickly power-cycle it (once, twice?) it does something separate like come on brighter etc.

maybe use uptime?

Interesting… But I’m pretty sure I’d need to know the uptime of the previous boot for this to fit what I’m trying to do, not sure it supports that?

Interesting. I know you can reset my Xiaomi bulbs by doing similar rapid toggling at the light switch.

When flashed with ESPHome does the device survive the rapid power cycles or does it go offline and reboot? Sounds like it reboots?

If it stays online, I wonder if the power cycles show up as a binary sensor on one of the gpio’s?

Do the devices use the ESPHome Tuya MCU? Did you check if it reports something on a “data point”?

I can’t really see how this could be exploited as a double press action etc if the esp reboots. I would have thought too much latency across a reboot?

What esphome does already internally is to check if the boot was “succesfull” - and when not in a series of (default) 10 attempts it will enter OTA safe mode. :arrows_counterclockwise:

maybe this function can be (ab)used to detect what you want? :thinking:

If you look the logs it will tell you right after booting this was the :x:th boot attempt