Hi all,
Like a few others he in Australia, I recently purchased some cheap Lenovo / Tuya WiFi motion detectors to use with HA, ALARMO and a couple automations to turn on the lights, where speed isn’t that important. They were on sale for $4 each and by the looks a few fellow Aussies bought them too! They are cheap, they are WiFi but they work good enough for my needs!
Anyway, the issue is though, these detectors need to be added to HA with the official Tuya / Smartlife addons (unless you flash them) and they report a “detected” state the entire time…
So, I wrote a couple automations to fix this and again, thought I’d share with you wonderful folks and post it all here, step by step how I got to work…
The first, “motion_detector_reset_state_after_motion” does as it says on the box, 10 seconds after detecting motion, this will reset the sensor state to clear. The second automation simply runs the first Automation when HA first starts up. I have multiple sensors, so this on HA startup resets all my detectors to clear.
To install you must have the motion detectors installed in Tuya, have HACS and enable & install the python script “set_state.py”.
Install your motion detector into the Tuya addon via the Tuya / Smart life app. I had to click add manually, then select wifi motion sensor. For ease of this, call them “Motion Sensor 1”, “Motion Sensor 2” etc etc.
Edit your HA configuration.yaml and add the following line: python_script:
Create a new automation called “Motion Sensor 1 - Reset State After Motion” and copy & paste the contents of: code-snippets/motion_detector_reset_state_after_motion-AUTOMATION at main · AdamGit69/code-snippets · GitHub
Edit it to suit if you didn’t name your detectors “Motion Sensor 1” etc earlier, otherwise you’ll need to change the two entity_ids to point to your motion detector. You will need to create one of these automations for each one of your detectors.
That’s a nice project. Thanks for sharing with the community.
I would suggest taking on the project of turning this into a couple of blueprints. You are already 85% of the way there, and it is easier for the newer members of the community to click the download button and add the entity names, rather that dive into the world of Github and the text editor.
If you decide to take this on and need any help, feel free to ping me.
Ahh thank you for your kind words, good idea too, I’ve been meaning to learn how to make blueprints, proper cards and stuff but I just haven’t time to learn yet! I just whip these things up for myself mainly, get them working enough for me, figure I’d share and then move on to the next project. lol I will get onto learning blueprints though! Thanks for the prompt to get off my butt and learn.
Bonus:
Here is the automation I use to turn on my lights when motion is detected by one of these devices. This is NOT that fast but it works good enough for places like my doorway, carport or shed. It can take a couple seconds to turn on once motion is detected, so I wouldn’t use it on a staircase for example! lol
Anyway, when motion is detected and is sent to HA, this automation checks first that the light is not already turned on (ie with the switch or whatever), then it turns on the light and waits until no motion is detected for 30 seconds and then turns them off again. If the light was already turned on this will not turn it off. It will only turn the light off again if this automation turned it on. The 30 second time along with the 10 seconds in the above automations means if no motion is detected in roughly 40 seconds, the lights will turn off… If you want to make the light go off quicker edit this time but I suggest a minimum of 30 seconds or you could end up with a disco…
There is a link below to the YAML, I suggest creating a new automation, copy & paste the contents, and then switch to visual editor to find all your device and entity ids.
You will need to edit (in visual as I said is easier):
The when section: edit to the Entity ID of your motion detector and the “to” should be set to detected
The if section: edit the device id to the light you want to check is off. The condition should be XYZ light is off
The do section: Change the first part, the “light turn on” dropdown thingy, to the target device of your light
The wait for 1 trigger part, set your motion sensor device id, the trigger should be XZY STOPPED detecting motion. SET THE DURATION TO 30 SECONDS.
Finally change the “light turn off” part, to the target device of your light.
Thanks for posting this, @Aussie_Adam. Way back when I bought two of these things when they were a slightly more expensive $5 each, but after applying a $10 voucher they ended up being free to me. The price appeared to be about right as they also seemed to be basically e-waste until I gave this a go. It would be nice if they were also supported by Local Tuya but sadly not the case, at least not yet.
Thanks a lot mate @Aussie_Adam (Just made a HA account to send this message haha)
I just picked these up from Bing Lee cause of its price and had no idea how to automate them due to the always motion detected status.
Your instructions worked pretty much perfectly!
Only part I had to change was the part which said The do section: Change the first part, the “light turn on” dropdown thingy, to the target device of your light
When I copied your text into the automation editor it made that part a “Call Service” instead of the standard “Device” where I could pick my light switch status.
But after changing that part at the end the automation worked like a charm.
The Lenovo sensors do have a bit of a delay on them as you mentioned by for $4 each, I can’t complain to be honest.
Much appreciated for the breakdown again, cheers!