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 directory called “python_scripts” under your main HA install directory. ie: /homeassistant/python_scripts. Create a new file called “set_state.py” and copy & paste the contents of:
code-snippets/motion_detector_set_state.py at c8bfaec1adf1166fb0a14da3b360afcebad0eeb4 · AdamGit69/code-snippets · GitHub
Save file and reboot HA. -
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. -
Create another new automation called “Motion Detector Reset All States On Startup” and copy & paste the contents of:
code-snippets/motion_detector_reset_all_states_on_startup-AUTOMATION at main · AdamGit69/code-snippets · GitHub
Edit it to suit, changing the entity_ids to point to your automation(s) you created in step 4.
And that’s it, your motion detectors should now function as you’d expect…
All files and the instructions are on my GitHub here:
More info on the set_state.py python script can be found here:
Happy HA’ing
EDIT: SEE MY COMMENT BELOW FOR MY AUTOMATION TO TURN ON AND OFF LIGHTS.