Add More Complex Logic to Pool Pump Timer Automation

I have two simple automations to turn my pool on and off. One turns on at sunrise and another turns off at 3 PM. This works well for simple time-of-year runtime adjustment. It runs longer in the summer, and shorter in the winter.

I’m in an area that’s affected by moderately strong winds occasionally. I have a weather station on the roof that can accurately measure wind speed and gusts. I’m trying to find a way to use wind speed and duration to “add” runtime to the pool pump.

The first challenge is the inconsistency of windspeeds, which will oscillate between say 3 and 12mph for a few hours, so my first problem is how to create and tune threshold sensors that differentiate between “windy” and “not_windy”.

The second half of the logic equation is “if it’s windy, run the pump continuously” then “when switching from ‘windy’ to ‘not_windy’ start a 3 hour timer then turn off”. This part I could probably figure out.

Something I want to be careful to avoid is long running timers as HA restarts disrupt them.

I’m looking for some suggestions. Thanks!

description: ""
mode: single
triggers:
  - event: sunrise
    trigger: sun
conditions: []
actions:
  - data: {}
    target:
      entity_id: switch.pentair_pool
    action: switch.turn_on
alias: Pool Pump - Off
description: ""
mode: single
triggers:
  - at: "15:00:00"
    trigger: time
conditions: []
actions:
  - data: {}
    target:
      entity_id: switch.pentair_pool
    action: switch.turn_off

You can probably use a history_stats sensor to count how long the wind was above 3mph or 10mph or 15mph - or all of them.

You then start a timer at 3:01PM and run it for a pre-calculated/variable time based on some algorithms that use the history_stats results - the pump then gets turned off when the timer expires.

Timers are not impacted by HA restarts but wait/delay actions are.

If you don’t want to stop and restart the pump you can add a condition for the stop action of the pump and only stop it when the timer that you started in a separate automation at 3:00PM is larger than 0 minutes.

I’s also recommend turning the pump off at a backstop time, e.g. 6:00PM so that it doesn’t run all night, if something else happens.

Or you can get really fancy and merge all this into one automation and run the respective actions based on a Trigger ID for each trigger, i.e. sunrise, 3:00PM, timer expiry, etc.