Aqara Motion Sensor Hack for 5 sec

Hi all,

what is the best way to reset the value to occupancy = no with hassio and node red? i dont find a good solution for me, can you give me a description of the solution?

Thank you

best regards

Mathias

@luetter I’m using 60 seconds occupancy=0. I have that configured with zigbee2mqtt, which works best for me. I don’t have a usecase where I want to switch on a light or something for a shorter period then 60 seconds, this is how I determined the time.

For me, none of the above methods work. I made the hardware modification to make the sensor update every 5 seconds. That worked. I can see in the log of my aqara gateway that the sensor recognizes every 5 seconds a new movement.

I used the python script to set the sensor state in home assistant to ‘off’. This worked, but after 5 seconds, the sensor state in home assistant will not turn to ‘on’ again even the sensor has regonized a movement (i can control it via the logs in the aqara gateway). I still have to wait 2 - 3 minutes before i can use the sensor in home assistant again.

Do i need to integrate the sensor via zigbee2mqtt or any other solution? Does the hack via the integration via the aqara gateway not work?

After a lot of testing I found a way to get this working for my setup by making changes in the source code for the motion sensor.

First, I changed the reset interval of the sensor to 10 seconds in this line.
Unfortunately this did not work. The sensor state has not been changed back to “off” within 10 seconds (i tooks about 3 minutes, dont now whats wrong there…)

Then I used the python script as mentioned above in my automation to manually reset the sensor state. This seems to work. The sensor state was reseted to “off”. But unfortunately no motion was recognized for the next 2 - 3 minutes.

Then, after a lot of logging, i found this line which seems to control if my automation gets triggered or not. I changed the return value to True. Now in combination with the python script everything works as expected.

Hopefully didnt break anything …

is use the aqara motion sensor hack within Deconz.
Is ZHA also useable with this hack? are there people who did this within ZHA?
I tried last year ZHA but i had issues with the motion sensors that they made false triggers.
dont know if that is already solved??

I think I found the solution to the ghost switches and posted here: https://github.com/zigpy/zha-device-handlers/issues/523#issuecomment-744746599

Basically the solution is to reset the state in ZHA, not in HA. This is the yaml to change the state (replace IEEE with the sensor address):

service: zha.set_zigbee_cluster_attribute
data:
  ieee: '00:15:8d...'
  endpoint_id: 1
  cluster_id: 1280
  cluster_type: in
  attribute: 2
  value: 0
3 Likes

Just used this code in my sensor reset routine in node red and it works flawlessly (at least for the last 30 minutes I’ve been testing it). No more ghost triggers even using a 5s reset delay! Thanks!!!

nice that was the number 1 reason i choose deconz over ZHA
but now fixed. going to test this in the future

Is there anyway to do this without the hardware hack? Just not confident in solder such a small board :frowning: I use Deconz and Conbee

The hardware hack is needed. You can use a 4B pencil, but soldering is more reliable.

Also a feedback from my side:

I did the hardware mod and use ZHA (with a zigbee dongle).
I also use Node Red and this simple json post with state off did the the job.
No appdaemon needed, no flickling of code.
Thanks for sharing!

And when I understand it correct the “ghost false positive” are also now fixed:

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.

6 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