For how long was the plug on?

Hi all!

I’m trying to sort some basic problem here with Home Assistant but I cannot seem to find a solution.

I have some anti mosquito plugs that needs refill every x hours, so my idea is to have Home assistant to turn them on and off as per a schedule and count the total amount of time they were on and send me a notification or even had to my shopping list the refill when the time has come.

Right now I’m struggling with the second step which is to count for how long each plug is on for in total.

Can anyone here point me in the right direction?

Hi, look at the history stat, for example:

- platform: history_stats
  name: Plex aan vandag
  entity_id: switch.lt_plex
  state: "on"
  type: time
  start: "{{ now().replace(hour=0, minute=0, second=0) }}"
  end: "{{ now() }}"

A bit out of the box, but could you use a utility meter helper?