Aqara Motion Sensor Hack for 5 sec

TL;DR new sensors seem to have a 1 min reset period but still requires HA+ZHA state resets.

I’m unsure if Aqara has new hardware or firmware but 4 new sensors I recently received from Aliexpress seem to have a 1 min reset, as opposed to 2 min or 5 min reported earlier.

I applied both the service: python_script.set_state and service: zha.set_zigbee_cluster_attribute in automations as described in the thread above to reset the sensor state in HA and in ZHA after 5s.

All sensors are clearing in HA in 5s, as expected, but surprisingly the sensors are able to retrigger in just 1 min without the hardware hack. I’ve confirmed these are not false-triggers due to hardware still being in the “on” state by using a box to control true/false triggers.

At least for my use cases, 1 min is an acceptable reset period and I’m happy to not have to attempt hardware hacks.

1 Like

[New revision without requiring python_script.set_state installed and used]

For newcomers, summing up what has been just discussed here, this is the solution I’m using.

Tested on Home Assistant Core 2021.1.0 and ZHA integration

Requirements:

  • Aqara motion sensor hardware hack

  • an automation to turn on the light (can use a switch or light HA entity):

alias: Turn on light if Aqara motion sensor is activated
description: ''
trigger:
  - entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone
    platform: state
    from: 'off'
    to: 'on'
condition: []
action:
  - service: switch.turn_on # (or light.turn_on)
    data: {}
    entity_id: switch.xxxxxxxxxxx # (or light.xxxxxxxxx)
mode: single
initial_state: true
  • an automation to turn off the light (can use a switch or light HA entity), but with checking after some seconds if the motion sensor is still clear, otherwise the light might be turned off even if somebody is still moving inside the room:
alias: Turn off light if Aqara motion sensor is clear
description: ''
trigger:
  - entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone
    platform: state
    from: 'on'
    to: 'off'
    for: '00:00:20'
condition:
  - condition: state
    entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone
    state: 'off'
action:
  - service: switch.turn_off # (or light.turn_off)
    data: {}
    entity_id: switch.xxxxxxxxxxxx # (or light.xxxxxxxxx)
initial_state: true
mode: single
  • finally, an automation to reset the Aqara ZHA zigbee cluster:
alias: Aqara motion sensor - reset ZHA cluster
description: ''
trigger:
  - entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone
    platform: state
    from: 'off'
    to: 'on'
condition:
  - condition: state
    entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone
    state: 'on'
action:
  - service: zha.set_zigbee_cluster_attribute
    data:
      ieee: '00:15:8d:00:xxxxxxxx'  # your Aqara IEEE
      endpoint_id: 1
      cluster_id: 1280
      cluster_type: in
      attribute: 2
      value: 0
mode: single

Delays are important to avoid ghost switching but can be adjusted or added to better suite your needs.
In this solution the light is turned off after 20 seconds the motion sensor is off.

5 Likes

Excellent wrap up!
ANy idea how to automate occupancy sensor in order to reset toghether with motion sensor?
Or even illuminance…

Actually, to update myself: illuminance works fine, every time motion is updated (5sec), illuminance is updated too.
But reset time for occupancy is still an challenge…

I found that the Aqara motion sensor for the cluster
MotionCluster (Endpoint id: 1, Id: 0x0500, Type: in)
has this cluster command:
init_test_mode (id: 0x0002)
which hopefully might be used to continuously reactivate the 5-second reset working mode that is normally temporarily activated after pairing, so without requiring the hardware hack.

I tried but this command fails as it requires 2 parameters that unfortunately are unknown to me.

Hi,

How do you open up the sensor so you can access the PCB? I have removed the battery, and don’t want to break the casing or interior by forcing it open.

Has anybody that have tried the pencil mod, any reliability issues? I’m considering if I should go with soldering (very inexperienced in soldering) or just use a pencil.
Thanks,
Br,
Tim

You can use a flat spudger between the casing and the piece that holds the battery. The latter is clipped into the casing, by gently making some room between the two and lifting the battery piece you should be able to get it out without much damage (the one shown in the photos below is damaged, the casing broke at its weakest point, below the sensor window; but that’s nothing a drop of super glue can’t fix).

I’m using the pencil hack on all my sensors (about 8 of them), and it has worked reliably for 18+ months.

1 Like

Hi,

Much thanks for the images.
I got this working together with @andrus example.

Having some issues with the sensor not being sensitive enough when sitting down (and moving laterally) might need to tweak some parameters to take into account the amount of time I sit still.

Thanks!
Br,
Tim

Hey it’s still working for you? I have also a aqara sensor and ZHA… but i don’t where to start to change the hardware to let it work every 5 seconds…

See:

1 Like

Has anyone experienced the motion sensor turning on (detecting motion) randomly after applying this hack? My sensor in the mud room keeps going on without anyone around.

To avoid ghost switching you should use an automation to turn off the light not before 20 seconds have passed from the initial sensor activation, like this:

