Pool pump Timer please save me arrrrrrr

It was as simple as you suggested. Thanks for picking that up, looking at the error now should have pointed me to that. Anyhow, its part of understanding the whole home assistant setup. Im a Copy Paste and hope it works type of guy right now as its all a bit overwhelming still. Thanks again.

1 Like

anyone got a fix for the broken automation after updates in hass.io especially this pool pump automation that now doesn’t work after upgrading hass.io

Will these HA pool timer automations survive a restart of Home Assistant? If the pool timer is set for 8hrs starting 1hr after sunrise and HA restarts at 0900, will the pump still stop after 8hrs?

As far as I understand @MyCool’s approach, the automation checks every minute if the pool pump is supposed to start or stop. If HA is not running at that exact minute, the start/stop tome would be missed, and the pool pimp would not start/stop until the next day.

In my approach, I check every 5 minutes if the pool pump is supposed to be on/off at that point in time, and stop/start accordingly. If HA is not running for a few minutes, the stop/start could be delayed by 5 minutes. However, I don’t check at night, so if HA is offline for longer, the pump may not stop until the next day.

Thanks. I’m convinced to use your custom component method for now but am investigating whether it is possible to do a similar 5m check with Node-Red and achieve a similar result as I’m working towards moving my automations to NR.

Thanks for the reply on your blog. Is it possible to remove all instances relating to multiple durations and have the pump start after sunset for just one duration (set by the input sliders)?

I guess if you don’t want the split run setup, you could vastly simplify the custom component code.
However, if you want to avoid too many code changes, the simplest solution would be to set all the breaks to zero.

OFF_SEASON_1ST_BREAK_MINUTES = 0
SWIMMING_SEASON_BREAK_1_MINUTES = 0
SWIMMING_SEASON_BREAK_2_MINUTES = 0

In the log file you would still see that multiple runs are being calculated but they would be back-to-back, and the pump should just continue running through.

That’s awesome, thank you. I’m playing with the idea of having something like this though.

- id: ID3
  alias: 'Check Pool Pump'
  trigger:
      - platform: time
        minutes: '/5'
        seconds: 00
  condition:
        - condition: time
          after: '08:00:00'
          before: '16:55:00'
        - condition: state
          entity_id: input_select.pool_pump
          state: Auto
  action:
      service: homeassistant.turn_on
      entity_id: switch.pool_pump

As I have fixed shut-off time in the ‘on season’ at 1700, I’d add an automation to turn the pump off at that time. For now, I tried my on, off and auto modes (your input select code), and it seems to work. If I turn the pump off then back to auto, within 5 minutes it turns it back on again. Would that not survive a home assistant restart?

Yes, that’s correct. That is working very well for me - as soon as it is set back to ‘Auto’ the next scheduled check will take the appropriate action.

Originally, I was hoping to implement my pool pump control in the form of an automation config. But my desire to run the pump in multiple scheduled runs per day and use solar electricity as much as possible led me to write this in Python where the maths around time and duration were much easier to implement.
If you just want to run the pump in one long time block, you can probably get away without the custom component and just automations to start and stop the pump.

Yep, managed to get it using just automations now and it looks like this.

image

1 Like

For those that want to achieve similar, my code below. I have a Sonoff in a waterproof box near the pool pump with a DS18B20 connected to GPIO14 (hard-wired) and using ESPEasy V2. There may be some unnecessary code in there but it seems to work. Sonoff is controlled by MQTT. I’ll be adding the pool LED lights soon!

- id: ID1
  alias: 'Pool Pump On'
  trigger:
      - platform: state
        entity_id: input_select.pool_pump
        to: 'On'
  action:
      service: homeassistant.turn_on
      entity_id: switch.pool_pump
- id: ID2
  alias: 'Pool Pump Off'
  trigger:
      - platform: state
        entity_id: input_select.pool_pump
        to: 'Off'
  action:
      service: homeassistant.turn_off
      entity_id: switch.pool_pump
## Checks pool pump status every few minutes defined by minutes: '/6' (6 minutes in this case)
## and as long as the Input slider is set to Auto, the swimming season has been turned on
## and it's between 0800 and 1655, it will turn the pump on. Designed without timers to
## survive HA restarts ##
- id: ID3
  alias: 'Check Pool Pump in Season'
  trigger:
      - platform: time
        minutes: '/6'
        seconds: 00
  condition:
        - condition: time
          after: '08:00:00'
          before: '16:55:00'
        - condition: state
          entity_id: input_select.pool_pump
          state: Auto
        - condition: state
          entity_id: input_boolean.swimming_season
          state: 'on'
  action:
      service: homeassistant.turn_on
      entity_id: switch.pool_pump
