It can be turned on via a HVAC → Pool Heat exchanger
And of course it can be turned on via a home assistant schedule, that also turns it off after 8 hours.
I also have a CT Clamp on the pool pump breaker. This feeds a binary_sensor - above 1000 watts the pump is on, below it’s off. The binary_sensor feeds a history_stats sensor.
Ideally, I’d like the “schedule” to be aware of the days runtime and run so that the max time is 8 hours in a 24hour period (time it takes to cycle the water).
EG:
If the kids turn the pool pump on for 1 hour
the heat exchanger turns it on for 4 hours
Then when the scheduled run starts, it will only run for 3 hours instead.
Or:
If the kids run it for 0
The heat exchanger runs it for 1
Then the scheduled run would be for 7 hours
I’m having trouble figuring out how to extract the “hours run in a 24 hour period” from the history_stats sensor.
Are you ok with 8 hours per calendar day (starting at midnight each day)? Or do you really need to look at the trailing 24 hour period? The latter would make for an extremely complicated problem.
Assuming calendar day is ok, are you wanting to trigger this automation at the latest point the day? So if it has ran for 5 hours total since 0:00, you’d trigger at 21:00 and run for 3 hours.
If all my assumptions are correct so far:
You need your history_stats sensor to calculate the hours of run time since midnight, so be sure it is set up like this:
sensor:
- platform: history_stats
name: Pool Pump ON today
entity_id: binary_sensor.my_pump
state: "on"
type: time
start: "{{ today_at() }}"
end: "{{ now() }}"
You could then do everything you needed in template triggers in an automation but to make it cleaner I would create a template sensor (you can do the from the helpers menu in the UI). This sensor would show the remaining run time needed today. You could call it “Pump time remaining today”:
You may also want another trigger to turn OFF the pump if someone (or some automation) leaves it on too long, and you can use a numeric state trigger for when sensor.pump_time_remaining_today crosses below zero.