Sun condition not workling?

Hi

I have made this automation to control some outdoor lights, but its not working.
what am i missing?

alias: "sol belysning "
description: ""
trigger:
  - platform: sun
    event: sunrise
    offset: "-02:00:00"
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
action:
  - type: turn_on
    device_id: bb3d2aecd9c02365aa35009613530525
    entity_id: switch.shelly_pro_2_switch_0
    domain: switch
  - delay:
      hours: 2
      minutes: 0
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: bb3d2aecd9c02365aa35009613530525
    entity_id: switch.shelly_pro_2_switch_0
    domain: switch
  - wait_for_trigger:
      - platform: sun
        event: sunset
        offset: 0
  - type: turn_on
    device_id: bb3d2aecd9c02365aa35009613530525
    entity_id: switch.shelly_pro_2_switch_0
    domain: switch
  - delay:
      hours: 2
      minutes: 0
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: bb3d2aecd9c02365aa35009613530525
    entity_id: switch.shelly_pro_2_switch_0
    domain: switch
mode: single

I would separate into 4 different automations by removing delay and wait_for_trigger. Each of these commands are triggers.
Divide to conquer.

Also, consider checking the debug log of the current automation you have.

  • Turn on the switch 2 hours before sunrise.
  • Turn off the switch 2 hours later at sunrise.
  • Turn on the switch at sunset.
  • Turn off the switch 2 hours after sunset.
alias: "sol belysning "
description: ""
trigger:
  - id: 'on'
    platform: sun
    event: sunrise
    offset: "-02:00:00"
  - id: 'off'
    platform: sun
    event: sunrise
  - id: 'on'
    platform: sun
    event: sunset
  - id: 'off'
    platform: sun
    event: sunset
    offset: "02:00:00"
condition:
  - condition: time
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
action:
  - service: "switch.turn_{{ trigger.id }}"
    target:
      entity_id: switch.shelly_pro_2_switch_0
mode: single

This works great! Thank you for taking the time to make this :slight_smile:

1 Like