Aqara Pir and lux sensor automation example

Hi,
I have an aqara motion sensor with illuminance sensor and want to share automations.
The idea is to turn on light when there is motion and illuminance below x.
Trigger is motion, condition is illuminance and action is turn on light.
Trigger starts a timer.
Once the light turns on the condition of illuminance does not meet so I have done another automation that does not have illumination condition.
So at fiirst… Automation 1: detect motion, illuminance below threshold --> turn on light, start timer, turn off automation 1, turn on automation 2.
Automation 2: detect motion --> restart timer
Automation 3: timer expires --> turn off light, turn on automation 1, turn off automation 2.

That’s it, what do you guys think?
Is this the correct approach?
Thanks in advance,

here some examples :

- alias: Badkamer motion ON
  initial_state: on
  trigger:
    platform: state
    entity_id: binary_sensor.xiaomi_sensor_3
    from: 'off'
    to: 'on'
  condition:
    - condition: numeric_state
      entity_id: sensor.xiaomi_sensor_3
      below: 20
  action:
  - service: light.turn_on
    entity_id: light.badkamer

- alias: Motion Dressing On
  initial_state: 'on'
  trigger:
#  - entity_id: binary_sensor.tradfri_motion_sensor1
  - entity_id: binary_sensor.xiaomi_sensor_4  
    platform: state
    from: 'off'
    to: 'on'
  action:
  - service: light.turn_on
    entity_id: light.dressing
    
- alias: Motion Dressing Off
  initial_state: 'on'
  trigger:
#  - entity_id: binary_sensor.tradfri_motion_sensor1
  - entity_id: binary_sensor.xiaomi_sensor_4 
    platform: state
    from: 'on'
    to: 'off'
    for:
      seconds: 30
  action:
  - service: light.turn_off
    entity_id: light.dressing

Hi Fabio, thanks for the quick response!

I am grateful for your examples, but I will still use my actual automations, that make use of the illuminance sensor for the first automation, then only motion for automation 2 and a timer for the switch off.

Here my code:

- id: '1'
  alias: automation1
  trigger:
  - entity_id: binary_sensor.0x000_occupancy
    platform: state
    to: 'on'
  condition:
  - below: '25'
    condition: numeric_state
    entity_id: sensor.0x000_illuminance
  action:
  - data:
      entity_id: timer.timer_1
    service: timer.start
  - data:
      entity_id: automation2
    service: automation.turn_on
  - data:
      entity_id: automation1
    service: automation.turn_off
  - data:
      entity_id: switch.sonoff_t4eu
    service: switch.turn_on
- id: '2'
  alias: automation2
  trigger:
  - entity_id: binary_sensor.0x000_occupancy
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      entity_id: timer.timer_1
    service: timer.start
- id: '3'
  alias: automation3
  trigger:
  - event_data:
      entity_id: timer.timer_1
    event_type: timer.finished
    platform: event
  condition: []
  action:
  - data:
      entity_id: automation2
    service: automation.turn_off
  - data:
      entity_id: automation1
    service: automation.turn_on
  - data:
      entity_id: switch.sonoff_t4eu
    service: switch.turn_off

Hi, how this automation works for you? I have the same sensor and its very close what I was thinking to implement.

Now I have switched to nodered for my automations. I dont understand you question @Makis

Aqara E1 PIR sensor had a weakness, lux value only updated when there are motion detected, it won’t provide realtime lux update. The automation you build won’t be accurate or consider their dedicated T1 lux sensor for better data. I only found out with node-red reading from the debug output.

Thanks for the info @raymondsfk . That weakness about the lux value update was making me crazy :slight_smile: Now I have an external lux sensor so I can do the automations using this new sensor.

Thanks for the hint