Help solution for unstable morning light sensor automation trigger

I have an automation setup with a light sensor and a motion sensor. Everything worked well until I encountered a problem with the automation logic. I configured the automation to turn on the light when the luminance is above 200 lux. However, in the morning, the light levels are unstable, causing the sensor to occasionally drop below 200 lux for about a minute before rising again. During this fluctuation, the automation triggers and turns on the light.

Does anyone have a solution for this?
I want the automation to consider the light level for the last 2 minutes before the trigger to ensure that it remains above 200 lux

Hello caohuongls,

Thanks for the question.

Unfortunately you have provided no code showing what you have done so far so I’m going to do a little guessing.

If you have used a numeric_state trigger you have a parameter there called for: I suggest you use that and set it so that the light level you want is checked to be stable about 4x longer than you think you might need, so like 5 minutes maybe. That should give you a more stable reading.

How to help us help you - or How to ask a good question.

I use a low pass filter to iron out the fluctuations:

Thanks for your reply, @Sir_Goodenough. Here is the full code I’m using.

I utilize motion sensors, light sensors, and a camera to trigger actions, with specific conditions to restrict them.

One of my triggers is a numeric_state trigger set for 15 minutes, which is only useful at night when the light sensor reads below 200 lux.

In my situation, the motion or camera triggers activate the automation. At that moment, the light sensor is below 200 lux, the condition is met, the light turns on

alias: Bật đèn phòng labo
trigger:
  - platform: state
    entity_id: group.cam_bien_chuyen_dong_phong_thiet_ke
    to: "on"
    id: Group cam_bien_chuyen_dong phòng thiết kế off to on
  - platform: template
    value_template: ""
    id: >-
      {{ 'person'  in
      state_attr('image_processing.doods_hass_camera','summary')    }}
    alias: Phát hiện khi có người từ camera
  - platform: numeric_state
    entity_id:
      - sensor.cam_bien_anh_sang_phong_thiet_ke_illuminance_lux
    below: "250"
    for:
      hours: 0
      minutes: 15
      seconds: 0
  - platform: state
    entity_id:
      - binary_sensor.hlk_ld2410_9eda_motion
    to: "on"
condition:
  - condition: state
    entity_id: group.cam_bien_chuyen_dong_phong_thiet_ke
    state: "on"
  - condition: time
    after: "08:00:00"
    before: "23:59:00"
  - condition: numeric_state
    entity_id: sensor.cam_bien_anh_sang_phong_thiet_ke_illuminance_lux
    below: 200
action:
  - alias: >-
      Chờ đến khi phát hiện có người thì bật, tránh trường hợp phát
      hiện chuyển động nhưng camera chưa kịp phát hiện người
    wait_for_trigger:
      - platform: template
        value_template: >-
          {{ 'person'  in
          state_attr('image_processing.doods_hass_camera','summary') }}
      - platform: state
        entity_id:
          - binary_sensor.hlk_ld2410_9eda_motion
        to: "on"
    timeout:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
    continue_on_timeout: false
  - action: light.turn_on
    target:
      entity_id:
        - light.cong_tac_labo_l1
        - light.cong_tac_labo_l2
    data: {}
mode: restart
max: 2

Thanks for the information @tom_l , that sounds great. I’ll check it out and hope it solves my problem.