0x5e / homebridge-tuya-platform

Make homebridge-tuya-platform great again.
MIT License
222 stars 67 forks source link

deviceOverrides doesn't work for Irrigator devices #327

Open el-lsan opened 1 year ago

el-lsan commented 1 year ago

Prerequisite

Cache

Version

v1.7.0-beta.45

Device Infomation JSON File

{
    "active_time": 1687169768,
    "biz_type": 18,
    "category": "sfkzq",
    "create_time": 1687169768,
    "icon": "smart/icon/ay1501578980436KOuNc/f922fa59436bd4ac23527b9a062b4365.png",
    "id": "bfa2cbb51bf5XXXXXXXXXX",
    "model": "SOP10",
    "name": "Water Timer",
    "online": true,
    "owner_id": "14227387",
    "product_id": "nxquc5lb",
    "product_name": "Smart Water Timer",
    "status": [
      {
        "code": "battery_percentage",
        "value": 48
      },
      {
        "code": "countdown",
        "value": 0
      },
      {
        "code": "smart_weather",
        "value": "sunny"
      },
      {
        "code": "switch",
        "value": false
      },
      {
        "code": "time_use",
        "value": 74
      },
      {
        "code": "use_time_one",
        "value": 2
      },
      {
        "code": "weather_delay",
        "value": "cancel"
      },
      {
        "code": "work_state",
        "value": "idle"
      }
    ],
    "sub": true,
    "time_zone": "+02:00",
    "uid": "eu1595272588065kDRmA",
    "update_time": 1687176556,
    "uuid": "98ea61afdbd30e77",
    "schema": [
      {
        "code": "battery_percentage",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "%",
          "min": 0,
          "max": 100,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "countdown",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "unit": "s",
          "min": 0,
          "max": 86400,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "smart_weather",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "sunny",
            "cloudy",
            "rainy"
          ]
        }
      },
      {
        "code": "switch",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "time_use",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "unit": "s",
          "min": 0,
          "max": 2592000,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "use_time_one",
        "mode": "ro",
        "type": "Integer",
        "property": {
          "unit": "s",
          "min": 0,
          "max": 86400,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "weather_delay",
        "mode": "rw",
        "type": "Enum",
        "property": {
          "range": [
            "cancel",
            "24h",
            "48h",
            "72h"
          ]
        }
      },
      {
        "code": "work_state",
        "mode": "ro",
        "type": "Enum",
        "property": {
          "range": [
            "auto",
            "manual",
            "idle"
          ]
        }
      }
    ]
  },

Device Control Mode

DP Instruction

Logs

If I try to turn on and the Irrigator from the Homekit app, I get the following logs in homebridge and the irrigator doesn't start:

