Aqara p1 motion sensor... when does it send events?

Hi all, I have an aqara p1 motion sensor, which for the most part works really well, but I have noticed something strange in one of my automations, which I think might be related to when the sensor actually sends events back to HA.

My question is this…

Does the Aqara p1 (or I’m guessing other motion sensors), only send an event to HA when a state changes ?

My motion sensor has a refresh interval of 30 seconds before it attempts detection again.

When I first go in range of the sensor, the detection is triggered and the state changes from ‘clear’ to ‘detected’.

If I stay in the area of the sensor and keep moving around, will I get another ‘detected’ in 30 seconds, or do I have to wait for it to go back to ‘clear’ (thus changing state), before it can then send another ‘detected’.

I’m assuming I don’t get another ‘detected’ in 30 seconds, because its already sent that message.

This has a side effect in my automation.

I have smart plug with a night light connected to it. When the sensor detects presence, AND the illuminance is below a certain level, it turns on.

If I have a main hall light on, the illuminance is too high and the night light doesnt come on. However, if I stand in the hall and switch off the main light, so the illuminance drops, the night light never comes on until I leave the area for a while then return. I think this is because of the above.

If so, how might you get around this ?

I have one, with the detection_interval set to 10 seconds. I regularly see motion detection events of over a minute.

You really need to share those automations so we can see if there’s a logic problem here.

You can always look at the entity’s history to see what happened.

Thanks for the tip. It is as I suspected. You never get multiple ‘detected’ in a row, the events simply toggled between cleared and detected:-

image

(I’ve scrolled through the whole day and its the same all the way down).

This is my automation:-

alias: 1st Floor Night Light
description: ""
trigger:
  - type: motion
    platform: device
    device_id: 003fb0c5928d1b972deedb8398a4aaea
    entity_id: binary_sensor.lumi_lumi_motion_ac02_iaszone_2
    domain: binary_sensor
condition:
  - type: is_illuminance
    condition: device
    device_id: 003fb0c5928d1b972deedb8398a4aaea
    entity_id: sensor.lumi_lumi_motion_ac02_illuminance_2
    domain: sensor
    below: 41
action:
  - type: turn_on
    device_id: 956725bc947f0414fa6e41ca785ee017
    entity_id: switch.tradfri_plug_first_floor_hall_switch
    domain: switch
  - wait_for_trigger:
      - type: no_motion
        platform: device
        device_id: 003fb0c5928d1b972deedb8398a4aaea
        entity_id: binary_sensor.lumi_lumi_motion_ac02_iaszone_2
        domain: binary_sensor
        for:
          hours: 0
          minutes: 1
          seconds: 0
  - type: turn_off
    device_id: 956725bc947f0414fa6e41ca785ee017
    entity_id: switch.tradfri_plug_first_floor_hall_switch
    domain: switch
mode: single

You could try adding an additional number state trigger for below 41 for illuminance and another condition for the state of the motion as activated.

  1. triggered by motion, tests both conditions, if illuminance is high nothing happens (obviously the second condition of motion will pass)
  2. triggered by you turning the “big” light off, tests both conditions, if the motion is still active will turn the light on (obviously passes the original condition)

I think, because the device itself is not sending another event until its state changes, I don’t think I can fix this in automation. Perhaps the best I can do is set the detection interval to a lower value (say 10 seconds), which fortunately the new aqara p1 lets you do.

The problem is that if it’s detecting motion when the light level drops, the automation won’t run.

That’s a trivial fix:

trigger:
  - type: motion
    platform: device
    device_id: 003fb0c5928d1b972deedb8398a4aaea
    entity_id: binary_sensor.lumi_lumi_motion_ac02_iaszone_2
    domain: binary_sensor
  - platform: numeric_state
    entity_id: sensor.lumi_lumi_motion_ac02_illuminance_2
    below: 41
condition:
  - type: is_illuminance
    condition: device
    device_id: 003fb0c5928d1b972deedb8398a4aaea
    entity_id: sensor.lumi_lumi_motion_ac02_illuminance_2
    domain: sensor
    below: 41
  - condition: state
    entity_id: binary_sensor.lumi_lumi_motion_ac02_iaszone_2
    state: 'on'

Now when either there is motion detected when the light level is already below 41, or the light level falls below 41 while motion is detected, the automation will run

Thanks @Tinkerer I’ll give that a go later and report back!