0x5e / homebridge-tuya-platform

Make homebridge-tuya-platform great again.
MIT License
217 stars 66 forks source link

Incorrect state for blind motors #162

Open sadanro100 opened 1 year ago

sadanro100 commented 1 year ago

Hi there, I've got a few Zemismart blind motors here and made a few tests regarding their state. It seems like it's being reported incorrectly when changing their state from another platform, such as Tuya Alexa skill or Tuya app.

Here is an example, in this case I was changing it from Open to Close, status only got updated once the cover closed completely and it went from:

Screenshot 2022-12-19 at 11 06 12

to:

Screenshot 2022-12-19 at 10 45 07

it remained "Opening..." while it was closed until I opened it again, it then went back to "Open".

Here are the logs for when I closed them, (I think this only came through once the blind closed completely):

[19/12/2022, 10:41:43] [TuyaPlatform] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/0bae77cae096a6758163ef02a3cbf1af
protocol = 4
message = {
  "dataId": "b253c096-3ee9-480b-be7c-f7aa5b348793",
  "devId": "eb5cf3d97be677ad8feh9u",
  "productKey": "ybrhmoymnvtdnwie",
  "status": [
    {
      "149": false,
      "code": "wireless_awake",
      "t": "1671457303",
      "value": false
    }
  ]
}
t = 1671457303
[19/12/2022, 10:41:44] [TuyaPlatform] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/0bae77cae096a6758163ef02a3cbf1af
protocol = 20
message = {
  "bizCode": "online",
  "bizData": {
    "time": 1671457304
  },
  "devId": "eb5cf3d97be677ad8feh9u",
  "productKey": "ybrhmoymnvtdnwie",
  "ts": 0
}
t = 1671457304
[19/12/2022, 10:41:45] [TuyaPlatform] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/0bae77cae096a6758163ef02a3cbf1af
protocol = 20
message = {
  "bizCode": "online",
  "bizData": {
    "time": 1671457305
  },
  "devId": "eb5cf3d97be677ad8feh9u",
  "productKey": "ybrhmoymnvtdnwie",
  "ts": 0
}
t = 1671457305
[19/12/2022, 10:41:47] [TuyaPlatform] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/0bae77cae096a6758163ef02a3cbf1af
protocol = 4
message = {
  "dataId": "5f09a04b-2984-41ea-800a-85dcd08ed5f4",
  "devId": "eb04484e5262004823cmxg",
  "productKey": "jzmy5ut0vishwscm",
  "status": [
    {
      "3": 100,
      "code": "percent_state",
      "t": "1671457306",
      "value": 100
    }
  ]
}
t = 1671457306
[19/12/2022, 10:41:47] [TuyaPlatform] [Quarto] Update value 0 => 100 for service = '0000008C-0000-1000-8000-0026BB765291', subtype = undefined, characteristic = '0000006D-0000-1000-8000-0026BB765291'
[19/12/2022, 10:41:47] [TuyaPlatform] [Quarto] Update value 1 => 2 for service = '0000008C-0000-1000-8000-0026BB765291', subtype = undefined, characteristic = '00000072-0000-1000-8000-0026BB765291'
[19/12/2022, 10:42:17] [TuyaPlatform] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/0bae77cae096a6758163ef02a3cbf1af
protocol = 4
message = {
  "dataId": "6600632f-3a69-4eeb-9c31-bcb1ea7a8bcf",
  "devId": "eb04484e5262004823cmxg",
  "productKey": "jzmy5ut0vishwscm",
  "status": [
    {
      "3": 0,
      "code": "percent_state",
      "t": "1671457336",
      "value": 0
    }
  ]
}
t = 1671457336
[19/12/2022, 10:42:17] [TuyaPlatform] [Quarto] Update value 100 => 0 for service = '0000008C-0000-1000-8000-0026BB765291', subtype = undefined, characteristic = '0000006D-0000-1000-8000-0026BB765291'
[19/12/2022, 10:42:17] [TuyaPlatform] [Quarto] Update value 2 => 1 for service = '0000008C-0000-1000-8000-0026BB765291', subtype = undefined, characteristic = '00000072-0000-1000-8000-0026BB765291'

and here are the logs for when I opened them again:

19/12/2022, 10:45:25] [TuyaPlatform] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/0bae77cae096a6758163ef02a3cbf1af
protocol = 4
message = {
  "dataId": "8df8f83b-80b9-4329-8755-59cb5b9468f6",
  "devId": "eb04484e5262004823cmxg",
  "productKey": "jzmy5ut0vishwscm",
  "status": [
    {
      "1": "open",
      "code": "control",
      "t": "1671457523",
      "value": "open"
    }
  ]
}
[19/12/2022, 10:45:49] [TuyaPlatform] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/0bae77cae096a6758163ef02a3cbf1af
protocol = 4
message = {
  "dataId": "a344a42b-bb90-478b-aff7-e20d27c078dd",
  "devId": "eb04484e5262004823cmxg",
  "productKey": "jzmy5ut0vishwscm",
  "status": [
    {
      "3": 100,
      "code": "percent_state",
      "t": "1671457547",
      "value": 100
    }
  ]
}
t = 1671457547
[19/12/2022, 10:45:49] [TuyaPlatform] [Quarto] Update value 0 => 100 for service = '0000008C-0000-1000-8000-0026BB765291', subtype = undefined, characteristic = '0000006D-0000-1000-8000-0026BB765291'
[19/12/2022, 10:45:49] [TuyaPlatform] [Quarto] Update value 1 => 2 for service = '0000008C-0000-1000-8000-0026BB765291', subtype = undefined, characteristic = '00000072-0000-1000-8000-0026BB765291'

