Automation runtime based on Season

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

I have this implemented, pump comes on at right time but the stop time does not work unless i manually set the start time everyday? any ideas why?

Post your automation and template sensor configuration.

template:

  • sensor:
    • name: Pump Stop
      device_class: timestamp
      state: >
      {% set hrs = {‘spring’: 5, ‘summer’: 5, ‘autumn’: 2, ‘winter’: 2}.get(states(‘sensor.season’), 5) %}
      {{ today_at(states(‘input_datetime.pump_start’)) + timedelta(hours=hrs) }}
alias: Pool Pump Seasonal Schedule
description: ''
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 }}
    data: {}
    target:
      entity_id: switch.sonoff_1000c301b9
  - service: notify.mobile_app_sm_n986b
    data:
      message: Pool Pump {{ trigger.id }}
mode: single

created the pump start input helper, and the pump stop template as suggested

I know this post i pretty old but i just moved to HA and i am thrilled by it and therefore i’m happy to share.

Here is my swimming-pool pump automation using timers.

What does it do :

  • different durations based on season
  • different start times based on season

requirements :

  • season integration
  • a Timer helper with ID timer.piscine (“Swimming-pool” in french or change the ID in the automation) with “restore” checked
alias: Piscine - timer
description: ""
trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.piscine
    id: Timer Finished
  - platform: time
    at: "08:30:00"
    id: Start Time Summer
  - platform: time
    at: "14:00:00"
    id: Start Time Winter
  - platform: time
    at: "11:00:00"
    id: Start Time Spring / Autumn
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - Timer Finished
        sequence:
          - type: turn_off
            device_id: 5a242c23c07295d4a587dc49f79b2f54
            entity_id: 96d3282898971aab57f67b3344a4d0b1
            domain: switch
      - conditions:
          - condition: trigger
            id:
              - Start Time Summer
          - condition: state
            entity_id: sensor.season
            state: summer
        sequence:
          - type: turn_on
            device_id: 5a242c23c07295d4a587dc49f79b2f54
            entity_id: 96d3282898971aab57f67b3344a4d0b1
            domain: switch
          - service: timer.start
            data:
              duration: "43200"
            target:
              entity_id: timer.piscine
      - conditions:
          - condition: trigger
            id:
              - Start Time Winter
          - condition: state
            entity_id: sensor.season
            state: winter
        sequence:
          - type: turn_on
            device_id: 5a242c23c07295d4a587dc49f79b2f54
            entity_id: 96d3282898971aab57f67b3344a4d0b1
            domain: switch
          - service: timer.start
            data:
              duration: "7200"
            target:
              entity_id: timer.piscine
      - conditions:
          - condition: trigger
            id:
              - Start Time Spring / Autumn
          - condition: state
            entity_id: sensor.season
            state:
              - spring
              - autumn
        sequence:
          - type: turn_on
            device_id: 5a242c23c07295d4a587dc49f79b2f54
            entity_id: 96d3282898971aab57f67b3344a4d0b1
            domain: switch
          - service: timer.start
            data:
              duration: "28800"
            target:
              entity_id: timer.piscine
mode: single

screenshot triggers

screenshot choose