alias: Turn off light if Aqara motion sensor is clear
description: ''
trigger:
  - entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone
    platform: state
    from: 'on'
    to: 'off'
    for: '00:00:20'  # avoid ghost switching on
condition:
  - condition: state
    entity_id: binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone
    state: 'off'
action:
  - service: switch.turn_off # (or light.turn_off)
    data: {}
    entity_id: switch.xxxxxxxxxxxx # (or light.xxxxxxxxx)
initial_state: true
mode: single
1 Like

Not me. The only places I occasionally get random triggers are my garage (which isn’t very windtight) and outside (where sometimes the sensor gets a hit of sunlight on one part of the lens causing it to trigger).

Thanks. I’ll give this a shot.

I purchased mine at the end of Dec 2020, and they reset after 1 min 30 sec.

Wish me luck. Damn I need a magnifying glass after 40+ :flushed:

So I can say that this automation works straight away after restarting HA with deconz/conbee2 after doing the HW mod.

alias: 'Xiaomi Aqara Motion Sensors duration fix'
trigger:
  - platform: homeassistant
    event: start
action:
  - service: deconz.configure
    data:
      entity: binary_sensor.aqara_motion1
      field: "/config"
      data: {"duration": 5}
  - service: deconz.configure
    data:
      entity: binary_sensor.aqara_motion2
      field: "/config"
      data: {"duration": 5}

I see it working in both deconz and HA. :smiley:

1 Like

I did the 5 sec hw hack, added post to change state to off. All works nicely, except that I also get
a false positive after about 90 sec. It seems that it is a quick “flip” between on->off that is very short.

Since I use this in node-red my solution is to add a delay of 1 sec from state change and then do a
“current state” and check if the state is the same. This seems to work, at least for me when doing my tests.
Using Zigbee2mqtt.

Hope this helps someone.

1 Like

Could you please post the flow? That would be very helpful. Thanks.

1 Like

ok, interesting, i didnt know there was a pencil hack too :slight_smile: , i cant solder , so maybe thats a alternative for me
does anyone have a pencil hack picture? do we just need to draw a line with a pencil? is that it?

i also read 2 posts back, that there is a false positive? is everyone having this issue? i dont want to have my light turning off/on every 90 sec later :slight_smile:

[{"id":"1074987e.c027b8","type":"server-state-changed","z":"835ce675.3824c8","name":"Cykelställ PIR","server":"c293cfab.618ab","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.aqara_motion_cyklar_occupancy","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":170,"y":1320,"wires":[["8c427945.b63538"],["8c427945.b63538"]]},{"id":"1849487e.9ff5a8","type":"api-call-service","z":"835ce675.3824c8","name":"Cykelställ Light on","server":"d5fcaec9.30db1","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.shelly_2_5_02_channel_2","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1050,"y":1360,"wires":[[]]},{"id":"38746a61.5b0886","type":"api-call-service","z":"835ce675.3824c8","name":"Cykelställ Light Off","server":"d5fcaec9.30db1","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.shelly_2_5_02_channel_2","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1050,"y":1420,"wires":[[]]},{"id":"b6495d2d.3294e","type":"time-range-switch","z":"835ce675.3824c8","name":"","lat":"55.77352","lon":"12.9887","startTime":"goldenHour","endTime":"sunriseEnd","startOffset":"","endOffset":0,"x":790,"y":1360,"wires":[["1849487e.9ff5a8"],[]]},{"id":"1eacbbf5.6db3c4","type":"delay","z":"835ce675.3824c8","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":800,"y":1420,"wires":[["38746a61.5b0886"]]},{"id":"af08b11d.8f207","type":"ha-api","z":"835ce675.3824c8","name":"Reset State to Off","server":"d5fcaec9.30db1","debugenabled":true,"protocol":"http","method":"post","path":"states/binary_sensor.aqara_motion_cyklar_occupancy","data":"{\"state\":\"off\"}","dataType":"json","location":"payload","locationType":"msg","responseType":"json","x":1050,"y":1300,"wires":[[]]},{"id":"802fbe9.ec03f4","type":"change","z":"835ce675.3824c8","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":1420,"wires":[["1eacbbf5.6db3c4"]]},{"id":"8fd20e3.e0884f","type":"delay","z":"835ce675.3824c8","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":740,"y":1300,"wires":[["af08b11d.8f207"]]},{"id":"8c427945.b63538","type":"delay","z":"835ce675.3824c8","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":1320,"wires":[["c4e21c0d.94383"]]},{"id":"c4e21c0d.94383","type":"api-current-state","z":"835ce675.3824c8","name":"recheck","server":"d5fcaec9.30db1","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.aqara_motion_cyklar_occupancy","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":460,"y":1320,"wires":[["8fd20e3.e0884f","b6495d2d.3294e","802fbe9.ec03f4"],["1eacbbf5.6db3c4"]]},{"id":"c293cfab.618ab","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"d5fcaec9.30db1","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
1 Like

With zigbee2mqtt you don’t need any ugly hacks to avoid ghost switches, you can set occupancy_timeout to 5 seconds as it was written in OP

1 Like