Create a sensor that is a stopwatch of the state of another sensor

How do I create a sensor that is a stopwatch of the state of another sensor?

I have a pool pump and I want it to run for 8hours a day. there are various conditions for it to be on or off, including electricity price. I need a counter of time placed on the pump status, so I can use that output as an additional condition in an automation.

I’d recommend History Stats sensor.

sensor:
  - platform: history_stats
    name: Pump ON today
    entity_id: binary_sensor.pool_pump_running
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"
2 Likes

how do you get the lovelace card to display in time format? currently mine says 2.8Hrs which is fine, but prefer 2:48

1 Like

I’ve created a stopwatch. Maybe it can be useful for you.

https://community.home-assistant.io/t/stopwatch-with-start-stop-resume-lap-and-reset/443994

1 Like

Maybe you can find this useful:
https://community.home-assistant.io/t/stopwatch-with-start-stop-resume-lap-and-reset/443994