Automation problem: lights on with motion, and trigger conditions

Hi, I have a little problem. I have an automation in relation to turning on (and off) a light depending on motion. The problem is that although the automation is working, it does not turn off the lights off, if its triggered by one of the two conditions. If the trigger condition is after sunset/below sunrise - it works fine. Turns on the light and turns off after one minute. But if the trigger condition is the lux value - it does turn on the light, but does not turn it off after a minut. No idea why. Help is appreciated!

alias: “[WIATROLAP][MOTION] wlacza i wylacza swiatlo na 1m”
description: “”
trigger:

  • platform: state
    entity_id:
    • binary_sensor.satel_cz_wejscie
      for:
      hours: 0
      minutes: 0
      seconds: 0
      to: “on”
      id: Motion Detected
  • platform: state
    entity_id:
    • binary_sensor.satel_cz_wejscie
      to: “off”
      for:
      hours: 0
      minutes: 1
      seconds: 0
      condition:
  • condition: or
    conditions:
    • condition: sun
      after: sunset
      before: sunrise
    • condition: numeric_state
      entity_id: sensor.xiaomi_lumi_sen_ill_mgl01_illuminance
      below: 15
      action:
  • if:
    • condition: trigger
      id:
      • Motion Detected
        then:
    • service: light.turn_on
      data:
      brightness: 255
      kelvin: 4200
      target:
      entity_id: light.tradfri_group_wiatrolap
      else:
    • service: light.turn_off
      data:
      transition: 15
      target:
      entity_id: light.tradfri_group_wiatrolap
      mode: single

Please format your code properly.
Click on </>, this gives you

type or paste code here

Then enter your code there.

f6be36681e0da431418ec7781fb6c62712941803

2 Likes

Check the automation’s trace when that happens. What you might find is that when it is triggered by the second trigger, the illuminance is greater than 15 and so it doesn’t pass the condition where it must be less than 15 (and so it doesn’t turn off the light).

Is the light visible to the illuminance sensor?


In addition, I agree with francisp, please format the YAML to make it easier to read and check for syntax errors.

1 Like

Sorry, new at this. i hope the way i pasted it is fine.

well, you are right. that might be a reason. the light is not directly visible, but well, it is slightly overall. is there a way around it in the parameters of the automation? i

Alias: “[WIATROLAP][MOTION] wlacza i wylacza swiatlo na 1m”
description: “”
trigger:

* platform: state
entity_id:
  * binary_sensor.satel_cz_wejscie
for:
hours: 0
minutes: 0
seconds: 0
to: “on”
id: Motion Detected
* platform: state
entity_id:
  * binary_sensor.satel_cz_wejscie
to: “off”
for:
hours: 0
minutes: 1
seconds: 0
condition:
* condition: or
conditions:
  * condition: sun
after: sunset
before: sunrise
  * condition: numeric_state
entity_id: sensor.xiaomi_lumi_sen_ill_mgl01_illuminance
below: 15
action:
* if:
  * condition: trigger
id:
    * Motion Detected
then:
  * service: light.turn_on
data:
brightness: 255
kelvin: 4200
target:
entity_id: light.tradfri_group_wiatrolap
else:
  * service: light.turn_off
data:
transition: 15
target:
entity_id: light.tradfri_group_wiatrolap
mode: single

Formatting still not right, I’m afraid. It ought to look something like:

trigger:
  - platform: state
    entity_id:
      - binary_sensor.satel_cz_wejscie
    to: "on"
  - platform: state
    entity_id:
      - binary_sensor.satel_cz_wejscie
    to: "off"
    for:
      hours: 0
      minutes: 1
      seconds: 0

etc. etc. 

Get. it. Should be correct now, thanks

alias: "[WIATROLAP][MOTION] wlacza i wylacza swiatlo na 1m"
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.satel_cz_wejscie
    for:
      hours: 0
      minutes: 0
      seconds: 0
    to: "on"
    id: Motion Detected
  - platform: state
    entity_id:
      - binary_sensor.satel_cz_wejscie
    to: "off"
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition:
  - condition: or
    conditions:
      - condition: sun
        after: sunset
        before: sunrise
      - condition: numeric_state
        entity_id: sensor.xiaomi_lumi_sen_ill_mgl01_illuminance
        below: 15
action:
  - if:
      - condition: trigger
        id:
          - Motion Detected
    then:
      - service: light.turn_on
        data:
          brightness: 255
          kelvin: 4200
        target:
          entity_id: light.tradfri_group_wiatrolap
    else:
      - service: light.turn_off
        data:
          transition: 15
        target:
          entity_id: light.tradfri_group_wiatrolap
mode: single
1 Like