Help with simple automation - lights

Hi Guys,

I’m struggling to get this simple lighting automtion working

alias: "kitchen lights motion "
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.hue_motion_kitchen_motion
    to: "on"
condition:
  - condition: numeric_state
    entity_id: sensor.hue_motion_kitchen_illuminance
    below: 30
action:
  - service: light.turn_on
    data:
      brightness_pct: 95
      transition: 3
    target:
      entity_id: light.kitchen_group
  - condition: state
    entity_id: binary_sensor.hue_motion_kitchen_motion
    state: "off"
    for:
      hours: 0
      minutes: 2
      seconds: 0
  - condition: state
    entity_id: light.kitchen_group
    state: "on"
  - condition: numeric_state
    entity_id: light.kitchen_group
    attribute: brightness
    below: 96
  - service: light.turn_off
    data:
      transition: 4
    target:
      entity_id: light.kitchen_group
mode: single

It’s designed to switch off the motion lights and not when they are switched on manually.
based on the brightness value, which is 100% for manually switched on lights and 95% when turned on by the motion sensor. The automation turns the lights on but won’t turn them off.

Suspect it’s something really simple?? I did create the whole automation using the visual editor. Any help would be much appreciated

Are you familiar with how action conditions work? If they evaluate to false, the automation terminates and doesn’t continue processing any subsequent actions.

Your automation is designed to trigger when the kitchen motion sensor turns on. Then the first action condition checks if the kitchen motion sensor has been off for at least 2 minutes. This condition can never be true because the motion sensor just triggered moments earlier (and it’s on). The condition doesn’t wait for the sensor to turn off for 2 minutes, it checks if it has been off for the past 2 minutes.

I guess it can’t turn it off because in the trigger section there is: to « on », so there is no way the automation gets triggered when off is raised

Simplest solution is to create two separate automations.

alias: "kitchen lights motion on"
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.hue_motion_kitchen_motion
    to: "on"
condition:
  - condition: numeric_state
    entity_id: sensor.hue_motion_kitchen_illuminance
    below: 30
action:
  - service: light.turn_on
    data:
      brightness_pct: 95
      transition: 3
    target:
      entity_id: light.kitchen_group
alias: "kitchen lights motion off"
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.hue_motion_kitchen_motion
    state: "off"
    for:
      hours: 0
      minutes: 2
      seconds: 0
condition:
  - condition: state
    entity_id: light.kitchen_group
    state: "on"
  - condition: numeric_state
    entity_id: light.kitchen_group
    attribute: brightness
    below: 96
action:
  - service: light.turn_off
    data:
      transition: 4
    target:
      entity_id: light.kitchen_group
mode: single

If you absolutely want a single automation then you can do it like this:

alias: "kitchen lights motion"
description: ""
trigger:
  - platform: state
    entity_id: binary_sensor.hue_motion_kitchen_motion
    to: "on"
  - platform: state
    entity_id: binary_sensor.hue_motion_kitchen_motion
    state: "off"
    for:
      minutes: 2
condition: []
action:
  - choose:
      - conditions:
          - "{{ trigger.to_state.state == 'on' }}"
          - condition: numeric_state
            entity_id: sensor.hue_motion_kitchen_illuminance
            below: 30
        sequence:
          - service: light.turn_on
            data:
              brightness_pct: 95
              transition: 3
            target:
              entity_id: light.kitchen_group
      - conditions:
          - "{{ trigger.to_state.state == 'off' }}"
          - condition: state
            entity_id: light.kitchen_group
            state: "on"
          - condition: numeric_state
            entity_id: light.kitchen_group
            attribute: brightness
            below: 96
        sequence:
          - service: light.turn_off
            data:
              transition: 4
            target:
              entity_id: light.kitchen_group
    default: []

@123 Thanks for your helpful replies, I guess its simpler to break into two separate automations.

I have always struggled a bit with conditions, but it makes complete sense the way you explained it. So what if I added a wait for say 3 minutes and then checked the motion sensor the automation would work??

Post an example (code) of what you’re proposing.