Occupancy automation with luminance condition not working

I am trying to create a simple automation that should be working based on what I am looking at but I must be missing something because it won’t trigger.

I have a trigger of when motion is detected with the condition of lux below 1000 lumens then turn on my kitchen and dining lights.

alias: Motion & Lux - Kitchen Lighting
description: ""
mode: single
triggers:
  - entity_id:
      - binary_sensor.kitchen_luminance_sensor_occupancy
    attribute: occupancy
    to: Detected
    trigger: state
conditions:
  - condition: numeric_state
    entity_id: sensor.kitchen_luminance_sensor_illuminance
    attribute: illuminance
    below: 1000
actions:
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.kitchen_dining_lights

Can anyone see what is wrong with this code?

A binary_sensor entity’s actual state will be “on” or “off”…

alias: Motion & Lux - Kitchen Lighting
description: ""
mode: single
triggers:
  - trigger: state
    entity_id: binary_sensor.kitchen_luminance_sensor_occupancy
    to: "on"
conditions:
  - condition: numeric_state
    entity_id: sensor.kitchen_luminance_sensor_illuminance
    below: 1000
actions:
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.kitchen_dining_lights
1 Like

OK excellent. I will make the changes and report back. Just wondering how I can get that info myself. How I came to add that state was in the state history it was reporting Detected & Clear. So I figured that was the two states I could automate on.

You can also see the attributes are true and false.

I would love to know the easy way to work out what an actionable state for an entity is.

You can see the current real state of entities in the States tab of Developer Tools.

Perfect, I can see that now. Very helpful.

However even with the suggested changes it doesn’t seem to work.

Are you sure your sensor has an attribute named illuminance? It’s more likely that a sensor called “sensor.kitchen_luminance_sensor_illuminance” holds the illuminance value in its state… you can check which attributes an entity has in the same States tab discussed earlier.

If your sensor doesn’t have illuminance listed in its attributes in the States tab, remove it from your condition:

    condition: numeric_state
    entity_id: sensor.kitchen_luminance_sensor_illuminance
    below: 1000

Double check your trigger entity in the States tab too… in your original post you had attribute: occupancy. Based on the entity info screenshot you provided earlier, it looks like the binary sensor does have an occupancy attribute, but it uses true or false as its values. I would suggest using the binary sensor’s state, not the occupancy attribute.

@stumbows,
From a diagnostic approach, I always try to isolate the conditions to test them individually.

For example, remove the “conditions:” section so you can just test that the motion sensor is working as you expect. You could verify this from the automations list where it will show you the last time the automation was executed.

If it’s executed and your light turns on, then there’s an issue with your condition. You could test this independently with the same approach by putting it in the trigger section.

If it’s executed without the conditions: section, but your light doesn’t come on, then your issue is with your “actions:” section, In my automations, I see that light.turn_on is using a device_id instead of an entity_id.

Good Luck!

Thank you for the suggestions. The comment about calling the entity id over the device id got me thinking.

First I disabled the condition of illuminance and the motion detection still didn’t work so I rebuilt the whole automation using the call of the device instead of entity like this.

alias: Test
description: ""
triggers:
  - type: occupied
    device_id: 467c5a3470a7408459f4e29d228a3e16
    entity_id: 03bdd9e5b39fa1844120bfcdcfebefab
    domain: binary_sensor
    trigger: device
    for:
      hours: 0
      minutes: 0
      seconds: 1
conditions:
  - type: is_illuminance
    condition: device
    device_id: 467c5a3470a7408459f4e29d228a3e16
    entity_id: 6691b2f8679c65f72a38e697cd4b3fbd
    domain: sensor
    below: 1000
actions:
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.kitchen_dining_lights
mode: single

Now it works

I have a similar problem. Here is my action:

alias: Kitchen LED Strips ON
description: Turn Kitchen LED Strips on if the Light Brightness in the Kitchen is over a certain level
triggers: []
conditions:
  - type: is_illuminance
    condition: device
    device_id: 34351ee27588060dd0c530a63211304f
    entity_id: aa853bc0d42cf70651cd93553f60f316
    domain: sensor
    below: 10
actions:
  - type: turn_on
    device_id: 53828b7902b98a9e43cf32a4e2958ca4
    entity_id: b1303657c8c63951303bdbc1792bab2d
    domain: light
    brightness_pct: 10
  - type: turn_on
    device_id: 99bab6be668f87372f7042c3fb29f1ec
    entity_id: 8727efeb4b5194c35b73516039b5a9f2
    domain: light
    brightness_pct: 10
mode: single

If I test the condition it fails. But If I run the action it executes the actions. What did I do wrong? I assume the action will not perform the "Then Do’ section if “And If” conditions failed