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
@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.
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.
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:
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.
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
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
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.
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”