Schedule Pool Pump to turn on outside of loadshedding time

I installed a Sonoff POW R316 switch to turn on or off my pool pump. My idea was to integrate the pump into Home Assistant to create a schedule for the water pump and do it in a way to avoid load-shedding times here in South Africa. (South Africa has a thing called Load-Shedding, where the electricity gets turned on or off at a scheduled time.)

I integrated the Sonoff switch with SonoffLAN, through HACS.
I also integrated the load-shedding schedule with HA-Eskom-Loadshedding.

My plan is to create an automation with triggers for the times I want the pump to turn on, then I thought to maybe insert an if statement to check if the trigger time (in hours) is between load-shedding start time and end time, and if it is to change a boolean switch to later when the electricity turns back on, continue turning on the pump, by maybe using a when HA starts and the boolean is switched on. If the trigger time is not between the load-shedding start time and end time the pump should just continue turning on for one hour.

Some NB notes: We do not have solar or a battery solution, so if it is load-shedding our power is out. The load-shedding schedule from the integration shows up as a calendar entity, but I know too little of Home Assistant to know how to utilize it. Basically a lot of the elements I want to do and use I know too little of, but I would really want to learn from this. I am also currently going on vacation but will be back in two weeks to further try this automation.

Some pictures of the entities I have configureded:




Any help would be greatly appreciated!

I was looking to solve for the same problem (over the last week my pool went slightly murky from not having the filter on for long enough, loadshedding has been spot on when my pump usually runs)

Instead of looking at when loadshedding is I just set a number of hours the pump should run per day, then after sunrise I keep turning the pump on until the desired run time is met. If there is no power to the pump then runtime does not get added.

I created a variable to measure how long my pump had been on for the day using history_stats. Then created another variable that I could be as the setpoint for how many hours a day I want to pump to run, and added a numeric input box to the dashboard to that I can easily change that setpoint.

Added an automation that runs every 30s to check if the pump should be turned on, and another automation the check if the pump should be turned off.

So far so good - will see if any errors come through during load shedding when HA cannot find the pool switch (HA Pi is connected to an inverter)

added to configuration.yaml entry

sensor:

  • platform: history_stats
    name: pooltime
    entity_id: switch.sonoff_100091783d
    state: “on”
    type: time
    start: “{{ now().replace(hour=0, minute=0, second=0) }}”
    duration: “24:00”

input_number:
slider1:
name: Slider
initial: 30
min: -20
max: 35
step: 1
box1:
name: Numeric Input Box
initial: 8
min: 0
max: 12
step: 1
mode: box
icon: mdi:pump

#automations.yaml additions
alias: Pool pump on timer
description: "Turns the pool pump on if it has not run for a set time. \nRuns every
10min \nOnly starts after sunrise "
trigger:

  • platform: time_pattern
    seconds: /30
    condition:
  • condition: numeric_state
    entity_id: sensor.pooltime
    below: input_number.box1
  • condition: sun
    after: sunrise
    action:
  • type: turn_on
    device_id: xxxxxxxxxx(my device id)
    entity_id: switch.pool_pump
    domain: switch
    mode: single
  • id: ‘xxx’
    alias: 'Turn Off Pool Pump if over time ’
    description: "Turns the pool pump OFF if it has run for a set time. \nRuns every
    10min "
    trigger:
    • platform: time_pattern
      seconds: /30
      condition:
    • condition: numeric_state
      entity_id: sensor.pooltime
      above: input_number.box1
      action:
    • type: turn_off
      device_id: xxx(my device ID)
      entity_id: switch.pool_pump
      domain: switch
      mode: single

Hi Daniel,

Thanks for sharing this - I am going to try to implement this on my setup.

A question: in your code you refer to ID: ‘xxx’. What is that?

Oh that’s just whatever you put as the ID
It’s been running perfectly since I set it up, since then I have added geyser controllers and have the pump turning off when a geyser is on, this is 8n preparation for a solar inverter

@NevilleBailey

Ive got a sonoff POW R2 running my pump and light. I have a custom python script i found on these forums. The interface has a winter and summer mode and it runs when the sun is up. It runs regardless of time set.

It runs for the hours you set it and it meets those requirements.


H @NevilleBailey , do you have a link to the post or the can you paste the code?

Hey,

Sorry to dig up an old post but your integration seems nice and I’d like to use something similar.

Is this integration based on water temperature ?
Is this from this integration ? GitHub - oncleben31/ha-pool_pump: 🏊💻Pool pump manager for Home Assistant

Maybe from one of the forks ?