milo526 / homebridge-tuya-web

Hoobs and Homebridge plugin for Tuya devices using Home Assistant Tuya Web Api
MIT License
217 stars 93 forks source link

Light brightness not working #495

Closed Tilotiti closed 1 year ago

Tilotiti commented 1 year ago

Describe the bug I have a dimmer switch connected to Tuya Smart. I forced the configuration of this device to be recognized as "Light". The brightness on HomeBridge is not updated from Tuya App, it can only be 0 or 100%. When trying to update the brightness from Home, an error appears in the logs & the Brightness is not updated if the value is not 0 or 100%.

Logs

[11/13/2022, 11:31:45 AM] [TuyaWebPlatform] Retrying authentication after previous error.
[11/13/2022, 11:31:45 AM] [TuyaWebPlatform] Requesting new token
[11/13/2022, 11:31:45 AM] [TuyaWebPlatform] Sending HTTP GET request to /homeassistant/skill - Header: {"name":"Discovery","namespace":"discovery","payloadVersion":1}.
[11/13/2022, 11:31:45 AM] [TuyaWebPlatform] Device type for "Canapé" is overruled in config from switch to: "light"
[11/13/2022, 11:31:45 AM] [TuyaWebPlatform] [Canapé] deviceConfig: {
  data: { online: true, state: true },
  name: 'Canapé',
  icon: 'https://images.tuyaeu.com/smart/icon/ay1525342462043yjwZs/1649161943e29c2229c70.png',
  id: 'bf8e765deaae2a6f32scaf',
  dev_type: 'light',
  ha_type: 'switch',
  config: {
    min_brightness: '0',
    max_brightness: '1000',
    light_characteristics: [ 'Brightness' ],
    old_dev_type: 'switch'
  }
}
[11/13/2022, 11:31:45 AM] [TuyaWebPlatform] Existing Accessory found [Name: Canapé] [Tuya ID: bf8e765deaae2a6f32scaf] [HomeBridge ID: fd574750-7ca3-46fa-ab29-63d64f59060b]
[11/13/2022, 11:31:45 AM] [TuyaWebPlatform] [Canapé] Characteristic.On - {"format":"bool","perms":["ev","pr","pw"]}
[11/13/2022, 11:31:45 AM] [TuyaWebPlatform] [Canapé] Characteristic.Brightness - {"format":"int","perms":["ev","pr","pw"],"unit":"percentage","minValue":0,"maxValue":100,"minStep":1}
[11/13/2022, 11:31:45 AM] [TuyaWebPlatform] [Canapé] Characteristic.Brightness - Tried to set brightness but failed to parse data. 
 { online: true, state: true }
[11/13/2022, 11:31:58 AM] [TuyaWebPlatform] [Canapé] - Requesting device state
[11/13/2022, 11:31:58 AM] [TuyaWebPlatform] [Canapé] - Creating new debounced promise
[11/13/2022, 11:31:58 AM] [TuyaWebPlatform] [Canapé] - Triggering debouncedDeviceStateRequest
[11/13/2022, 11:31:58 AM] [TuyaWebPlatform] [Canapé] - Unsetting debouncedDeviceStateRequestPromise
[11/13/2022, 11:31:58 AM] [TuyaWebPlatform] [Canapé] - Resolving resolveDeviceStateRequest from cache
[11/13/2022, 11:31:58 AM] [TuyaWebPlatform] [Canapé] Characteristic.On - [GET] true

Steps To Reproduce

  1. Go to Tuya Smart.
  2. Switch on the light & set brightness to 50%. The light brightness is updated to 50% in real life.
  3. Restart HomeBridge.
  4. The dimmer is considered as "on", but the brightness is set to 100%.
  5. Go to the Home app
  6. The device is "on" and the brightness is 100%. But the light is in reality on, but with 50% brightness.
  7. Change the Brightness, still on the Home app, to 50%.
  8. The light doesn't change brigthness. The device on the Home app appears "disconnected". Logs of Tuya plugin in Homebridge display errors.

Plugin Version Up-to-date : @milo526/homebridge-tuya-web v1.1.2

Homebridge Config

 {
    "name": "TuyaWebPlatform",
    "options": {
        "username": "thibault@henry.pro",
        "password": "Thibault-31031990",
        "countryCode": "33",
        "platform": "tuya"
    },
    "defaults": [
        {
            "id": "Canapé",
            "device_type": "light",
            "min_brightness": "0",
            "max_brightness": "1000", // Tried with 100 or 1000
            "light_characteristics": [
                "Brightness"
            ]
        }
    ],
    "scenes": false,
    "hiddenAccessories": [
        "Lumière bar",
        "Guirlande bar"
    ],
    "platform": "TuyaWebPlatform"
}

Device Config

{
  "header": {
    "code": "SUCCESS",
    "payloadVersion": 1
  },
  "payload": {
    "devices": [
      {
        "data": {
          "online": True,
          "state": False
        },
        "dev_type": "switch",
        "ha_type": "switch",
        "icon": "https://images.tuyaeu.com/smart/icon/15439983441dp9ar3ey4r_0.png",
        "id": "37733038dc4f22a257d8",
        "name": "Guirlande bar"
      },
      {
        "data": {
          "online": True,
          "state": True
        },
        "dev_type": "switch",
        "ha_type": "switch",
        "icon": "https://images.tuyaeu.com/smart/icon/ay1525342462043yjwZs/1649161943e29c2229c70.png",
        "id": "bf8e765deaae2a6f32scaf",
        "name": "Canapé"
      },
      {
        "data": {
          "online": True,
          "state": False
        },
        "dev_type": "switch",
        "ha_type": "switch",
        "icon": "https://images.tuyaeu.com/smart/icon/15439983441dp9ar3ey4r_0.png",
        "id": "37733038dc4f22a23ded",
        "name": "Lumière bar"
      },
      {
        "data": {},
        "dev_type": "scene",
        "ha_type": "scene",
        "id": "kzxo3kM16ruTMSej",
        "name": "\\"Lumière salon\\" Switch:OFF"
      },
      {
        "data": {},
        "dev_type": "scene",
        "ha_type": "scene",
        "id": "A4VANEHnOEFEUXlf",
        "name": "\\"Lumière salon\\" "
                                              "Brightness:210Percent"
      },
      {
        "data": {},
        "dev_type": "scene",
        "ha_type": "scene",
        "id": "V4Knfvis5I7aMWzh",
        "name": "\\"Lumière salon\\" "
                                              "Brightness:467Percent"
      }
    ],
    "scenes": []
  }
}

Additional Context Just thank you for your work.

EcomGraduates commented 1 year ago

what switches are you using? I'm also having similar issues. I use treat life smart dimmers and switches

milo526 commented 1 year ago

In your logs it says:

[11/13/2022, 11:31:45 AM] [TuyaWebPlatform] [Canapé] Characteristic.Brightness - Tried to set brightness but failed to parse data. { online: true, state: true }

That last part misses the brightness information.
Tuya does not provide information on the brightness of your light to the API that this plugin uses. Sadly there is nothing I can do to change that since I am in no way affiliated with them. You should be able to continue using this plugin without the dimming capabilities or you could use the plugin developed by Tuya: https://github.com/tuya/tuya-homebridge

Tilotiti commented 1 year ago

Thank you for looking into it :) Unfortunatly, I try the Tuya plugin, but didn't worked :/ Never the Tuya cloud has been able to push any state to the dimmer (but could read the state ... odd ...)

Thank you anyway for your work !