Pool Solar Pump Automation doesn't work right

Hi,

for my Pool i want to switch the pump with HA.

It should turn ON 4 hours after sunrise < works!
it should turn OFF 2 hours before sunset < doesn’t work, stays on.

here my YAML:

alias: Pool Filterpumpe
description: ''
trigger:
  - platform: sun
    event: sunrise
    offset: '04:00:00'
  - platform: sun
    event: sunset
    offset: '-02:00:00'
action:
  - choose:
      - conditions:
          - condition: sun
            after: sunrise
            after_offset: '04:00:00'
        sequence:
          - service: switch.turn_on
            entity_id: switch.pumpe_relays_1
      - conditions:
          - condition: sun
            before: sunset
            before_offset: '02:00:00'
        sequence:
          - service: switch.turn_off
            entity_id: switch.pumpe_relays_1
mode: single

i am trying for many days now but can’t find an error.
(chatGPT couldn’t help either :slight_smile: )

Can someone help?

alias: Pool Filterpumpe
description: ''
trigger:
  - id: 'on'
    platform: sun
    event: sunrise
    offset: '04:00:00'
  - id: 'off'
    platform: sun
    event: sunset
    offset: '-02:00:00'
action:
  - service: 'switch.turn_{{ trigger.id }}'
    target:
      entity_id: switch.pumpe_relays_1
mode: single

Because although it triggers exactly 2 hours before sunset, it evaluates the Sun Condition several microseconds later, when the time is no longer 2 hours before sunset (it’s approximately 1 hour, 59 minutes, 59 seconds and several milliseconds before sunset).

thank you!

would it run if offset and trigger are ‘-02:00’ instead of ‘02:00:00’ ?

You’re welcome!

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 about the Solution tag, refer to guideline 21 in the FAQ.

? or should be a delay somewhere?
(your code runs well, but i am still trying to understand my original code)

Try it and let us know the result.