core icon indicating copy to clipboard operation
core copied to clipboard

Tuya Motion detection 'Stop detection' not working

Open coleburg opened this issue 1 year ago • 28 comments

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

coleburg avatar Feb 08 '24 09:02 coleburg

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)

home-assistant[bot] avatar Feb 08 '24 09:02 home-assistant[bot]

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

Eelco66 avatar Feb 08 '24 19:02 Eelco66

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 avatar Feb 12 '24 01:02 astenger

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

astenger avatar Feb 12 '24 01:02 astenger

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 avatar Feb 13 '24 12:02 andylitt

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

andylitt avatar Feb 19 '24 01:02 andylitt

Same problem here.

petoor avatar Feb 19 '24 17:02 petoor

problem exists in latest release today too,

coleburg avatar Feb 22 '24 13:02 coleburg

Still faulty in today release (29/2)

coleburg avatar Feb 29 '24 20:02 coleburg

@frenck please help

coleburg avatar Mar 02 '24 21:03 coleburg

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

coleburg avatar Mar 12 '24 16:03 coleburg

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.

andylitt avatar Mar 20 '24 04:03 andylitt

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 avatar Mar 25 '24 12:03 astenger

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 avatar Mar 25 '24 12:03 astenger

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 avatar Mar 25 '24 12:03 astenger

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 avatar Mar 25 '24 12:03 astenger

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 avatar Mar 26 '24 01:03 astenger

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 avatar Mar 26 '24 01:03 astenger

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 avatar Mar 26 '24 01:03 astenger

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:

  • I found some hint somewhere on the net that if a trigger is set without a from or to state it will be executed every time an event comes in, even if the state does not change. Not sure whether it actually works that way, but it's a good shot.
  • the "restart" mode means that if there is a new PIR event while the automation is in the "delay", it will kill the old one and start a new one, meaning wait another 5 minutes from the most recent event
  • delays under a minute probably don't make sense for this, but YMMV; 5 minutes makes sense for me and my use case.

astenger avatar Mar 26 '24 05:03 astenger

Tested your work around and it works perfectly, thank you

coleburg avatar Mar 26 '24 11:03 coleburg

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

andylitt avatar Apr 14 '24 11:04 andylitt

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

The original problem has not been resolved in multiple new HA versions over the past 5 months.

andylitt avatar Jul 17 '24 08:07 andylitt