QuickTip: deCONZ workaround for hacked Aqara Motion Sensor
If you read this blog entry you’ve probably run into this issue: You just finished setting up your new “5-Second-Hacked” Aqara Motion Sensor (RTCGQ11LM) in deCONZ but now you realize that this thing STILL doesn’t trigger every 5 Seconds… that’s exactly what I just found out…
This isn’t because the sensor doesn’t report new values every 5 seconds, deCONZ actually has a default duration for that sensor which is set to 90 seconds. And the funny catch is: You can’t easily edit this value. And even when you do it’ll reset every few minutes automatically.
Without the hack this would be fine, the sensor goes into sleep after a certain amount of time and won’t detect anything during that period so deCONZ simply respects that hardware “limitation”. However you hacked that sensor to report values every 5 seconds yet deCONZ simply ignores new values for the default 90 seconds and stores the last motion event for that period.
We actually have to use the deCONZ API to set this. There is no other, easier way (as of writing this) to set and store this value which honestly sucks but whatever… they made a lot of other, rather questionable decisions while writing that software but this is out of the scope of this blog entry ;)
So how can we fix this (somewhat easily)? Well, the way I chose to do it is: cURL. Since we can set the duration via a POST request to their API I’ve simply created a bash script that gets started as a service on system startup and runs a “while true” loop every 5 seconds. Yes, this may not be the best way to do this but it certainly is the easiest solution as of now.
Solution
First you need to acquire an API key. You can find a guide on how to do this HERE on their Wiki page. They mention Postman for Chrome, but it doesn’t exist anymore. Rather go HERE and download their Standalone version.
Once done send a GET request to “<deconz-address>/api/<your-api-key>/sensors
“, this will show you all sensors that deCONZ has registered. Search for the Aqara entry and make sure you have the one that also shows the “duration:” setting since there will be 2 different ones.Once done remember the number at the very top of that block, in my case this would be “3“. You can now use a PUT request to set the duration to something lower, like in the above case to 7 seconds. The URL you have to use now is “<deconz-address>/api/<your-api-key>/sensors/3/config
“, the JSON body you have to use is “{ "duration": 7 }
“, of course replace the duration with anything you like. However I think that 7 seconds is a good value to set to give the Motion Sensor some time to reset itself too, you can always set this higher if you encounter problems of course.
Now go back and check the new duration setting by sending a GET request to “<deconz-address>/api/<your-api-key>/sensors/3
“.As you can see it worked! However if you leave it like this it’ll reset after a few minutes again. What we have to do now is to create a cURL request which sends this value every other second. Easily done on Linux!
Simply create a new bash script via “nano deconz-set-duration.sh
“. Don’t forget to “chmod +x deconz-set-duration.sh
” this script, else it won’t work. Once done copy and paste the following text into it, replace the <> values with the ones you want.
#!/bin/bash
while true; do
curl --location --request PUT '<deconz-address>/api/<your-api-key>/sensors/<your-sensor-number>/config' --header 'Content-Type: text/plain' --data-raw '{"duration":7}';
sleep 5;
done
Exit via Ctrl + X, hit “y” and Enter. If you were to run this script manually it’d already set the value. However, once you log off the script will stop, so we have to run it as a service on startup.
To do this run the following command “sudo nano /etc/systemd/system/deconz-set-duration.service
” and paste the below text into this file. Replace the path to the .sh file below.
[Unit]
Description=Sets the deCONZ duration for Motion Sensors to a low seconds value every 5 seconds.
[Service]
ExecStart=<path>/<to>/<your>/<script>/deconz-set-duration.sh
Restart=always
[Install]
WantedBy=multi-user.target
Again exit via Ctrl + X, hit “y” and Enter. Now we need to enable this service, simply use “sudo systemctl enable deconz-set-duration.service
“.
You’re done! The service should now automatically be running on startup and loop every 5 seconds. You can verify this by once again sending a GET request as explained above, the value shouldn’t change anymore.
If you also want to verify that the service is running correctly use “sudo systemctl status deconz-set-duration.service
” which should say “active (running)” on top. The output below shows you if the cURL command has been sent successfully.
Voila! You’re done now :) Enjoy your Motion Sensor updating way faster now!
For the reference of anyone else looking for this information, a fix was recently implemented in deCONZ version V2.05.81 to prevent restarting the deCONZ service from reverting the configuration change.
https://github.com/dresden-elektronik/deconz-rest-plugin/pull/3176