Tuya motion sensor is not supported in Home Assistant

if you have Zigbee PIR sensors, buy a Zigbee dongle and use Zigbee2MQTTor ZHA. A ping to a Zigbee sensor does not work.

It’s now supported along with the water leak sensors :grinning::grinning::grinning::+1::+1::+1:

2 Likes

it is true that it seems to work and I have also used the ping sensor for a long time but then I know or notice that sometimes the sensor connects to the wifi even if there is no passage, I have proof of this because I compared the ping sensor with tuya app alerts and in fact there was no alert

My PIR sensor is now shown in the dashboard. Though it just always says “detected”. Presumably I need to find somewhere in the config to put delay_off: 60 or something

Thank you HDDBlackguard!

Your solution works!

fyi…I added some code diffs here on how to add PIR support to the new Tuya Integration for some cheap Battery based Tuya Cameras I obtained very cheaply ( I am monitoring battery life to see how well it works ) :

These cameras have a “wireless_awake” boolean status that can be keyed off to know if the camera has woken up due to PIR activity.

I will shortly start work to see if there is any way to use the Tuya entity “movement_detect_pic” to do the same for non-pir cameras . Motion detection seems to come directly from the device, and not offered as a status via Tuya IoT Core API .

For PIR cameras, the above seems to be perfect.

Which water leak sensors do you use?

US $7.75 39%OFF | AVATTO Tuya WiFi Water Leak Sensor, Water Leak Detector, Smartlife APP Notification Alerts,Water Flood Leak Alarm Home Security

Hi All,

Have you succeeded to add this motion sensor as local tuya?
image

I get the following error in the logs

2021-12-19 23:59:05 ERROR (MainThread) [custom_components.localtuya.common] [eb5...qui] Connect to 172.17.1.41 failed
Traceback (most recent call last):
  File "/config/custom_components/localtuya/common.py", line 141, in _make_connection
    self._interface = await pytuya.connect(
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 637, in connect
    _, protocol = await loop.create_connection(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1056, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect
    return await fut
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 537, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('172.17.1.41', 6668)

Thank you!

It is not supported by any local tuya solutions other than ping sensor.

This worked for me too.
I have Fritzbox which also supports this.

Sorry guys for a real noob question, but what is Tuya’s PIR sensors called on your router??

Could it be ESP_194887?? Trying to find the IP-address for mine…

EDIT: Like was alluded to above these little buggers weren’t that easy to find on the router. I got a ton of Tuya devices and my router is crowded with these esp… devices, but after finding their MAC-addresses in the Tuya app it was a walk in the park. The MAC-address is available up in the right corner when you chose to change the device’s name… :wink:

So I got the Motion sensor going. But it’s a bit laggy, doesn’t always work and often it connects after about 2-4 sec. I have two PIRs for lights in a stair, one on each end.

These are my settings:


alias: Trappbelysning on
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.trappa1_pir
    to: 'on'
  - platform: state
    entity_id: binary_sensor.trappa2_pir
    to: 'on'
condition:
  - condition: sun
    after: sunset
action:
  - type: turn_on
    device_id: 2752e2591b0331eb8cb4efc2ebda092e
    entity_id: switch.smart_switch_trappa_switch_1
    domain: switch
  - type: turn_on
    device_id: 2ffcc02a4bcb201954de89e2027c48bc
    entity_id: switch.tuya_on_off_switch_1
    domain: switch
mode: single

And:


alias: Trappbelysning av
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.trappa1_pir
    to: 'off'
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - platform: state
    entity_id: binary_sensor.trappa2_pir
    to: 'off'
    for:
      hours: 0
      minutes: 30
      seconds: 0
condition: []
action:
  - type: turn_off
    device_id: 2752e2591b0331eb8cb4efc2ebda092e
    entity_id: switch.smart_switch_trappa_switch_1
    domain: switch
  - type: turn_off
    device_id: 2ffcc02a4bcb201954de89e2027c48bc
    entity_id: switch.tuya_on_off_switch_1
    domain: switch
mode: single

Anyone see any room for improvement?

Just ran into this thread and wanted to share my two cents. I configured this Tuya sensor in the Smartlife app and from the Tuya IoT portal, managed to snag the Device ID and the Local Key. Once done, it’s a simple matter to configure the sensor in Local Tuya (not the official Tuya integration). The first problem which I came across was adding the sensor to Local Tuya, which always came up with “An unexpected error has occured”. After a lot of troubleshooting, I stumbled upon the same conclusion as someone here already mentioned - these devices are usually in sleep/low power mode. When motion is detected, they wake up, connect to WiFi and then trigger the routine/scene in Smartlife and then go back to sleep.

So here’s how to add this sensor in Local Tuya. When you get the error adding the device, just trigger the device. When it connects to WiFi, add the device then and you’ll be able to get by. Configure it as a Binary Sensor with Device Class as Motion and we’re done…

…Not quite. You see, when the device goes to sleep, the device will be shown as “Unavailable” in Home Assistant. However when motion is detected, you will see the device online with the status as “Clear”. But here’s the beauty of things. “Unavailable” and “Clear” are the staes of the sensor when it goes offline and comes online respectively. Since the integration is local, the status updates within 1-2 seconds. You can thus create automations where the device state “Unavailable” can be used when no motion is detected while device state “Clear” can be used when motion is detected. See example code below:

alias: 'Test '
description: ''
mode: single
trigger:
  - platform: state
    entity_id: binary_sensor.pir_sensor
    to: Clear
condition: []
action:
  - service: light.turn_on
    target:
      entity_id: light.bedroom_bulb_1

Hope this helps.

1 Like

Hi,

Can you tell me what for PIR sensor you got? Model/ maybe aliexpress link or? :slight_smile:
My PIR pings 2 times and goes to sleep which is to short to add it on localtuya.

Its wifi?

It’s a generic Chinese WiFi based sensor.

Will look at it then, I added this in my yaml:

localtuya:
  host: 192.168.0.226
  device_id: 8608XXXXXXXXXX
  local_key: bcXXXXXXXXXXX
  friendly_name: Tuya Device
  protocol_version: "3.3"
  entities:
    - platform: binary_sensor
      friendly_name: PIR Status
      id: 1
      device_class: motion
      state_on: "true" # Optional
      state_off: "false" # Optional

No succes for now :frowning:.

Logger: custom_components.localtuya.common
Source: custom_components/localtuya/pytuya/__init__.py:637
Integration: LocalTuya integration (documentation, issues)
First occurred: 08:45:47 (11 occurrences)
Last logged: 08:56:01

[860...32e] Connect to 192.168.0.226 failed
Traceback (most recent call last):
  File "/config/custom_components/localtuya/common.py", line 141, in _make_connection
    self._interface = await pytuya.connect(
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 637, in connect
    _, protocol = await loop.create_connection(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1056, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 1041, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 955, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 502, in sock_connect
    return await fut
  File "/usr/local/lib/python3.9/asyncio/selector_events.py", line 537, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
OSError: [Errno 113] Connect call failed ('192.168.0.226', 6668)

Do you have the latest version of local tuya? 3.2.4?

I have not configured it via YAML but via the UI. However your logs state that it failed to connect. You sure the IP address of the device is correct? Are you able to ping the device?

Yes, and yes. Via the UI I can’t find it so I can’t add it. I will get a plug with energy meter today so I can test it if I add it to see if the local tuya sees that one. Tomorrow I receive Tuya motion sensor and another one to test that to see which works.

If motion is triggered, I see 2 pings and then it goes sleeping again.