Pool pump Timer please save me arrrrrrr

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

Pretty sure you can define template device as switch.

Post config for the sonoff

EDIT
I was thinking of “device_class” but I think it only apply to sensor types.

Use template switch integration and make a proper switch

Thanks, I am trying all of the feedback received now.
@exxamalte, I am starting by implementing your cleaner version , thanks

I do need to figure out how to change the light to a switch as per the use of the code.
With the MQTT integration for the SONOFF and them all detected as lights, there is no .yaml includes specifying the lights, its all done in the integration. Ill attempt again, specifiying it with a include switch.yaml

Thanks for the replies, ill provide feedback on my success/failure shortly

So I Managed to get the Sonoff to import as a switch now instead of a light. I reset the Sonoff to factory and imported it straight away as switch. I can only think previous settings on the Sonoff in the console made changes to the import status prior. not sure, but anyhow, this has not resolved the service pool_pump check.

I can confirm that the switch works as it turns the pump on/off, the older component left no logs, the newer cleaner version by @exxamalte does leave logs.

Logged error:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py”, line 134, in handle_call_service
connection.context(msg),
File “/usr/src/homeassistant/homeassistant/core.py”, line 1232, in async_call
await asyncio.shield(self._execute_service(handler, service_call))
File “/usr/src/homeassistant/homeassistant/core.py”, line 1255, in _execute_service
await handler.func(service_call)
File “/config/custom_components/pool_pump_service/init.py”, line 83, in check
if await manager.is_water_level_critical():
File “/config/custom_components/pool_pump_service/init.py”, line 239, in is_water_level_critical
return entity_id and self._hass.states.get(entity_id).state == STATE_ON
AttributeError: ‘NoneType’ object has no attribute ‘state’

EDIT: Seems im missing this binary sensor ? binary_sensor.pool_water_level_critical?
I have added the below

pool_pump:
  switch_entity_id: switch.pool_pump
  pool_pump_mode_entity_id: input_select.pool_pump
  swimming_season_entity_id: input_boolean.swimming_season
  run_pool_pump_hours_swimming_season_entity_id: input_number.run_pool_pump_hours_swimming_season
  run_pool_pump_hours_off_season_entity_id: input_number.run_pool_pump_hours_off_season
  water_level_critical_entity_id: binary_sensor.pool_water_level_critical

into the configuration.yaml

Do you actually have a water level sensor binary_sensor.pool_water_level_critical? If not it should be possible to just remove that line from your configuration.

I feel like a complete idiot… like I ran 100 miles and tripped at the finish line…
dont think i need to explain more, all working … much appreciated. Thank you

1 Like

No worries.
Please also note that this new custom component generates a non-standard entity pool_pump.schedule that displays the next (or current) time period the pump is going to run.

Ahh Brilliant, that helps with a bit of guessing whether it should be running or not. Ive put it straight into use! lovely!

The latest HA update breaks the pool Schedule. I found a fix from another thread regarding a Strava plugin. If anyone wants a fix. Edit the custom_components\pool_pump_service\manifest.json

add a comma at the last line after codeowners and add a new line for version
“version”: “0.1”

see full example below

{
  "domain": "pool_pump",
  "name": "Pool Pump Manager",
  "requirements": [],
  "dependencies": [],
  "codeowners": ["@exxamalte"],
  "version": "0.1" 
}
1 Like

Could someone please give me a hand with setting this up?

Thanks! :slight_smile: homeassistant n00b

Did someone made a blueprint for the pool pump timer??