[19/06/2023, 13:42:29] [Tuya] [TuyaOpenAPI] Request:
method = post
endpoint = https://openapi.tuyaeu.com
path = /v1.0/devices/bfa2cbb51bf5605455enzt/commands
query = null
headers = {
  "t": "1687174949401",
  "client_id": "vcqpaafjv9k7qkXXXXXX",
  "nonce": "7b84b963-4cfe-427c-bdb4-b8e4c7dfb8ad",
  "Signature-Headers": "client_id",
  "sign": "EBAB4A5C16A7E5F5C5CF75DBDBD8DF9D1E873B7109C03843D4695C4EEEC5XXXX",
  "sign_method": "HMAC-SHA256",
  "access_token": "42d2f2f1b96bc44108196aXXXXXXXXXX",
  "lang": "en",
  "dev_lang": "javascript",
  "dev_channel": "homebridge",
  "devVersion": "1.7.0-beta.45"
}
body = {
  "commands": [
    {
      "code": "switch",
      "value": true
    }
  ]
}
[19/06/2023, 13:42:30] [Tuya] [TuyaOpenAPI] Response:
path = /v1.0/devices/bfa2cbb51bf5605455enzt/commands
data = {
  "result": true,
  "success": true,
  "t": 1687174950096,
  "tid": "5f35211a0e9611ee9b65f25b5112df17"
}
[19/06/2023, 13:42:34] [Tuya] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/8d54cd7e02d63d7c7e22fbXXXXXXXXXX
protocol = 4
message = {
  "dataId": "1c44a124-3f61-4a46-846c-bbfcf40b8884",
  "devId": "bfa2cbb51bf5605455enzt",
  "productKey": "nxquc5lb",
  "status": [
    {
      "16": "AA=="
    }
  ]
}
t = 1687174952
[19/06/2023, 13:42:34] [Tuya] [Water Timer] [Valve/switch/InUse] Update value: 0 => 1
[19/06/2023, 13:42:34] [Tuya] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/8d54cd7e02d63d7c7e22fbXXXXXXXXXX
protocol = 4
message = {
  "dataId": "a88c197f-e1a4-4a4d-8f03-c546fe39701c",
  "devId": "bfa2cbb51bf5605455enzt",
  "productKey": "nxquc5lb",
  "status": [
    {
      "17": "AAADwAAFf2QBAAAAAAABAhwABH9kAQAAAAAAAgUoAAR/ZAEAAAAAAA=="
    }
  ]
}
t = 1687174952
[19/06/2023, 13:42:38] [RPi] homebridge: read file: /sys/class/leds/PWR/brightness
[19/06/2023, 13:42:38] [RPi] homebridge: warning: heartbeat error: /sys/class/leds/PWR/brightness: cannot open: ENOENT no such file or directory
[19/06/2023, 13:42:39] [Tuya] [TuyaOpenAPI] Request:
method = post
endpoint = https://openapi.tuyaeu.com
path = /v1.0/devices/bfa2cbb51bf5605455enzt/commands
query = null
headers = {
  "t": "1687174959027",
  "client_id": "vcqpaafjv9k7qkXXXXXX",
  "nonce": "01e3baa6-cd9a-4cf9-ba7a-6625741fdf34",
  "Signature-Headers": "client_id",
  "sign": "192B31991769F5D8E090C2B1A8CFD17CEF1BD4DC4E898F2A9E456C2B48B2XXXX",
  "sign_method": "HMAC-SHA256",
  "access_token": "42d2f2f1b96bc44108196aXXXXXXXXXX",
  "lang": "en",
  "dev_lang": "javascript",
  "dev_channel": "homebridge",
  "devVersion": "1.7.0-beta.45"
}
body = {
  "commands": [
    {
      "code": "switch",
      "value": false
    }
  ]
}
[19/06/2023, 13:42:39] [Tuya] [TuyaOpenAPI] Response:
path = /v1.0/devices/bfa2cbb51bf5605455enzt/commands
data = {
  "result": true,
  "success": true,
  "t": 1687174959221,
  "tid": "64a93cab0e9611ee9b65f25b5112df17"
}
[19/06/2023, 13:42:39] [Tuya] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/8d54cd7e02d63d7c7e22fbXXXXXXXXXX
protocol = 4
message = {
  "dataId": "36e0a39b-9037-4659-b604-d0bacf41b27e",
  "devId": "bfa2cbb51bf5605455enzt",
  "productKey": "nxquc5lb",
  "status": [
    {
      "1": false,
      "code": "switch",
      "t": "1687174957",
      "value": false
    }
  ]
}
t = 1687174957
[19/06/2023, 13:42:39] [Tuya] [Water Timer] [Valve/switch/InUse] Update value: 1 => 0
[19/06/2023, 13:42:49] [Tuya] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/8d54cd7e02d63d7c7e22fbXXXXXXXXXX
protocol = 4
message = {
  "dataId": "d392eda0-7c94-44a6-b9c2-cbbd93efef7c",
  "devId": "bf8e39941edeXXXXXXXXXX",
  "productKey": "gw173aldekvpzalg",
  "status": [
    {
      "3": 261,
      "code": "temp_current",
      "t": "1687174968",
      "value": 261
    }
  ]
}
t = 1687174968

However, when I use the Smart Life app to control my device, everything is fine, and I get the following logs in my Homebridge logs:

[19/06/2023, 13:33:03] [Tuya] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/8d54cd7e02d63d7c7e22fbXXXXXXXXXX
protocol = 4
message = {
  "dataId": "e2ca3160-3815-44d4-9e40-cf177a93a434",
  "devId": "bfa2cbb51bf5605XXXXXXX",
  "productKey": "nxquc5lb",
  "status": [
    {
      "11": 298,
      "code": "countdown",
      "t": "1687174382",
      "value": 298
    }
  ]
}
t = 1687174382
[19/06/2023, 13:33:03] [Tuya] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/8d54cd7e02d63d7c7e22fbXXXXXXXXXX
protocol = 4
message = {
  "dataId": "2bb32935-bf14-406d-afa9-a3402d66b5be",
  "devId": "bfa2cbb51bf5605XXXXXXX",
  "productKey": "nxquc5lb",
  "status": [
    {
      "11": 300,
      "code": "countdown",
      "t": "1687174382",
      "value": 300
    },
    {
      "12": "manual",
      "code": "work_state",
      "t": "1687174382",
      "value": "manual"
    },
    {
      "1": true,
      "code": "switch",
      "t": "1687174382",
      "value": true
    }
  ]
}
t = 1687174382
[19/06/2023, 13:33:03] [Tuya] [Water Timer] [Valve/switch/Active] Update value: 0 => 1
[19/06/2023, 13:33:03] [Tuya] [Water Timer] [Valve/switch/InUse] Update value: 0 => 1
[19/06/2023, 13:33:05] [Tuya] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/8d54cd7e02d63d7c7e22fbXXXXXXXXXX
protocol = 4
message = {
  "dataId": "ae86f2ca-d297-48a5-83ac-e926b79a9e9d",
  "devId": "bfa2cbb51bf5605XXXXXXX",
  "productKey": "nxquc5lb",
  "status": [
    {
      "11": 0,
      "code": "countdown",
      "t": "1687174384",
      "value": 0
    },
    {
      "12": "idle",
      "code": "work_state",
      "t": "1687174384",
      "value": "idle"
    },
    {
      "1": false,
      "code": "switch",
      "t": "1687174384",
      "value": false
    },
    {
      "9": 43,
      "code": "time_use",
      "t": "1687174384",
      "value": 43
    }
  ]
}
t = 1687174384
[19/06/2023, 13:33:05] [Tuya] [Water Timer] [Valve/switch/Active] Update value: 1 => 0
[19/06/2023, 13:33:05] [Tuya] [Water Timer] [Valve/switch/InUse] Update value: 1 => 0
[19/06/2023, 13:33:05] [Tuya] [TuyaOpenMQ] onMessage:
topic = cloud/token/in/8d54cd7e02d63d7c7e22fbXXXXXXXXXX
protocol = 4
message = {
  "dataId": "8dc985b6-a97c-4679-87a0-f1cabe31670c",
  "devId": "bfa2cbb51bf5605XXXXXXX",
  "productKey": "nxquc5lb",
  "status": [
    {
      "15": 1,
      "code": "use_time_one",
      "t": "1687174384",
      "value": 1
    }
  ]
}
t = 1687174384


### Other Infomations

I have been trying to get my Irrigation system working with Homekit, and even though it's detected and added to my Homekit, it doesn't work.

<img width="519" alt="image" src="https://github.com/0x5e/homebridge-tuya-platform/assets/1249548/beab9416-b0c7-46b9-817b-c39b941fc296">
<br><br>
By default, this plug-in sends the boolean switch command to Tuya's openapi, which is the reason why currently it doesn't work with this type of Irrigator. After some debugging on Tuya's IoT platform, I realized the device expects two parameters/commands to be sent: switch and countdown, and if I just set the switch to on or off without passing the countdown, nothing happens. 
And if I use the following command, it works (it will turn on the device for 60 seconds) :
<br><br>
<img width="440" alt="image" src="https://github.com/0x5e/homebridge-tuya-platform/assets/1249548/82347c4e-4b96-4b3b-a039-17efb6eeb733">
<br><br>

I tried to use the deviceOverrides option in the config and tried so many different scenarios, but still the plug in would send the default  `
body = {
  "commands": [
    {
      "code": "switch",
      "value": true/false
    }
  ]
}
`
command as body! 
So no matter what I use for overriding the schema, the tuya-platform plug-in would always send the same command.
monkeycatdog commented 1 year ago

Same problem

Soeren1507 commented 11 months ago

Same Problem here.. Any Solution for this? Greetings