Aqara Motion Sensor Hack for 5 sec

Tags: #<Tag:0x00007f326c78b338>

I’ve got an Aqara Motion Sensor paired with ZHA and I’ve modded it to send motion every 5 seconds instead of 2 minutes with this guide:

The behaviour hasn’t changed after completing the mod, and I’ve seen that with Zigbee2mqtt it is required to change occupancy_timeout to work around that:

¿Does something like this exists in ZHA? ¿Is there any workaround available in ZHA so that I can use the mod?


I’m wondering the same thing about the Deconz stick. I have all of my devices using deconz. Did you ever get it working with zha? If so I might just have to switch over

Yes I found the line where the time is set:

I modified it to 5 seconds and it works, but the problem is that I have to change it every time I update Home Assistant

Hi all,

i use hassio version 0.102.3 and want to use “Xiaomi motion sensor hack”:
Currently, if a i connect the 2 points (described in the link), the motion sensor sends always “occupancy=true”, it goes never back to false.

Must i set this state manually or is there any other solutions?
Or what is the best way to achieve it, that the motion sensor detects motion every 10 seconds?

Or works this solution furthermore?

  1. Modded one (two others are not modded, connected to the same gateway) of my aqua sensors (I can see in the Xiaomi Home app that the mod worked)
  2. created a folder ‘custom_components’ in ‘config’ folder
  3. created a folder ‘xiaomi_aqara’ in ‘custom_components’ folder
  4. uploaded and init .py from ‘ ’ to ‘xiaomi_aqara’ folder
  5. restarted home assistant

thank you for your help


Hi. Can your please show me, where is zhaquirks/xiaomi/ init .py file in hassio

It’s in /usr/local/lib/python3.7/site-packages/zhaquirks/xiaomi/ inside the container, but if you want to reset the sensor there’s a better way: Xiaomi Human / Body / Motion Sensor - Timeout
I’ve implemented it on nodered and this way I don’t have to change the source every time home assistant gets updated


thank your very much. This is exactly what I wanted

no soldering needed anymore

I used this method and everything seemed to be working fine. The sensor is reset after 5 seconds and is ready for operation again. But after motion detection and reset after 5 seconds, there are repeated false motion detection after 30 seconds and after 100 seconds . I replaced the python script with rest_command but the result was repeated. I think the sensor sends out three motion detection signals within 2 minutes of motion detection. Maybe I have a defective sensor?

I run hassio 0.105.5 on rpi3b+ with HUSBZB-1 and zha integrations, aquara 2 motion sensor

Today, for the experiment, I removed the jumper i had previously soldered in the motion sensor. Connected automation with a python script that clears the binary sensor after 5 seconds and made a series of observations. Script automation works just like with a soldered jumper. So there is no sense in this jumper. But there is a false triggering a minute after the actual motion is detected. I will have to abandon the script and use the default behavior of the sensor (

I think there is just no hardware solution, setting the state of a binary sensor does nothing with the hardware itself…

It’s the hardware at the end that needs to send a new state , regardless the state of the binary sensor

Could you share the node red flow you’re using to do this please?

It’s not possible with a software setting/automation/configuration… Only possible by modifying the hardware

I’ve already soldered the jumper to my sensors but they don’t seem to be reseting in home assistant every 5 seconds. I’m using ZHA what do I need to do after soldering the jumper?

1 Like

they you could use this example :

Thanks that did the trick. Everything working as expected now.

The state script is no longer available. I would very much appreciated if you could share your node red flow

Here you have, although you have a more complete script on hacs:

# Set the state or other attributes for the entity specified in the Automation Action

inputEntity = data.get('entity_id')
inputStateObject = hass.states.get(inputEntity)
inputState = inputStateObject.state
inputAttributesObject = inputStateObject.attributes.copy()

newState = data.get('state')
if newState is not None:
    inputState = newState
newIcon = data.get('icon')
if newIcon is not None:
    inputAttributesObject['icon'] = newIcon

hass.states.set(inputEntity, inputState, inputAttributesObject

Thank you sir!

Do you have the repo for HACS? Or is it already there? I couldn’t find anything.

I still use the automation.yaml solution wich resets it every 15 seconds. However some sensors have experienced false positive trigger suddenly lately… I noticed it triggers ever 110 minutes (exactly by the minute) a false positive…

I forgot to share Node Red flow, just in case yo need it:

[{"id":"8d5644fa.b4b938","type":"server-state-changed","z":"64c31825.2bb9f","name":"Sensor entrada","server":"f7110cd.9a9c9f","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.sensor_entrada_movimiento","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":140,"y":460,"wires":[["f9fed3f2.c89fb8","3c400ae8.1c9fa6"],[]]},{"id":"f9fed3f2.c89fb8","type":"stoptimer","z":"64c31825.2bb9f","duration":"5","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":320,"y":460,"wires":[["d68441a1.498688"],[]]},{"id":"d68441a1.498688","type":"ha-api","z":"64c31825.2bb9f","name":"","server":"f7110cd.9a9c9f","debugenabled":false,"protocol":"http","method":"post","path":"states/binary_sensor.sensor_entrada_movimiento","data":"{\"state\":\"off\"}","dataType":"json","location":"payload","locationType":"msg","responseType":"json","x":470,"y":460,"wires":[["6c8994d1.03f574"]]},{"id":"f7110cd.9a9c9f","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]