Got my Smart Plug from Tuya now, and Tuya local is seeing it. So that works. Will come back tomorrow to check the motion sensors.
Alright, tested it with the first wifi pir motion sensor. It’s finding it in local tuya, and in this case the status is ‘off’ for lights on and ‘unavailable’ to turn it off. But there is a issue, even in local it takes 7 seconds to turn my light on…
Second doesn’t work either. I think I’ll stick with Z-wave for now.
Thank you @angadsingh and others for this thread on how to get Tuya WIFI sensors working using Ping. Got my two WIFI motion sensors (the same one posted by @alecsandes) working. Being a Noob with Home Assistant and automations, it did take me some effort to get this going. Below are the steps documented as I thought it might help other Noobs like me:
- Install the wifi sensor in the Tuya App. I recommend just stick with Tuya instead of Smarthome. Both are on the same server so keeping all devices it in Tuya is easier.
- Once all working in Tuya, click on the device icon in the app and top left screen which has edit your device name. Click on the edit icon and next page has ‘Device Information’. Tap on that to get the MAC address of the device. The IP address listed is you external IP, so not the one you need for setting up the device in Home Assistant YAML files.
- Finding the IP address from MAC is not straightforward as the device goes to sleep quickly after triggered. Also, once triggered it goes back to sleep for two or four minutes so you cannot locate it . There is a toggle switch at the back of the device which you can setup to be 2 mins instead of 4 min to wake up the device more often. However, that consumes you battery faster so once setup in HA you can make it 4 minutes again.
- Usual Apps like Fing is not able to locate these sensors as these perhaps sleep too quickly for it to be picked up, so don’t waste you time with those.
- Trigger the device (you will see a red led flashing a few times) and then quickly run in windows cmd: arp -a
- This lists the IP address and MAC address and hopefully you will find it IP address there.
- If arp is not able to find the sensor, then go to your router’s interface and find it in the IPs listed there for the MAC address. In my Telstra router, I had to check on the ‘show not connected’ devices to be able to see the sensor listed. Interestingly it appeared in the list of ‘wired’ devices instead of Wifi devices.
- Once located, fix that IP address to the MAC in your router. Otherwise, it changes when device wakes up after a while and you would have to change the YAML file with the new one.
- The YAML code that I used is:
# time sensor used in pingging tuya motion sensors
sensor:
- platform: time_date
display_options:
- 'date_time'
binary_sensor:
- platform: ping
host: 10.0.0.39
count: 1
scan_interval: 1
name: ping_tuya_motion_sensor_front_gate
- platform: ping
host: 10.0.0.38
count: 1
scan_interval: 1
name: ping_tuya_motion_sensor_north_driveway
- platform: template
sensors:
tuya_motion_sensor_front_gate:
friendly_name: "Front Gate Motion Sensor Alarm"
value_template: >-
{{ as_timestamp(states.sensor.date_time.last_changed) -
as_timestamp(states.binary_sensor.ping_tuya_motion_sensor_front_gate.last_changed) < states('input_number.motion_sensor_idle_secs1')|int }}
# Tuya motion sensor North Driveway
tuya_motion_sensor_north_driveway:
friendly_name: "North Driveway Motion Sensor Alarm"
value_template: >-
{{ as_timestamp(states.sensor.date_time.last_changed) -
as_timestamp(states.binary_sensor.ping_tuya_motion_sensor_north_driveway.last_changed) < states('input_number.motion_sensor_idle_secs2')|int }}
input_number:
motion_sensor_idle_secs1:
name: Motion Sensor Idle1
min: 60
max: 600
step: 30
icon: 'mdi:motion-sensor'
motion_sensor_idle_secs2:
name: Motion Sensor Idle2
min: 60
max: 600
step: 30
icon: 'mdi:motion-sensor'
- of course replace with your IP addresses and device names.
Hope this helps others like me. Any errors please comment as I am no expert in this.
Yup, I had the same issue. Honestly, I just gave up on it. I made a sensor using nodemcu and an HC-SR501 using ESPHome and wired it up with a USB adapter. This sensor never goes to sleep since it’s powered via mains and not batteries so response time is instantaneous. The only issue is figuring out how to run a wire from the sensor to a wall outlet.
FYI, I’ve had several motion and door contact sensors integrated into HA using the official cloud based Tuya V2 integration for several months and they worked without issues, no workarounds needed. I recently migrated my setup from the cloud-based official integration to localtuya, and getting the motion sensors to work with them it’s a bit trickier (Cannot add door sensor in home assistant · Issue #770 · rospogrigio/localtuya · GitHub).
Same here. They are on ‘detected’ all the time.
Anything I can try?
Funny thing: The Homey Tuya cloud app uses the same Tuya iot API, and the PIRs work flawless
Make sure you’re using the right codes for on and off. On = ‘pir’, off = ‘none’
Thank you. I’m a rookie, can you reveil a little more how to?
After searching and reading, I think this should be put in configuration.yaml , but I’m clueless how to get it to work.
Edit after 2 nights of reading and fiddling:
I’ve put this into the configurarion.yaml, and sensor changes to ON. Still it won’t change back to OFF…
binary_sensor:
- platform: template
sensors:
binary_sensor.sensor_dining:
friendly_name: "Sensor Dining"
value_template: >-
{% if states('binary_sensor.sensor_dining') == 'pir' %}
{{on}}
{% elif states('binary_sensor.sensor_dining') == '' %}
{{off}}
{% else %}
unknown
{% endif %}
Not quite. You have to specify those codes during the config flow for the sensor in localtuya. No yaml required. Make sure you use lower case. Those strings are basically how Tuya decided to specify motion in their Pir sensors. See images.
Thanks, unfortunately I’m using the native Tuya integration
I’ve tried localtuya, but as none of my lights respond, I deleted it (after days of trying)
The native Tuya integration shows the motion sensors without any issues for me. No modifications needed and no additional yaml, it should create a binary sensor for you right out of the box. When I was using it, motion responded within 3 secs or so. Good luck.
Thank you. It responds well, but it never changes back from pir to none…
If only there is a script which virtually pushes the “Set Status” button with this code…
I would get rid of any template sensors you’ve created related to this sensor. If you’re using the sensor using the Tuya integration, you should have a device that creates three entities, a binary sensor, battery and Tamper. See image below. No need for any additional yaml code.
Kia ora, all.
I’ve just bought a Nextech Wifi PIR Motion Sensor which is a Tuya product. However, it’s still showing up as Unsupported within HA. It’s there, but no sensors are showing
I’m running the latest version of HA via Docker… anyone else having this issue?
btw, I’ve found this thread extremely helpful setting up the ping sensor… but now I feel I’m missing out — haha.
Edit: I give up, there’s several similar open issues from over a year ago: PIR WIFI sensor does not changing statuses in HA (motion/no motion) · Issue #144 · tuya/tuya-home-assistant · GitHub
Thanks.
I wish it would work that way, but the sensor keeps at “detected” state (all 4 of them). I can change the state to Off with the manual tool, but not with any script up 'till now.
We have different sensor types though.
What puzzles me, they worked fine with the previous Tuya V2 integration. Also in the Homey app, which uses exact the same API. That app has a setting for the blind time, 60 seconds or more, which sets the status to Off or ‘not detected’ or such.
This is from the diagnostics report:
"last_changed": "2022-07-08T23:19:37.238355+00:00",
"last_updated": "2022-07-08T23:19:37.238355+00:00"
I just set the state to ‘null’ and only then, it updates it’s state after I made it detect me. All sensors see motion several times a day.
"last_changed": "2022-07-10T23:29:44.937671+00:00",
"last_updated": "2022-07-10T23:29:44.937671+00:00"
I also tried the “ping” workaround, but of no avail.
Also in the Homey app, which uses exact the same API. That app has a setting for the blind time, 60 seconds or more, which sets the status to Off or ‘not detected’ or such.
This is exactly what seems to be missing/broken in HA right now, as per the GH issue #144 you linked. I just checked the Tuya debug tools in their web platform and my sensor does send the “detected” alert to them, but there’s no “off” alert. As explained there, this must be defined by the reading app; as you see, Homey seems to do that correctly, but in HA that feature is either forgotten, neglected, or broken. Let’s wait and hope they pick that up and patch it
I have an old S5 acting as a gateway for one of these tuya wifi motion sensors. I have smart life setup for alert notifications. Then I feed last notification to HA through the app.
There is a delay of .5 to 1 sec. I’ve only had it going for a day, but so far it seems mostly reliable.
I also have a doorbell that will not integrate with HA nicely. I have it’s app signed in on the gateway phone as well. Now I can do whatever I want based on app notifications. So this method pretty much makes anything that works via app notifications work with HA.
Is anybody else doing it this way?
Hi everyone,
I have a question regarding this solution now a few years later. I am having the problem of my Tuya sensor staying detected. I tried the given code but it doesn’t work:
sensor:
- platform: time_date
display_options:
- 'time'
- 'date'
- 'date_time'
- 'date_time_utc'
- 'date_time_iso'
- 'time_date'
- 'time_utc'
- 'beat'
input_number:
'motion_sensor_idle_secs':
initial: 60
min: 10
max: 360
step: 1
binary_sensor:
- platform: ping
host: 192.168.178.241
count: 1
scan_interval: 1
name: binary_sensor.slimme_pit_sensor
- platform: template
sensors:
tuya_motion_sensor_master_bedroom:
friendly_name: "Sensor Gang"
value_template: >-
{{ as_timestamp(states.sensor.date_time.last_changed) - as_timestamp(states.binary_sensor.binary_sensor.slimme_pit_sensor.last_changed) < states('input_number.motion_sensor_idle_secs')|int }}
Are there any workarounds these days?
Clunky, but having just purchased a few of these, you can use virtual devices and the built in Tuya rules engine to create a work around.
Login to Tuya IoT Platform as you did to setup the integration and go to your cloud project
Find the devices tab, where your Tuya devices should be listed
Select add device, virtual device
Select something i.e a switch or bulb
Choose ‘Add to Tuya App Account’
Scan with the Tuya App
Now you have a virtual device and you can build a simple automation to turn the virtual device on and off with motion. My proof of concept is: IF motion detection status ‘alert’ THEN turn on virtual_bulb, wait 20s, turn off virtual bulb.
The bulb shows up in the standard Tuya integration of Home Assistant and you can go ahead and use it like any other motion sensor.
This isn’t perfect as you’re using Tuya automations in the cloud to drive it, but it is a simple way to get wifi motion sensor functionality working as it should.
I would be very interested in your solution because I also have a lot of devices that work in the app but not via the Tuya integration.
Best wishes
Marc