A "last time an event occured" sensor - how?

Hi, I’d like to have a sensor that would tell me when was the last time an electricity blackout occured. I have an APC UPS integrated via NUT. When a blackout occurs, sensor.ups_status_data changes from “OL” to “OL CHARG”.

How can I make a sensor that would show the time and date (or maybe even “a month ago”) of the last blackout? I’m not a programmer and templates go a bit over my head.

Thanks!

Hi @Stooovie
This can be done using an date time helper input

The idea here would be to create your own entity (with the input_datetime)
Then using automation triggered by sensor.ups_status_data changing state to set your newly created entity to “now()”

  - action: input_datetime.set_datetime
    data:
      datetime: "{{ now().timestamp() | timestamp_local }}"
    target:
      entity_id: input_datetime.your_freshly_created_helper
1 Like

Thank you, it does what I need.

1 Like