You have a binary_sensor, eg.
binary_sensor.tank_limiter_tank_pump_status, that gives you ‘on’ and ‘off’.
In this case, if a pump is running or not.
Create an input.number helper. f.e input_number.tank_pump_runtime
Then create 2 automations:
automation:
- id: reset_tank_pump_runtime
alias: "Reset Tank Pump Runtime on Pump Start"
trigger:
- platform: state
entity_id: binary_sensor.tank_limiter_tank_pump_status
to: 'on'
action:
- service: input_number.set_value
data:
entity_id: input_number.tank_pump_runtime
value: 0
mode: single
automation:
- id: tank_pump_runtime
alias: "Tank Pump Runtime"
description: "Increase input_number.tank_pump_runtime every second while binary_sensor.tank_limiter_tank_pump_status is 'on'"
trigger:
- platform: time_pattern
seconds: /1
condition:
- condition: state
entity_id: binary_sensor.tank_limiter_tank_pump_status
state: 'on'
action:
- service: input_number.increment
data:
entity_id: input_number.tank_pump_runtime
mode: single
This will give you a counter, which will count up every second of the runtime of this pump. As soon as the pump stops, the last count will stay visible in input_number.tank_pump_runtime.
As soon as the pump restarts, the stopwatch will be set on 0 seconds and the measuring of the runtime will be started again.