Why this automation turns on the light?

Hi. I have made an automation which is meant:

  1. To automatically turn off the lights when im not around.
  2. To make sure that all the lights are off - sometimes one of the bulbs in the Zigbee group desynchronizes and stays on. The automation should turn it off again if nobody is there.

alias: Switch off private office light if nobody is there
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.private_office_presence_sensor_occupancy
    to: "off"
    for:
      hours: 0
      minutes: 15
      seconds: 0
condition:
  - condition: or
    conditions:
      - condition: state
        entity_id: light.private_office_light
        state: "on"
      - condition: state
        entity_id: light.private_office_desk_light
        state: "on"
      - condition: state
        entity_id: light.private_office_light_1
        state: "on"
      - condition: state
        entity_id: light.private_office_light_2
        state: "on"
      - condition: state
        entity_id: light.private_office_light_3
        state: "on"
      - condition: state
        entity_id: light.private_office_light_4
        state: "on"
      - condition: state
        entity_id: light.private_office_light_5
        state: "on"
      - condition: state
        entity_id: light.private_office_light_6
        state: "on"
action:
  - service: light.turn_off
    data:
      transition: 2
    target:
      entity_id:
        - light.private_office_desk_light
        - light.private_office_light
mode: single

Unfortunately, what this automation actually do is persistently switching the lights ON when im not around, so it is doing exact opposite of what its supposed to do :slightly_frowning_face: Why this happens?
Screenshot from 2024-06-14 06-03-11

Test it using

    from: "on"
    to: "off"

You can also look at Traces to identify why it’s failing

Lights were OFF

Lights were ON

To simplify this automation , you can put your office lights in a group using a helper. If any one light is ON ,HA will report the helper entity as ON. The state will only be OFF if all lights are OFF

Condition part should not be a problem, its not about this automation not executing but executing and doing a wrong thing.

Click on the X and post what it says. I tested your automation and it worked fine.

My guess is that it’s the transition causing the issue. Try removing that.

You can also remove the entire condition block. If all the lights are already off, turning them off again isn’t going to break anything.

1 Like

What sort of presence sensor are you using?
Do you have an automation to turn these lights on?

Yes I have an automation to turn the lights on when presences is detected.

My sensors are Hue connected via Z2M, no Hue Hub.

Might be worth sharing you automation that turns the lights on.

FYI…I included the transition in my test

Sorry, this is a misunderstanding, the X is not a problem, the problem is that the condition is met, automation goes to action phase and instead of switching the lights OFF it switches them ON, even if the service call is definitely light.turn_off.
This bit:

Answering the other questions, there’s no automation supposed to turn the lights on, they are supposed only to be turned on manually

I understand the issue. I wanted to convey the automation you posted works as its should in my system. I The source of the issue may not necessarily be the automation.

I was simply offering up my system as a guinea pig to eliminate possible process issues.

Have you tried a simple test of changing turning the lights off to turning them on, as the action? This may then lead to the state being somehow wrong.

Thanks, it seems that the problem went away since i have disabled transition.
Just for the record, my bulbs are Ikea LED2106R3 in case someone will have a similar problem in the future.