0x5e / homebridge-tuya-platform

Make homebridge-tuya-platform great again.
MIT License
219 stars 68 forks source link

dimming sends `switch_led` instead of `bright_value` #169

Closed ascn closed 1 year ago

ascn commented 1 year ago

Describe the bug Dimming does not work even with updated schema. Logs indicate wrong code sent on brightness change - the switch_led is sent instead of the bright_value. When brightness in Homekit is changed, there is a brief delay before the brightness is set back to 100% and the light brightness does not change at all.

Expected behavior Brightness in Homekit is changed, and then the light brightness is updated.

Device info

[12/24/2022, 5:05:04 PM] [TuyaPlatform] [Geeni BW223 Smart Filament Bulb] Characteristic.Brightness set to: 50
[12/24/2022, 5:05:05 PM] [TuyaPlatform] [TuyaOpenAPI] Request:
method = post
endpoint = https://openapi.tuyaus.com
path = /v1.0/devices/redacted/commands
query = null
headers = {
  "t": "1671930305085",
  "client_id": "redacted",
  "nonce": "redacted",
  "Signature-Headers": "client_id",
  "sign": "redacted",
  "sign_method": "redacted",
  "access_token": "redacted",
  "lang": "en",
  "dev_lang": "javascript",
  "dev_channel": "homebridge",
  "devVersion": "1.7.0-beta.11"
}
body = {
  "commands": [
    {
      "code": "switch_led",
      "value": true
    }
  ]
}
[12/24/2022, 5:05:05 PM] [TuyaPlatform] [TuyaOpenAPI] Response:
path = /v1.0/devices/redacted/commands
data = {
  "result": true,
  "success": true,
  "t": 1671930305259,
  "tid": "redacted"
}
[12/24/2022, 5:05:05 PM] [TuyaPlatform] [TuyaOpenMQ] onMessage:
topic = redacted
protocol = 4
message = {
  "dataId": "redacted",
  "devId": "redacted",
  "productKey": "redacted",
  "status": [
    {
      "1": true,
      "code": "switch_led",
      "t": "1671930304",
      "value": true
    }
  ]
}
t = 1671930304
[12/24/2022, 5:05:05 PM] [TuyaPlatform] [Geeni BW223 Smart Filament Bulb] Update value 50 => 100 for service = 'redacted', subtype = undefined, characteristic = 'redacted'
0x5e commented 1 year ago

Can you upload the device info json? I want to check the schema of your device's brightness. On/Off command will be auto added by homekit when slide the brightness bar, not instead of the brightness command, usually there's no side effect.

ascn commented 1 year ago

Yup, here it is!

{
    "id": "redacted",
    "schema": [
        {
            "oldCode": "bright_value",
            "code": "bright_value",
            "type": "Integer",
            "onGet": "((((value - 25) / 230) * 99) + 1);",
            "onSet": "((((value - 1) / 99) * 230) + 25);",
            "property": {
                "min": 1,
                "max": 100,
                "scale": 0,
                "step": 1
            }
        }
    ]
}
0x5e commented 1 year ago

I didn't mean the config file, I mean the device information json file which can be get from the log (/path/to/TuyaDeviceList.{uid}.json) It contains all the device info including category, status and schema :) Usually the brightness schema is correct, no need to do this convertion manually.

ascn commented 1 year ago

My bad, here it is:

    "active_time": 1671913151,
    "biz_type": 0,
    "category": "dj",
    "create_time": 1671901691,
    "icon": "smart/icon/ay1480002761059me2zH/x.png",
    "id": "",
    "ip": "",
    "lat": "",
    "local_key": "",
    "lon": "",
    "model": "",
    "name": "Geeni BW223 Smart Filament Bulb",
    "online": true,
    "owner_id": "92637966",
    "product_id": "",
    "product_name": "Geeni BW223 Smart Filament Bulb",
    "status": [
      {
        "code": "bright_value",
        "value": 25
      },
      {
        "code": "led_switch",
        "value": true
      },
      {
        "code": "temp_value",
        "value": 0
      }
    ],
    "sub": false,
    "time_zone": "-08:00",
    "uid": "",
    "update_time": 1671913151,
    "uuid": "",
    "schema": [
      {
        "code": "bright_value",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "min": 25,
          "max": 255,
          "scale": 0,
          "step": 1
        }
      },
      {
        "code": "led_switch",
        "mode": "rw",
        "type": "Boolean",
        "property": {}
      },
      {
        "code": "temp_value",
        "mode": "rw",
        "type": "Integer",
        "property": {
          "min": 0,
          "max": 255,
          "scale": 0,
          "step": 1
        }
      }
    ]
  }
0x5e commented 1 year ago

Thanks for the information. Seems the schema is correct, so no need to set deviceOverrides manually. Have you tried clean the accessory cache? And during the launch, the logs output: Light Accessory type: CW is it right?

ascn commented 1 year ago

Yup, removed the manual deviceOverrides. Also just reinstalled the plugin, the launch log has this: [12/24/2022, 10:14:53 PM] [TuyaPlatform] [Geeni BW223 Smart Filament Bulb] Light Accessory type: CW

0x5e commented 1 year ago

OK I know the reason: https://github.com/0x5e/homebridge-tuya-platform/blob/d5740d5605173153fa99219bbeac37237e19a1af/src/accessory/LightAccessory.ts#L181-L202

I see Characteristic.Brightness set to: xxx from your log, so the onSet handler has been executed. And your device didn't have the work_mode schema, then it goes to the else block, nothing happends.

I will fix this later.

ascn commented 1 year ago

Thank you!

0x5e commented 1 year ago

Please try beta.12

ascn commented 1 year ago

It works :) Thanks for fixing it so quickly!