home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.88k stars 28.98k forks source link

Tuya Motion detection 'Stop detection' not working #109972

Open coleburg opened 5 months ago

coleburg commented 5 months ago

The problem

Motion detection using tuya works when starting motion, but stop motion does not trigger, if you refresh the tuya app, it resets to clear. Motion triggers corretly but gets stuck in detected. Does not ever clear.

What version of Home Assistant Core has the issue?

core-2024.2.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Tuya

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tuya/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 5 months ago

Hey there @tuya, @zlinoliver, @frenck, mind taking a look at this issue as it has been labeled with an integration (tuya) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `tuya` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign tuya` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


tuya documentation tuya source (message by IssueLinks)

Eelco66 commented 5 months ago

Hi Coleburg, because of some limitations with the zigbee tuya motion sensors I decided to install them directly with a zigbee stick through ZHA in Home assisitant. You will have to look for the custom quirks and install these in Home Assisitant. After some installation hurdles it works fine, and so I am able to use the Tuya sensors to drive IKEA, Sonoff and Tuya devices. regards Eelco

astenger commented 5 months ago

This is an issue for me as well. It worked fine with the previous integration, but with the 2024.02 update this does not work any more. I do use a network based tuya zigbee GW for these motion sensors.

astenger commented 5 months ago

diagnostics for one of the sensors: tuya-a15feb06f42f06a14e7862194e9b11ef-pir-server-291fa2ff69598de7624c8fd37773b263.json

astenger commented 5 months ago

diagnostics for the zigbee gw: tuya-a15feb06f42f06a14e7862194e9b11ef-zigbeegw1-d3667acd2ff5a6d1016e4ad55c6dd218.json

astenger commented 5 months ago

If there is any other info that I can provide please let me know. Thank you for your help with this!

andylitt commented 4 months ago

I too have this issue with 2 x different brand Tuya motion detectors. Once motion is detected, the detection state stays on and never resets/clears to off. In the the Tuya app itself, the state changes correctly. This is not reflected in HA.

andylitt commented 4 months ago

Diagnostics for each of the sensors tuya-474465d782ca872536bbece6cf33c7c6-Verandah PIR-3e1f3e0b14ca2e0d1909c048103edb61.json And the other tuya-474465d782ca872536bbece6cf33c7c6-Shed PIR-63d4c5abfd403881702c76411e516727.json

andylitt commented 4 months ago

Hi, any traction on this? Most of my automations rely on motion sensor activations, so until this is resolved, my HA is basically useless.

petoor commented 4 months ago

Same problem here.

coleburg commented 4 months ago

problem exists in latest release today too,

coleburg commented 4 months ago

Still faulty in today release (29/2)

coleburg commented 4 months ago

@frenck please help

coleburg commented 4 months ago

Still same in Core 2024.3.0 Supervisor 2024.03.0 Operating System 12.0 Frontend 20240306.0

andylitt commented 3 months ago

Copied from #110996 Upgraded to 2024.3.1 Tuya motion detector state now changed from "Detected" to "Clear", probably because of HA restart after upgrade, however they now do not register detections. Constantly show "clear". Detections are registering in Tuya but not HA. Have reloaded Tuya integration. No difference. Anything else I can try? EDIT: Situation seems worse actually. One of my sensors just registered a detection, and the state is now stuck on "Detected" as per the original issue. Appears HA reflection of Tuya PIR states is really messed up now.

astenger commented 3 months ago

Interestingly enough I have one tuya motion sensor on the same hub as the others that does seem to work just fine. This is a different model compared to the others that are not working. However, the only relevant difference in the diagnostics file seems to be that this device has a pir_sensitivity attribute.

tuya-a15feb06f42f06a14e7862194e9b11ef-pir-ensuite-edc38486abc57cbdf28b359bd7756dbe.json

astenger commented 3 months ago

The behaviour for me for the affected devices over the past few updates is as as initially described. After a HA reboot status goes to "motion detected" once and then stays there until the next HA reboot.

astenger commented 3 months ago

Is there a way to live monitor data sent from a device to the hub and or the messages sent from the hub to HA?

astenger commented 3 months ago

I was using the developer based account when it was working. I am wondering whether one of the mappings does not match any more. When I go to the device logs on iot.tuya.com, the Event Details are named slightly different: "State" "Motion Detection" (on the one where it never clears) vs "PIR state" "Motion detector" (on the one that works) "State" "Period after IR detection" (on the one where it never clears) vs "PIR state" "No one" (on the one that works)

Screenshot 2024-03-25 at 10 18 37 pm

Screenshot 2024-03-25 at 10 19 11 pm

astenger commented 3 months ago

I enabled the debug log for the tuya integration and it appears that the "broken" devices only send PIR detection events ('pir': 'pir') whereas the one "working" device does send detection and non-detection events ('pir': 'none').

Was there a HA side piece of code older that cleared the PIR status for these "broken" devices after NOT receiving a 'pir': 'pir' event for a minute or two minutes?

Here is a piece of the logs:

2024-03-26 10:37:11.786 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb39419defea24e9cpvzb: {'pir': 'pir', 'battery_percentage': 49}
2024-03-26 10:37:55.002 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf75d3b030f0f41409dnkk: {'pir': 'pir', 'battery_percentage': 52}
2024-03-26 10:37:56.532 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb199e6451ae1c9abmleo: {'pir': 'pir', 'battery_percentage': 15}
2024-03-26 10:38:12.137 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb39419defea24e9cpvzb: {'pir': 'pir', 'battery_percentage': 49}
2024-03-26 10:38:31.938 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb39419defea24e9cpvzb: {'pir': 'pir', 'battery_percentage': 49}
2024-03-26 10:38:37.661 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:38:38.175 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf5a3e941debc24a7cygfz: {'pir': 'pir', 'battery_percentage': 78}
2024-03-26 10:38:49.117 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfd702f2d07642d0dckavh: {'pir': 'pir', 'battery_percentage': 100, 'pir_sensitivity': 'high'}
2024-03-26 10:38:55.306 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf75d3b030f0f41409dnkk: {'pir': 'pir', 'battery_percentage': 52}
2024-03-26 10:39:04.962 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfd702f2d07642d0dckavh: {'pir': 'none', 'battery_percentage': 100, 'pir_sensitivity': 'high'}
2024-03-26 10:39:07.183 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb199e6451ae1c9abmleo: {'pir': 'pir', 'battery_percentage': 15}
2024-03-26 10:39:32.498 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb39419defea24e9cpvzb: {'pir': 'pir', 'battery_percentage': 49}
2024-03-26 10:39:37.982 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:39:38.378 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf5a3e941debc24a7cygfz: {'pir': 'pir', 'battery_percentage': 78}
2024-03-26 10:39:50.579 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb39419defea24e9cpvzb: {'pir': 'pir', 'battery_percentage': 49}
2024-03-26 10:40:02.840 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:40:03.198 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf5a3e941debc24a7cygfz: {'pir': 'pir', 'battery_percentage': 78}
2024-03-26 10:40:06.169 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf624628193fdb90f4mueo: {'pir': 'pir', 'battery_percentage': 68}
2024-03-26 10:40:07.761 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb199e6451ae1c9abmleo: {'pir': 'pir', 'battery_percentage': 15}
2024-03-26 10:40:24.841 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfe0edb64b5f28cca9qz3q: {'pir': 'pir', 'battery_percentage': 65}
2024-03-26 10:40:50.842 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb39419defea24e9cpvzb: {'pir': 'pir', 'battery_percentage': 49}
2024-03-26 10:41:03.216 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:41:03.570 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf5a3e941debc24a7cygfz: {'pir': 'pir', 'battery_percentage': 78}
2024-03-26 10:41:06.596 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf624628193fdb90f4mueo: {'pir': 'pir', 'battery_percentage': 68}
2024-03-26 10:41:20.489 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf5a3e941debc24a7cygfz: {'pir': 'pir', 'battery_percentage': 78}
2024-03-26 10:41:33.419 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf624628193fdb90f4mueo: {'pir': 'pir', 'battery_percentage': 68}
2024-03-26 10:41:36.232 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:41:40.035 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb39419defea24e9cpvzb: {'pir': 'pir', 'battery_percentage': 49}
2024-03-26 10:42:20.764 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf5a3e941debc24a7cygfz: {'pir': 'pir', 'battery_percentage': 78}
2024-03-26 10:42:36.562 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:42:40.362 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb39419defea24e9cpvzb: {'pir': 'pir', 'battery_percentage': 49}
2024-03-26 10:43:33.383 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf624628193fdb90f4mueo: {'pir': 'pir', 'battery_percentage': 68}
2024-03-26 10:43:34.336 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf624628193fdb90f4mueo: {'pir': 'pir', 'battery_percentage': 68}
2024-03-26 10:44:16.028 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf5a3e941debc24a7cygfz: {'pir': 'pir', 'battery_percentage': 78}
2024-03-26 10:44:16.984 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:44:34.726 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf624628193fdb90f4mueo: {'pir': 'pir', 'battery_percentage': 68}
2024-03-26 10:44:46.395 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfe0edb64b5f28cca9qz3q: {'pir': 'pir', 'battery_percentage': 65}
2024-03-26 10:45:16.382 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf5a3e941debc24a7cygfz: {'pir': 'pir', 'battery_percentage': 78}
2024-03-26 10:45:17.318 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:46:24.752 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:47:03.820 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf5a3e941debc24a7cygfz: {'pir': 'pir', 'battery_percentage': 78}
2024-03-26 10:47:05.655 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb39419defea24e9cpvzb: {'pir': 'pir', 'battery_percentage': 49}
2024-03-26 10:47:18.680 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfd702f2d07642d0dckavh: {'pir': 'pir', 'battery_percentage': 100, 'pir_sensitivity': 'high'}
2024-03-26 10:47:25.237 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:47:46.193 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfd702f2d07642d0dckavh: {'pir': 'none', 'battery_percentage': 100, 'pir_sensitivity': 'high'}
2024-03-26 10:47:50.509 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
2024-03-26 10:48:03.417 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfd702f2d07642d0dckavh: {'pir': 'pir', 'battery_percentage': 100, 'pir_sensitivity': 'high'}
2024-03-26 10:48:04.197 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf5a3e941debc24a7cygfz: {'pir': 'pir', 'battery_percentage': 78}
2024-03-26 10:48:05.960 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfb39419defea24e9cpvzb: {'pir': 'pir', 'battery_percentage': 49}
2024-03-26 10:48:41.630 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bfd702f2d07642d0dckavh: {'pir': 'none', 'battery_percentage': 100, 'pir_sensitivity': 'high'}
2024-03-26 10:48:50.848 DEBUG (Thread-10 (_thread_main)) [homeassistant.components.tuya] Received update for device bf7b55cbb22e64e4157tmv: {'pir': 'pir', 'battery_percentage': 51}
astenger commented 3 months ago

The diagnostics json for a "broken" device does list "pir" and "none" as values in the data.status_range.pir.value.range section of the JSON. I wonder if the HA side code changes behaviour and does the HA side reset if the value range only lists "pir" and NOT "none". Can this be manually overridden for a particular device for testing? If so, how?

astenger commented 3 months ago

Here's the JSON section I mentioned above:

"data": {
    "endpoint": "https://apigw.tuyaeu.com",
    "terminal_id": "1707437824919KicFHm",
    "mqtt_connected": true,
    "disabled_by": null,
    "disabled_polling": false,
    "id": "bfb39419defea24e9cpvzb",
    "name": "pir-andy",
    "category": "pir",
    "product_id": "b5g40alm",
    "product_name": "PIR",
    "online": true,
    "sub": true,
    "time_zone": "+10:00",
    "active_time": "2023-05-28T05:13:49+00:00",
    "create_time": "2023-05-28T05:13:49+00:00",
    "update_time": "2023-05-28T05:13:49+00:00",
    "function": {},
    "status_range": {
      "battery_percentage": {
        "type": "Integer",
        "value": {
          "unit": "",
          "min": 0,
          "max": 100,
          "scale": 0,
          "step": 1
        }
      },
      "pir": {
        "type": "Enum",
        "value": {
          "range": [
            "pir",
            "none"
          ]
        }
      }
    },
astenger commented 3 months ago

I think I found a workaround.

This uses a python script that allows to set arbitrary states on entities. I got the script from here: https://github.com/rodpayne/home-assistant/blob/88875142d709ed9f0aa738d68f61ab533c6eb9d5/.homeassistant/python_scripts/set_state.py

I installed the script a while ago at: config/python_scripts/set_state.py

along with an entry in: config/python_scripts/services.yaml

set_state:
  name: set arbitrary states
  description: https://github.com/rodpayne/home-assistant/blob/88875142d709ed9f0aa738d68f61ab533c6eb9d5/.homeassistant/python_scripts/set_state.py
  fields:
    entity_id:
      description: the entity id to set
      example: binary_sensor.pir_server
    allow_create:
      description: do not use
    state:
      description: new state to set
      example: "off"

More documentation on installing python scripts: https://www.home-assistant.io/integrations/python_script/

Once the script is installed, you should be able to use it in automations.

Here is the yaml of the automation I use:

alias: pir-server-state-reset
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.pir_server
condition: []
action:
  - delay:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - service: python_script.set_state
    metadata: {}
    data:
      entity_id: binary_sensor.pir_server
      state: "off"
mode: restart

And copy paste for a separate automation for all PIR sensors that are broken.

Notes:

coleburg commented 3 months ago

Tested your work around and it works perfectly, thank you

andylitt commented 2 months ago

I've given up on an official fix and have also installed the work around, which works for me also. Thank you.