Let me know if there's anything else I can do to help. Thanks

0x5e commented 1 year ago

Let me simplify the logs and convert it to state change:

When you close the blind (from another platform?):

{ wireless_awake: false } // ignore
{ percent_state: 100 }
{ percent_state: 0 }

When you open the blind:

{ control: open }
{ percent_state: 100 }

From curtain documentation: https://developer.tuya.com/en/docs/iot/f?id=K9gf46o5mtfyc control represents for turn on/off the curtain percent_state represents for the percent state, 0 for fully closed, 100 for fully opend, I guess. It's weird that no { control: close } received, can you upload the device info json, I want to see if the range of your device's control schema is correct.

sadanro100 commented 1 year ago

Hi there, I'm really sorry for the delay to reply.

"(from another platform?):"

Yes, I controlled it from Tuya app to see what states would be picked up by the plugin, and the logs are from that.

"can you upload the device info json"

Do you mean Tuya IOT > API Explorer > Smart Home Device System > Device Management > Get device details? If so, here you go:

{
  "result": {
    "active_time": 1654712805,
    "biz_type": 0,
    "category": "cl",
    "create_time": 1653365034,
    "icon": "smart/icon/ay1535532217868NsRD0/d303688e83885c9920b0b2dcf3872aa3.png",
    "id": "eb2711cb0da5df89e8ihmb",
    "ip": "189.68.245.196",
    "lat": "-23.6064",
    "local_key": "0837d81abc2d9073",
    "lon": "-46.6592",
    "model": "",
    "name": "Sacada",
    "online": true,
    "owner_id": "70503222",
    "product_id": "jzmy5ut0vishwscm",
    "product_name": "zemismart curtain motor",
    "status": [
      {
        "code": "control",
        "value": "close"
      },
      {
        "code": "percent_control",
        "value": 26
      },
      {
        "code": "percent_state",
        "value": 30
      },
      {
        "code": "control_back_mode",
        "value": "forward"
      },
      {
        "code": "work_state",
        "value": "opening"
      },
      {
        "code": "situation_set",
        "value": "fully_open"
      },
      {
        "code": "fault",
        "value": 0
      }
    ],
    "sub": false,
    "time_zone": "-03:00",
    "uid": "az1651931460713uDVji",
    "update_time": 1670074686,
    "uuid": "74b8e7c2e8e1c6d8"
  },
  "success": true,
  "t": 1671649449016,
  "tid": "3f6d7d24816211ed8bf3266109e39bbb"
}
0x5e commented 1 year ago

It's okay, I'm also busy these days, I locate see this issue after chrismas. Thanks.

0x5e commented 1 year ago

I've changed the piority order when getting current state, percent_state > control, please have a try.

sadanro100 commented 1 year ago

Hi, it doesn't seem to have helped. It shows as "opening..." (indefinitely) when I close it from tuya app.

0x5e commented 1 year ago

OK... So what's the last status when your blind is fully closed/opened? I guess percent_control and percent_state should equals to 0 or 100 when they are stopped.

0x5e commented 1 year ago

https://developer.tuya.com/en/docs/iot/s?id=K9gf48r5zjsy9

The mainly problem is the documentation is not detailed enough, and I want to fully understand the mean of control, percent_control and percent_state these 3 datapoints. Is it convient for you to use tuya website device debugging tool, and have some try using web to control the device?

0x5e commented 1 year ago

https://github.com/0x5e/homebridge-tuya-platform/issues/179#issuecomment-1367086209 I guess my thoughts for percent_control is wrong, please have a test. the closing and opening process is not avaliable with the virtual device to testing.

sadanro100 commented 1 year ago

Hi, just updated to v1.7.0-beta.18.

I've got 4 motors, one of them is set to Forward and the resto to Back. The one that is set to Forward seems to be working fine, the rest have inconsistent statuses, they don't update their status when configured from Tuya app and when they do work, they are inverted, if the curtains are closed, they are displayed as opened and all the behaviour is inverted as well. When they do pick status changes because I changed from Tuya app or Alexa, they stay in closing... or opening... states indefinitely.

0x5e commented 1 year ago

I'm going to revert of the "reverse motor state": https://github.com/0x5e/homebridge-tuya-platform/issues/179#issuecomment-1367922879

After beta.20 (not released yet), if some of your motor has wrong on/off state, please use manual config: https://github.com/0x5e/homebridge-tuya-platform/blob/develop_1.7.0/ADVANCED_OPTIONS.md#reverse-curtain-motors-onoff-state

for the infinite opening/closing issue, can you help me verify the last state?

OK... So what's the last status when your blind is fully closed/opened? I guess percent_control and percent_state should equals to 0 or 100 when they are stopped.