Turn light on based on Lux value

Getting hung up on this simple automation and I’m not sure what is wrong. All I’m trying to do is turn on a light when the Lux value of a nearby sensor is below a certain value. Ive verified the sensor entity is reporting the value that should trigger the automation but it doesn’t work. I initially had the attribute blank but it didn’t work so I added the Lx attribute which still didn’t help. Here is the code:

alias: Kitchen cabinet light on @ 55 lux
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.kitchen_sensor_illuminance
    below: 55
    attribute: lx
conditions: []
actions:
  - action: light.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: light.cabinet_light
  - action: notify.mobile_app_pixel_8
    metadata: {}
    data:
      message: Kitchen cabinet light turned on
mode: single

Hello Shawn,

First, if you share code, please use the formatter button so we can read it. It is very hard for us to tell what is what when the text formatter jumbles everything like that.
You can use the </> button like this… How to format your code in forum posts
OR… Here is an example of how to fix it from the site FAQ Page.
How to help us help you - or How to ask a good question.

Then, I’m guessing from your question that this is messing you up. Triggers probably don’t work like you are thinking they do, based on your question. Automations #1: trigger only fires when it changes from not true to true

You don’t need the lx attribute.

As @Sir_Goodenough says, this is probably something to do with the trigger. A trigger only fires when the sensor value passes it - in your case goes from 56 to 54. It won’t fire again until lx goes back up above 55, then down again.

But apart from that… watch out for weird things when the light sensor is close to the light - it’s easy to get it flashing on and off repeatedly. :grin:

Got it working based on the trigger comments. Oddly enough the biggest learning curve was initially defining the light’s device instead of the light entity under it. The light won’t turn on if you just define the device.

alias: Kitchen Cabinet Light
description: Turns on when lux is above set value.
triggers:
  - type: illuminance
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: sensor.kitchen_sensor_illuminance
    domain: sensor
    trigger: device
    below: 55
    id: Too dark
    alias: Lux below 55
  - type: illuminance
    device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    entity_id: sensor.kitchen_sensor_illuminance
    domain: sensor
    trigger: device
    above: 55
    id: Too bright
    alias: Lux above 55
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id: Too dark
        sequence:
          - action: light.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: light.cabinet_light
      - conditions:
          - condition: trigger
            id: Too bright
        sequence:
          - action: light.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: light.cabinet_light
mode: single