- id: ID4
  alias: 'Check Pool Pump off Season'
  trigger:
      - platform: time
        minutes: '/6'
        seconds: 00
  condition:
        - condition: time
          after: '08:00:00'
          before: '11:55:00'
        - condition: state
          entity_id: input_select.pool_pump
          state: Auto
        - condition: state
          entity_id: input_boolean.swimming_season
          state: 'off'
  action:
      service: homeassistant.turn_on
      entity_id: switch.pool_pump
- id: ID5
  alias: 'Pool Pump Off 1700'
  trigger:
    platform: time
    at: '17:00:00'
  condition:
    - condition: state
      entity_id: input_boolean.swimming_season
      state: 'on'
    - condition: state
      entity_id: input_select.pool_pump
      state: Auto
  action:
    service: homeassistant.turn_off
    entity_id: switch.pool_pump
- id: ID6
  alias: 'Pool Pump Off 1200'
  trigger:
    platform: time
    at: '12:00:00'
  condition:
    - condition: state
      entity_id: input_boolean.swimming_season
      state: 'off'
    - condition: state
      entity_id: input_select.pool_pump
      state: Auto
  action:
    service: homeassistant.turn_off
    entity_id: switch.pool_pump
1 Like

@exxamalte Any chance you could cast a glance over my ‘running’ code? All working except that the stats shows the time as a decimal instead of minutes and hours.

# Pool pump status icon as switch is hidden:
- platform: template
  sensors:
    pool_pump_status:
      value_template: '{% if is_state("switch.pool_pump", "on") %}Running{% else %}Stopped{% endif %}'
      friendly_name: 'Pool Pump Status'

- platform: history_stats
  name: Pool Pump running today
  entity_id: sensor.pool_pump_status
  state: 'Running'
  type: time
  start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  end: '{{ now() }}'

The decimal hour value is a bit awry, but I guess that’s how that sensor works. You could work around this by adding another template sensor. The time value is stored in an attribute of the history stats sensor, so your value template would look something like {{ states.sensor.pool_pump_running_today.attributes.value }}. And then you can hide the history stats sensor.

Thanks again. I’ll see if I can figure that out. Almost ready to deploy!!

Thanks, that worked!!

image

- platform: template
  sensors:
    pool_pump_time_on:
      value_template: '{{ states.sensor.pool_pump_running_today.attributes.value }}'
      friendly_name: 'Pool Pump Hours Running'
1 Like

@exxamalte Have you looked at using the season sensor?

Yes, I have thought about using this instead of a manual switch. I guess it depends on how close the actual ‘Summer’ season aligns with the swimming season where ones lives.
I live in Sydney, and I already noticed that the astronomical season setting does not really match the felt seasons, and thus switched to meteorological.

FYI, I have released a Swimmig Pool Automation System based on raspberry pi + HA

Is anyone avaialble to assist me with some changes ? I reinstalled my whole HA as I felt I needed to stop adding on from the many years of updates and start with the all new lovelace and GUI automations etc. Ive re-implemented the pool timer, but with the SONOFFs all imorting via MQTT integrations, they are all listed as lights and not switches, therefore breaking the service check as per automation action:

action:
service: homeassistant.turn_on
entity_id: switch.pool_pump

I cannot simply change the entity id to light.pool_pump as I receive an error when running the automation as I think there is some hard coded content in the ‘init.py’ custom component file.

Not sure how to best fix this ?

Futher on this, when I test calling the service from the developer tools I receive the below popup error:

Failed to call service pool_pump_service/check. ‘NoneType’ object has no attribute ‘lower’

In general, turning on and off switches and lights is pretty much interchangeable, but of course the code may make an assumption here or there that the entity is indeed a switch.
Is there a more detailed error message in the log file? This could point you to the line in the source code where an assumption fails.

Again, is there a more detailed error message in the log file? As I have mentioned on my blog I could only reproduce this particular error message with my custom component when the switch entity id was undefined. This may of course be related to your above mentioned issue with the light vs. switch.

BTW: In the meantime I have been working on a cleaner implementation of my custom pool pump component. You can find the source code here: home-assistant-customisations/pool-pump at master · exxamalte/home-assistant-customisations · GitHub