Hilfe bei Automation: Steckdosen schalten sich nicht 3 Stunden vor Sonnenaufgang ein

Hallo zusammen,

ich habe eine Automation erstellt, die meine Steckdosen 3 Stunden vor Sonnenaufgang einschalten soll. Leider funktioniert das nicht wie erwartet, und ich kann den Fehler nicht finden.

Hier ist der YAML-Code meiner Automation:

alias: Steckdosen Steuerung  
description: >  
triggers:  
  - event: sunrise  
    offset: "-03:00:00"  
    trigger: sun  
  - event: sunrise  
    trigger: sun  
  - event: sunset  
    trigger: sun  
  - at: "23:00:00"  
    trigger: time  
conditions: []  
actions:  
  - choose:  
      - conditions:  
          - condition: template  
            value_template: >-  
              {{ trigger.event == 'sunrise' and (now().timestamp() | timestamp_custom('%H:%M:%S')) < (state_attr('sun.sun', 'next_rising') | timestamp_custom('%H:%M:%S', true)) }}  
        sequence:  
          - target:  
              entity_id:  
                - switch.steckdose_001_switch_0  
                - switch.steckdose_002_switch_0  
            action: switch.turn_on  
            data: {}  
      - conditions:  
          - condition: template  
            value_template: "{{ trigger.event == 'sunrise' }}"  
        sequence:  
          - target:  
              entity_id:  
                - switch.steckdose_001_switch_0  
                - switch.steckdose_002_switch_0  
            action: switch.turn_off  
            data: {}  
      - conditions:  
          - condition: template  
            value_template: "{{ trigger.event == 'sunset' }}"  
        sequence:  
          - target:  
              entity_id:  
                - switch.steckdose_001_switch_0  
                - switch.steckdose_002_switch_0  
            action: switch.turn_on  
            data: {}  
      - conditions:  
          - condition: time  
            after: "23:00:00"  
        sequence:  
          - target:  
              entity_id:  
                - switch.steckdose_001_switch_0  
                - switch.steckdose_002_switch_0  
            action: switch.turn_off  
            data: {}  
mode: single  

Ich habe versucht, das Event ‘sunrise’ mit einem Offset von ‘-03:00:00’ zu nutzen, aber irgendwie wird die Aktion nicht ausgelöst. Kann mir jemand sagen, ob ich hier einen Denkfehler gemacht habe?

Vielen Dank im Voraus!

Was fragst du denn in den Templates genau ab?
Der Trigger sollte aktiv sein. Das müsstest du im Trace der Automation sehen.

Ein Tipp wäre eine ID für das EVENT zu vergeben und darauf weiter aufzubauen.

Ich habe dazu eine Option 5 implementiert.

alias: Steckdosen Steuerung
description: ""
triggers:
  - event: sunrise
    offset: "-03:00:00"
    trigger: sun
    id: SUNRISE-3H
  - event: sunrise
    trigger: sun
    id: SUNRISE
  - event: sunset
    trigger: sun
  - at: "23:00:00"
    trigger: time
conditions: []
actions:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.event == 'sunrise' and (now().timestamp() |
              timestamp_custom('%H:%M:%S')) < (state_attr('sun.sun',
              'next_rising') | timestamp_custom('%H:%M:%S', true)) }}  
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_on
            data: {}
      - conditions:
          - condition: template
            value_template: "{{ trigger.event == 'sunrise' }}"
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_off
            data: {}
      - conditions:
          - condition: template
            value_template: "{{ trigger.event == 'sunset' }}"
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_on
            data: {}
      - conditions:
          - condition: time
            after: "23:00:00"
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_off
            data: {}
      - conditions:
          - condition: trigger
            id:
              - SUNRISE-3H
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_on
            data: {}
mode: single

1 „Gefällt mir“

Ich würde es auch über IDs und damit so lösen:

alias: Steckdosen Steuerung
description: ""
triggers:
  - event: sunrise
    offset: "-03:00:00"
    trigger: sun
    id: AUFGANG-3
  - event: sunrise
    trigger: sun
    id: AUFGANG
  - event: sunset
    trigger: sun
    id: UNTERGANG
  - at: "23:00:00"
    trigger: time
    id: UHRZEIT
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - AUFGANG-3
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_on
            data: {}
      - conditions:
          - condition: trigger
            id:
              - AUFGANG
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_off
            data: {}
      - conditions:
          - condition: trigger
            id:
              - UNTERGANG
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_on
            data: {}
      - conditions:
          - condition: trigger
            id:
              - UHRZEIT
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_off
            data: {}
mode: single

EDIT:

Oder sogar noch besser so:

alias: Steckdosen Steuerung
description: ""
triggers:
  - event: sunrise
    offset: "-03:00:00"
    trigger: sun
    id: AN
  - event: sunrise
    trigger: sun
    id: AUS
  - event: sunset
    trigger: sun
    id: AN
  - at: "23:00:00"
    trigger: time
    id: AUS
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - AN
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_on
            data: {}
      - conditions:
          - condition: trigger
            id:
              - AUS
        sequence:
          - target:
              entity_id:
                - switch.steckdose_001_switch_0
                - switch.steckdose_002_switch_0
            action: switch.turn_off
            data: {}
mode: single

Gruß, Lars

1 „Gefällt mir“

Danke Euch! :hugs: Die Automation funktioniert mit den IDs perfekt. :clap: