I’ve just switched power companies and I’m now on two tiers, off-peak 1100-1700 and 2100-0700 Mon to Friday and all weekend. To leverage the cheap power, I want to tweak my automation below so I always get 8 hours of pool pump operation but only between the off-peak hours.
Anyone know how to modify my scripts to check for those time and days?
- alias: 'Check Pool Pump in Season'
initial_state: true
hide_entity: true
trigger:
- platform: time_pattern
minutes: '/2'
# seconds: 00
condition:
- condition: time
after: '11: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'
- alias: 'Pool Pump Off 1700'
initial_state: true
hide_entity: true
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
i know its a minor curveball but do you have solar?
it’s worth maximising solar export pool pump time as you get to heat the pool for free that way too.
you can have nested conditions with and’s and or’s
so you could have an OR condition containing 2 ANDs
one of the ANDs would be
condition: time (weekday)
condition: day (weekday)
and the other
condition: time (weekend)
condition: day (weekend)
Thank you, I had looked at that but I was looking for something a bit smarter.
Mon-Friday, I need to start at 1100 but stop at 1700 then restart at 2100 for the last 2hrs of pumping (total 8hrs). However, Saturday and Sunday I can resume normal scheduling and use 0900 - 1700. Looking for a way to weave those on/off statements into one or two automations.
So as I’m tracking the on time of the input_boolean, all I need now is a trigger template that reads the hours/minutes and after 08:00 of on time, I can turn off the device. Anyone help with that template?
No, as that won’t survive Home Assistant restarts or account for any times when I do filter maintenance and turn the pump on and off manually for a few minutes. Needs to track total time on for the day and turn off after a total on time of 8hrs 0 minutes.
- alias: 'Fake Pool Pump Off'
initial_state: true
hide_entity: true
trigger:
- platform: time_pattern
minutes: '/5'
# seconds: 00
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.fake_pool_pump
state: 'on'
- condition: template
value_template: "{{ states('sensor.fake_pool_pump_running_today') | float > 8.00 }}"
- condition: or
conditions:
- condition: time
after: '17:00:00'
before: '23:15:00'
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: time
after: '17:00:00'
before: '18:00:00'
weekday:
- sat
- sun
action:
service: input_boolean.turn_off
entity_id: input_boolean.fake_pool_pump
I can’t use the sensor.fake_pool_pump_running_today as a trigger I believe at there is no state change so I’m checking every 5 minutes around the times when it should have been running for 8hrs (8.00). the problem with that methodology is there is a possibility that the time window could get missed if I accidentally turn the pump off and then its short on hours for the day when it starts up. It will never get a pump off command.
I ideally need a time based trigger that is creating a state change when "{{ states('sensor.pool_pump_running_today') | float > 8.00 }}" reports true. Is that possible? Can I create a sensor to do that?
You can move that template from the binary sensor to the trigger if you don’t want that sensor for other uses. This allows you to update it easier as you can reload automations versus restarting for sensor updates.
I’ve added a condition into the start timer to ensure that the pump does not start again within the time window if it’s already been on for 8hrs and we are good to go.
###################################
## Automations
###################################
automation:
- alias: 'Pool Pump on Test'
initial_state: true
hide_entity: true
trigger:
- platform: time_pattern
minutes: '/2'
# seconds: 00
condition:
condition: and
conditions:
#''and' condition to check all states are true and will only proceed if all are true #
- condition: state
entity_id: input_select.pool_pump
state: Auto
- condition: state
entity_id: input_boolean.swimming_season
state: 'on'
- condition: numeric_state
entity_id: sensor.fake_pool_pump_running_today
below: 8.00
# The 'or' conditions check if 'any' of the stated times are relevant and proceeds if any are #
# Opened the time windows for off-peak hours #
- condition: or
conditions:
- condition: time
after: '11:00:00'
before: '16:58:00'
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: time
after: '21:00:00'
before: '22:58:00'
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: time
after: '09:00:00'
before: '18:58:00'
weekday:
- sat
- sun
action:
service: input_boolean.turn_on
entity_id: input_boolean.fake_pool_pump
- alias: 'Fake Pool Pump Off'
initial_state: true
hide_entity: true
trigger:
trigger:
- platform: numeric_state
entity_id: sensor.fake_pool_pump_running_today
above: 8.00
condition:
- condition: state
entity_id: input_boolean.fake_pool_pump
state: 'on'
action:
service: input_boolean.turn_off
entity_id: input_boolean.fake_pool_pump
You can probably simplify it a bit more by changing your trigger in the turn on automation.
If you only want runtime of 8 hours a day you can always use the daily window from 21:00 to 7:00
So you could trigger to turn on at 21:00 with your condition on the runtime and the booleans you have.
Then use the turn off automation to turn it off as you are when runtime is over 8 hours.
You could also use an input_number for the 8 hours so your runtime is exposed in the web gui if you want to bump that up over the season (here in MD we run runs longer in the hot season versus cool).
Please be mindful of typos below, not done in a YAML editor.
trigger:
- platform: time
at: "21:05:00"
condition:
- condition: state
entity_id: input_select.pool_pump
state: Auto
- condition: state
entity_id: input_boolean.swimming_season
state: 'on'
- condition: numeric_state
entity_id: sensor.fake_pool_pump_running_today
below: 8.00
action:
....turn on pump.....
I created a ‘time to run’ sensor and put a condition in the pump start routine that ‘time to run’ had to be above 0.
the benefit of this approach is an easily displaying how long in a given day the pump has been on.
probably not essential in your exact setup but if you’re triggering the pool pump using solar production its handy to know the trending run-time to avoid random swampiness.
Thanks Jon and apologies for the delayed reply. I have to have specific start and stop times defined so the pool pump operates around the off-peak power rates. It’s all working a treat now with Mon-Fri 6hrs during the day and 2hrs at night and at the weekend, it returns to normal 0900-1700 as all weekend is all off-peak. First power bill using this methodology is the lowest I’ve ever had. Now to tackle the hot water cylinder!!
I’m now wanting to extend this further and tidy it up a bit. I’ve realised I have a sensor called sensor.power_rate that is either peak or offpeak so I could use that to define when the pump starts? That would remove the necessity for all of the time conditions.
But how would I get the pump to start at 0900 everyday but only if the the power rate was offpeak whilst waiting for the power to change to offpeak if it was peak at 0900 (weekdays)? Furthermore, it would need to stop when the rate changed at 1700 to peak and again wait until the rate change back to offpeak at 2100 and then finally finish for the day when sensor.pool_pump_running_today was > 8.00.
Anyone got a clue on how to roll that all together?
I would approach this with an automation using a time_pattern trigger that runs every 5 minutes between 9am and nighttime.
And then you could implement a templated action that distinguishes two cases:
If offpeak and pool_pump_running_today < 8: turn pump on
Any idea on whether I can combine everything into one service_template inside an action?
{% if is_state('light.shelly_dimmer_kitchen' , 'on') and ('light.shelly_dimmer_lounge' , 'on')%}
yes
{% else %}
no
{% endif %}
I’m testing with two lights I can easily turn on and off to validate the template but in the scenario above, I get a yes with only one light on so the and is not working.
I already have a time pattern trigger so start the automation so I’d continue with this with one condition that it was after 0900 then an action that tests the and condition and either turns on or off the pump.