Automation, why doesn't this work?

Why doesn’t this work? Any ideas? The automation doesn’t get triggered and doesn’t work when i try it manually.

alias: 00_Woonkamer Licht AAN
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.woonkamer_ms_groep
    to: "on"
    id: M1
condition:
  - condition: state
    entity_id: binary_sensor.woonkamer_ms_groep
    state: "on"
action:
  - if:
      - condition: trigger
        id:
          - M1
      - condition: and
        conditions:
          - condition: numeric_state
            entity_id: sensor.hue_motion_sensor_2_illuminance_2
            below: 100
          - condition: state
            entity_id: light.woonkamer
            state: "off"
          - condition: state
            entity_id: light.eetkamer
            state: "off"
    then:
      - type: turn_on
        device_id: d76a7df18ac7a7226664f4c1b295eb6f
        entity_id: bfb946a49ed6dc7d999c380a7cfe3257
        domain: light
      - type: turn_on
        device_id: dba492b2c9de821bd23dfb2475fbba0c
        entity_id: f59c866fc98387621769a3781a099001
        domain: light
trace:
  stored_traces: 150
mode: single

Tracing:

Executed: 11 september 2023 om 18:02:27

if

Executed: 11 september 2023 om 18:02:27
Result:

result: false

if/condition/0

Executed: 11 september 2023 om 18:02:27
Result:

result: false

Your condition is redundant, and you don’t really need a trigger id. when you manually test it, it only runs the actions so you’ll always fail the trigger id condition in the if.

if it doesn’t trigger otherwise via the binary_sensor, then you want to verify that you have the correct entity_id.

alias: 00_Woonkamer Licht AAN
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.woonkamer_ms_groep
    to: "on"
condition:
  - condition: numeric_state
    entity_id: sensor.hue_motion_sensor_2_illuminance_2
    below: 100
  - condition: state
    entity_id: light.woonkamer
    state: "off"
  - condition: state
    entity_id: light.eetkamer
    state: "off"
action:
  - type: turn_on
    device_id: d76a7df18ac7a7226664f4c1b295eb6f
    entity_id: bfb946a49ed6dc7d999c380a7cfe3257
    domain: light
  - type: turn_on
    device_id: dba492b2c9de821bd23dfb2475fbba0c
    entity_id: f59c866fc98387621769a3781a099001
    domain: light

Why do you need to keep a record of the last 150 times the automation executed?

Wanted 15. So a typo.

Will try this, but entity ID’s are created with the GUI. Called livingroom (woonkamer) en diningroom (eetkamer). So i am not sure how this could be wrong.

When i look those devices up and turn them on/off manually it works.

I’m not sure what the entities have to do with this. It’s failing the condition when you hit the test button because there’s no trigger. That’s what your if condition is stopping. This is causing your test button to fail

I have tested your version of my automation. (Manually) the lights go on then.

Will have to test a bit longer to see if the binary sensors (motion) also turn the light on with your version.

Thanks so far will get back to you soon.

One question you removed the part if lights are on do nothing. Will this not tricker the light to flash / "turn on "again? If i am not mistaken i have seen that happing in the past.

I did not remove that. It’s in your condition. I removed all your uncessary checks.

you only have 1 trigger.

so, you don’t neeed to check if it’s the trigger

The automation only triggers when binary_sensor.woonkamer_ms_groep turns to ‘on’, so there’s no reason to check

Removing all that stuff gets you the version I posted here

Nope, that won’t trigger a flickering light. :slight_smile: But you can try it yourself.

Turn on the light you want to check manually, after that go to Developer tools > Services and choose Light: turn on and change the code underneath to this:

service: light.turn_on
data: 
  entity_id: <YOUR_ENTITY_ID_HERE>

Then click Call service and watch the light. :slight_smile:

I apologize, i mixed two automation up in my head.

@petro ,

Ok i tried it a couple of times but the motion sensors (helper group) doesn’t turn the light on.

I have check the 3 motion sensors in the group, they are correct and working (separately).

Where should i look next?

Watch the helper and make sure it’s changing states.

“AAN” is dutch for ON. So the answer is yes it changes Status.

but does it turn off? State needs to change for it to cause a trigger e.g. (off to on). Also make sure you have the correct entity_id on your trigger.

Yes it turns off.
And yes it is the right one.

Then you should watch the trace and verify that the condition is passing or failing.

That is the thing. It just doesnt run. The last trace is from 18.42 when i triggered it manually. (It is 21.00 now here)

If it’s just not running, then it’s not triggering. So something is wrong with the trigger itself or the entity. Are you 100% sure you have the correct entity? Are you 100% sure that it’s changing state when you walk in front of the motion sensors? You can watch all of this in developer tools → states page.

Could you check here?

Maybe my errors have got something to do with it.