Automation not starting, lux and sunrise

How do I solve this? Can’t think by myself apparently.

The automation below didn’t start today because sun condition didn’t pass.

Automation consists of a Hue outdoor motion sensor (light level) and sun condition.

Triggered by the numeric state of sensor.infart_motion_light_level at 28 September 2021, 18:31:08
Test sun condition
Stopped because a condition failed at 28 September 2021, 18:31:08 (runtime: 0.00 seconds)
Not all shown logbook entries might be related to this automation.

Normally, the sun sets before the lightlevel drops below 25 lux, but today with heavy clouds and rain, the sun triggered after the light level dropped to 25 lux.

How do I prevent this to happen again? I wan’t the automation to run like the snippet below, but also if the sun has dropped below horizon before the lux level hasn’t.
Suggestions highly appreciated!

alias: 'Light: Nattlampor SH/TH ON; <25 lux, sunset'
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.infart_motion_light_level
    below: '25'
condition:
  - 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: 15
  - service: light.turn_on
    data:
      brightness_pct: 70
      rgb_color:
        - 255
        - 0
        - 0
    target:
      entity_id: light.koksfonster
  - service: light.turn_on
    data:
      brightness_pct: 20
    target:
      entity_id: light.th_nattlampor
mode: single

If you are happy for the automation to run on either sunset and or lux below 25 then just remove the sunset condition and add it as the 2nd trigger that way causing the automation to run on either state.

Unless of course you want or need both conditions to be true?

Just add the sun as a trigger and the lux as a condition.

So you end up with both as triggers and as conditions

1 Like

Good idea, but I prefer to have both conditions to be true. That’s why I can’t figure out how to do… :thinking:

Like this?

alias: 'Light: Nattlampor SH/TH ON; <25 lux, sunset'
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.infart_motion_light_level
    below: '25'
  - platform: sun
    event: sunset
condition:
  - condition: sun
    after: sunset
  - condition: numeric_state
    entity_id: sensor.infart_motion_light_level
    below: '25'
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: 15
  - service: light.turn_on
    data:
      brightness_pct: 70
      rgb_color:
        - 255
        - 0
        - 0
    target:
      entity_id: light.koksfonster
  - service: light.turn_on
    data:
      brightness_pct: 20
    target:
      entity_id: light.th_nattlampor
mode: single

Ok what about having them both as triggers then and using the choose option and under each action use the trigger id and set the other as the condition?

That way it will trigger twice, and will only action when both conditions are true

I have never done that. How do I get the trigger ID? RTFM…? :wink:

This should work:

alias: New Automation
description: ''
mode: single
trigger:
  - platform: numeric_state
    entity_id: sensor.garage_motion_sensor_lux_level
    below: '25'
    id: lux below 25 or some other frinedly name
  - platform: sun
    event: sunset
    id: sunset or some other friendly name
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: lux below 25 or some other frinedly name
          - condition: sun
            after: sunset
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.bathroom
      - conditions:
          - condition: trigger
            id: sunset or some other friendly name
          - condition: numeric_state
            entity_id: sensor.garage_motion_sensor_lux_level
            below: '25'
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.bathroom
1 Like

Yours should also achieve the same thing as in basic form you want both conditions to be true and therefore want it to trigger on both states but only proceed to actions if both states are true.

1 Like

Excatly! Is one way or another to prefer you think?

Not really I don’t think, like most things in home assistant there are 101 ways to achieve the same thing in most cases!

I use the choose a lot so that’s the first thing that tends to come to my mind when writing an automation to script, what ever my brain finds easier to compute i guess.

1 Like

Yes, that will work.

I don’t see a reason to complicate things with a choose since the actions that run don’t depend on which trigger occurred.

Unless I’ve missed something? :man_shrugging:

1 Like