Automation runtime based on Season

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