Automation not running, lux and sunrise

Hi all,
I have been struggling with some light automations. The first one to turn lights on after lux level below 20, and after sunrise works fine.

alias: deCONZ light nattbelysning SH/TH on
description: Below 20 lx and after sunset
trigger:
  - platform: numeric_state
    entity_id: sensor.infart_motion_light_level
    below: '20'
condition:
  - condition: and
    conditions:
      - condition: sun
        after: sunset
action:
  - service: light.turn_on
    data:
      brightness_pct: 50
    target:
      entity_id: light.hallfonster
  - service: light.turn_on
    target:
      entity_id: light.gardsfonster
    data:
      brightness_pct: 30
  - service: light.turn_on
    data:
      brightness_pct: 50
      rgb_color:
        - 255
        - 0
        - 0
    target:
      entity_id: light.koksfonster
  - service: light.turn_on
    data:
      brightness_pct: 30
    target:
      entity_id:
        - light.th_nattbelysning
mode: single

But I can’t get it to work the opposite way, e.g. turn off the lights at sunset and above a certain lux level.

alias: deCONZ light nattbelysning SH/TH off
description: Sunrise and above 15 lx
trigger:
  - platform: numeric_state
    entity_id: sensor.infart_motion_light_level
    above: '15'
condition:
  - condition: and
    conditions:
      - condition: sun
        after: sunrise
action:
  - service: light.turn_off
    target:
      entity_id:
        - light.nattbelysning
        - light.th_nattbelysning
mode: single

Any suggestions highly appreciated!

Check the time of the sunrise. Maybe the lux level is already above 15 before sunrise event happen. So the first time the automation is triggered, it does not satisfy the after sunrise condition.

You can add the condition into the trigger-

trigger:
  - platform: numeric_state
    entity_id: sensor.infart_motion_light_level
    above: '15'
  - platform: sun
    event: sunrise
condition:
  - condition: numeric_state
    entity_id: sensor.infart_motion_light_level
    above: '15'
  - condition: sun
    after: sunrise
1 Like

Thanks, that didn’t come to my mind at all, and I doubt it would ever cross my mind either :smiley:. You are probably right, I’ll try your solution!