Xiaomi Aqara light automatization based on moving sensor

Hi Guys

I am using HA installed on raspberry pi with the Zigbee2Mqtt addon. There are 2 devices

  1. aqara moving sensor
  2. aqara switch

Simple automatization for bathroom light off/on


- alias: 'Bathroom auto light on'
  trigger:
    - platform: state
      entity_id: binary_sensor.aqara_bathroom_moving_occupancy
      from: "off"  
      to: "on"
  condition:
    - condition: state
      entity_id: switch.aqara_switch_bathroom_left
      state: 'off'
  action:
    - service: switch.turn_on
      entity_id: switch.aqara_switch_bathroom_left
      
- alias: 'Bathroom auto light off'
  trigger:
    - platform: state
      entity_id: binary_sensor.aqara_bathroom_moving_occupancy
      from: "on"  
      to: "off"
  condition:
    - condition: state
      entity_id: switch.aqara_switch_bathroom_left
      state: 'on'
  action:
    - service: switch.turn_off
      entity_id: switch.aqara_switch_bathroom_left

The problem with that it turns off the light when I am inside and I need to start moving to turn it on again.

For example I came to the bathroom at 15:00 and sensor changed state to on and turn light on. It have some delay like 3 mins (how to change that timeout time?) and at 15:03 moving sensor change state to off and light turned off. How to do some changes here when I move in bathroom it move timeout to +3 mins? So if sensor detect movement at 15:02 then it move turn off time +3 mins to 15:05 when it see movement at 15:04 move turn off +3 mins to 15:07. Something like that.

Duke

I do this with 2 automations.
1st switches the light on as soon as motion is detected.
2nd switches light off when there is no more motion detected. (+10 sec)
(it has some extra stuff that you can ignore)

There are some blueprints around that do exactly that as well.

EDIT: in fact, the first blueprint that came with HA is exactly that …