How do I know how long the power has been out?

Hello. I’m new to HA and hoping someone can help me out. I’m trying to keep power outage statistics by keeping track of the active state of my Raspberry Pi (where the HA is installed). I use sensor.uptime for this, it takes into account when the HA went offline and turned back on, and also displays the time the HA has been continuously running. But I need to know how long the power was out. Maybe there is a way to see the difference between powered off and powered on and add that information to the card in the notification?

I am not sure if this is useful to you
here

How about

  • Pick a device that is always plugged into power, like a switchable power outlet, etc. During a power outage all devices with static power supplies will record as ‘unavailable’ with a correct status once power is back.
  • If you happen to have a connected UPS (larger APC models (1kVA and up usually have a data-port HA can connect to via USB) you can check when the UPS switched into battery mode and when back to line-power mode.