Automation runtime based on Season

Hi All,

I’m pretty new at this but I’m learning, stuck with this problem, and I couldn’t find an example to use as a basis for my automation.

So, I have a pool pump that runs every day to turn over the water, and generate Chlorine (using a Chlorinator).

I need to adjust the runtime based on the time of year (it will prolly involve pool water temp in the future too). so I need the pump to run for:

6 hours in the Spring
8 hours in the Summer
6 hours in the Autumn
6 hours in the Winter

I have an automation that is working at the moment, but I have to adjust the time delay before pool turn off manually, so I created the following three automation’s, I have used a similar OR condition to that used in the Spring & Autumn automation in another routine for a light and it works, but not here.

Can anyone see an obvious error?
How would I get all of the three automations into a single block?

Thanks

Alan

- id: '1646643845828'
  alias: Pool Pump On Spring & Autumn  6 Hrs
  description: ''
  trigger: []
  condition:
  - condition: or
    conditions:
    - condition: state
      entity_id: sensor.season
      state: Spring
    - condition: state
      entity_id: sensor.season
      state: Autumn
  action:
  - service: homeassistant.turn_on
    data: {}
    target:
      device_id: 0732ac3b46a11b0a6718f1af93ae53dd
  - delay:
      hours: 6
      minutes: 0
      seconds: 0
      milliseconds: 0
  - service: homeassistant.turn_off
    data: {}
    target:
      device_id: 0732ac3b46a11b0a6718f1af93ae53dd
  mode: single
- id: '1646644237411'
  alias: Pool Pump on Summer 8 Hrs
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.season
  condition: []
  action:
  - service: homeassistant.turn_on
    data: {}
    target:
      device_id: 0732ac3b46a11b0a6718f1af93ae53dd
  - delay:
      hours: 8
      minutes: 0
      seconds: 0
      milliseconds: 0
  - service: homeassistant.turn_off
    data: {}
    target:
      device_id: 0732ac3b46a11b0a6718f1af93ae53dd
  mode: single
- id: '1646644452020'
  alias: Pool Pump On Winter 6 Hrs
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.season
  condition: []
  action:
  - service: homeassistant.turn_on
    data: {}
    target:
      device_id: 0732ac3b46a11b0a6718f1af93ae53dd
  - delay:
      hours: 4
      minutes: 0
      seconds: 0
      milliseconds: 0
  - service: homeassistant.turn_off
    data: {}
    target:
      device_id: 0732ac3b46a11b0a6718f1af93ae53dd
  mode: single

Triggering on the season is probably not what you want. It will trigger only 4 times per year…
Obviously, no trigger at all (trigger: []) means it will never be … triggered.

What would be the actual trigger? Time of the day?
Then use a Time Trigger

Assuming your automation is linked to the length of the day, rather than seasons you might want to use the actual sun

For the time being you are only triggereing when the season change or not triggering at all …
You have to trigger at a specific time every day. than in the actions, test which season you are to run the correct actions using choose in the automation…

  • trigger based on time of the day
  • no condition
  • action:
    • turn on the device
    • choose:
      -condition: season = summer
      sequence:
      - delay 8 hours
      - turn off
      default:
      - delay: 6 hours
      - turn off

I am running a pool + chlorinator based on the pool temperature and the month (running during the day between march and october and early in the morning during the winter…) So if your are interested in the future, let me know…

In addition to the advice you have received, I suggest you do not use a multi-hour delay action as a method of scheduling the turn-off time. If you execute Reload Automations or restart Home Assistant at any time during the delay, it is cancelled (and the pump won’t be turned off).

Let me know if you are interested in learning about a robust way to schedule the turn-off time.

Chris, Browet, Taras thanks for the pointers.

Schoolboy mistake only triggering the pool pump 4 times a year D’oh!

It’s obvious now that it’s been pointed out that I need to test to see what the current season is then run the pump based on the result.

The pump is triggered on 365 days at 11.00am (so that I can run other stuff beforehand know that my solar power generation isn’t going to be used up by multiple users all running at once) the pump run end time is varied by the automation.

I want to run the pump in the fat part of my power generation curve. not quite sure how the length of the day would fit into that scenario.

It hadn’t occured to me (like lots of things don’t apparantely) that if home assistant fell over or got restarted the pump could be left running, I’m definitely interested in guaranteeing that running devices stop when they were scheduled to.

I’ll correct my mistakes and have another go

Thanks again for the help

If you mean solar, you might want to have a look at

Disclaimer: not using solar myself…

Create a time-only input_datetime helper called input_datetime.pump_start.

Screenshot from 2022-03-07 11-50-25

In the Lovelace UI, set its value to the desired start time (11:00).
Screenshot from 2022-03-07 12-00-23

Create a Template Sensor called sensor.pump_stop whose device_class is timestamp. The template uses sensor.season to determine the pump’s duration (in hours) and adds it to the value of input_datetime.pump_start. The result is the time when the pump should stop.

template:
  - sensor:
    - name: Pump Stop
      device_class: timestamp
      state: >
        {% set hrs = {'Spring': 6, 'Summer': 8, 'Autumn': 6, 'Winter': 6}.get(states('sensor.season'), 6) %}
        {{ today_at(states('input_datetime.pump_start')) + timedelta(hours=hrs) }}

Now you have an input_datetime to set the pump’s start time and a timestamp sensor that automatically computes a seasonally-adjusted stop time.

The following automation controls the pump’s operation.

- id: scheduled_pool_pump
  alias: Scheduled Pool Pump
  trigger:
  - id: on
    platform: time
    at: input_datetime.pool_start
  - id: off
    platform: time
    at: sensor.pool_stop
  condition: []
  action:
  - service: 'homeassistant.turn_{{ trigger.id }}'
    target:
      device_id: 0732ac3b46a11b0a6718f1af93ae53dd

Restarting Home Assistant (or executing Reload Automations) won’t affect the pump’s scheduled operations (unless, of course, you restart exactly at the scheduled on/off times … and there are ways to mitigate that as well).

1 Like

Sorry about the delay, lots going on in my life right now, so Home automation has to take a back seat.

Anywhoo
Created some things:

 `input_datetime.pump_start`  (time only)

set the time at 11.00 (I can set the value manually, but should there be a dropdown? (I use 24 hour clock, not am pm))

template:
  - sensor:
      - name: "pump_stop"
        device_class: timestamp
        state: >
          {% set hrs = {'Spring': 6, 'Summer': 8, 'Autumn': 6, 'Winter': 6}.get(states('sensor.season'), 6) %}
          {{ today_at(states('input_datetime.pump_start')) + timedelta(hours=hrs) }}

I changed the name to pump_stop to create the sensor with that name

created the automation:

- id: "1648188605868"
  alias: Pool Pump Seasonal Schedule
  trigger:
    - id: "on"
      platform: time
      at: input_datetime.pump_start
    - id: "off"
      platform: time
      at: sensor.pump_stop
  condition: []
  action:
    - service: homeassistant.turn_{{ trigger.id }}
      target:
        device_id: 0732ac3b46a11b0a6718f1af93ae53dd

I think that the words pump and pool were getting mixed up (well I was anyway), so I used pump everywhere except in the automation name.

I think that I understand most of the code (apart from the state control for the pump_off) Its still not starting the pump, can’t figure out what I’m doing wrong.

OK, the problem was the season sensor.

Fixed that, with the sensor naming mods above it is now working!!!

Very pleased, and grateful for the help.

What was the problem?

I had a problem with some Shelly devices and the HA integration.

So I restored from a backup, that backup must have been taken before I added the Season sensor in my config file, so the automation couldn’t get a value for the sensor, therefore it wasn’t working.

I found out by going into developer tools, I was looking to make sure that a value had been set, but no sensor was present.

OK, I just wanted to confirm that what I had suggested didn’t contain errors and was functional.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.

Not working correctly yet.

input_datetime.pump_start  is currently set to 11:00:00  which is the value that I set it to.

sensor.pump_stop  is currently set to  2022-03-282022-03-28T09:00:00+00:00   

The pump is starting at 11.00, but not shutting off, the pump_stop sensor is visible in developer tools, but is the value above correct?
I can see that its todats date, but I don’t understend the ‘T09:00:00+00:00’ statement

The device_class for sensor.pump_stop is timestamp. It’s normal for a timestamp sensor to report time in UTC. Home Assistant will use your timezone offset to convert it to your local time.

I don’t know what is your timezone but 09:00 should represent the UTC equivalent of your local stop time (11:00 start time plus 6 hours for Spring equals 17:00 plus or minus whatever is your timezone offset).

Copy-paste this into the Template Editor. It should display the stop time in your timezone.

{{ states('sensor.pump_stop') | as_datetime | as_local }}

2022-03-28 17:00:00+08:00

I’m in Perth Western Australia which is UTC+8 hours so it’s correct. I wasn’t aware that the time was handled as UTC + offset, but it makes sense.

OK, good. The stop time (17:00 local time) is correct yet it failed to turn off the pump?

Check the automation’s trace and see what happened at 17:00.

It was sent the command to turn the pump off, so your script is working properly. (unsurprisingly)

There is definitely something else strange going on, the last entry in the log reports that the pump is on, but it isn’t.

The only automation currently enabled which is tallking to the pool pump, is the sheduled one that you showed to me. I modified the runtimes per season using the Studio code server.

The problem might be that the wifi signal is not consistent enough, and commands are being sent during dropouts, I’ll have to check the signal strength at the Shelly (1PM) which is controlling the pool pump, it’s a bit strange though because the pump consistently turns on.

Can’t think of anything else to check. I believe that its a hardware problem not software

I’ll do some checks tomorrow. Up for work early tomorrow.

What’s concerning are the log messages reporting “became unavailable”.

I interpreted that as the device losing its network connection.

To rule that issue out, I’m going to put the pool pump back onto its mechanical timer, and bring the Shelly controlled mains outlet inside the house and test it. Hopefully then I can determine whether its a connectivity issue.

I believe that it is because my pool pump is in a metal shed, I used EoP to create a wireless access point as close as poss to the shed, the automation triggers reliably, maybe there is something causing the dropouts (“became unavailable”).

I’ll do some tests

thanks for this, got most of it working except the turn_ {{ trigger.id }} part

this is the error i get

Error while executing automation automation.pool_pump_seasonal_schedule: Template rendered invalid service: homeassistant.turn_

any help greatly appreciated im running 2022.5.5 os 8.1