rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
3k stars 565 forks source link

Can't dim lights to their lowest brightness value (boundary value for `bright_value_v2` is 10 but HA doesn't go lower than 22) #756

Open jant90 opened 2 years ago

jant90 commented 2 years ago

The problem

I've added a few tunable white Tuya lightbulbs to Home Assistant using the LocalTuya integration. While I can control them just fine I can't dim them to their lowest value. When I set their brightness to 1% in HA they actually stay stuck at 2.2%.

Through the Tuya Smart app and the Tuya API Explorer I can see that the boundaries for brightness are 10 (=1%) and 1000 (=100%) and using the Tuya Smart app I can set the brightness to 1% just fine (= a bright_value_v2 of 10 in the API Explorer) but when I set the brightness to 1% in HA the bright_value_v2 of the light is actually set to 22 (or 2.2%). When I change the brightness from that 2.2% to 1% using the Tuya Smart I can actually see the light dim further so currently it's impossible to reach the lowest brightness of these light through HA. Setting the light to 50% brightness in HA results in a bright_value_v2 of 507 on the bulb (where it should be 500). So something in the scaling seems off.

I want to note that the color temperature has a similar scale with boundary values of 0 (= warmest temp of 1800K) and 1000 (= coolest temp of 3000K for these specific bulbs) and this can be controlled perfectly fine in HA. Using the color temperature slider I can reach the boundary values of 0 and 1000 as expected.

Environment

Steps to reproduce

  1. Check the brightness boundary values of a Tuya light, e.g. 10-1000 (bright_value_v2 in Tuya API Explorer, also visible in Tuya Smart app).
  2. Set brightness for a Tuya light to 1% through HA.
  3. Check the bright_value_v2 in Tuya API Explorer or Tuya Smart app (in my case it's 22 while it should be 10).
  4. While the bright_value_v2 is at 22, use the Tuya Smart app to dim the light further to 1% and see the actual light get dimmer (this brightness setting can't be set through HA).
  5. Set brightness for a Tuya light to 50% through HA and check the bright_value_v2 in Tuya API Explorer or Tuya Smart app (in my case it's 507 while it should be 500).
  6. Color temperature works with a similar scale called temp_value_v2 ranging from 0-1000 and is working perfectly fine in HA.

Configuration configuration.yaml or config_flow

I used config flow and the lights can be controlled just fine.

DP dump

$ ./test.py bf6b8013c1c1e9b112tya1 192.168.178.33 xxxxxxxxxxxx
INFO:localtuya:localtuya version 1.0.0
INFO:localtuya:Python 3.10.2 (main, Jan 15 2022, 19:56:27) [GCC 11.1.0] on linux
INFO:localtuya:Using pytuya version '8.1.0'
INFO:localtuya:Detecting list of available DPS of device bf6b8013c1c1e9b112tya1 [192.168.178.33], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bf6b8013c1c1e9b112tya1","devId":"bf6b8013c1c1e9b112tya1"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:decode payload=b'\xde\xf6Va?\xf9\x93\xf4V\xfc\xd6\xbd+\xb8\x8a"W\xbc\xba\x00b<\x92zS\x9b\x8a\x95\xce\x1e\xecaT\xc6\xfd )l\x0e\xe4\x0e\xc9/\xddk\x14\xb5\xa0\x915\xd3q\x15>\xc5dA~\x1aP\xaa\x06S=\xa4\xb4C\xc1\xad\xcfg!li\xc2\x06\xcfh\xa9.\xc5(\x91\xd9\x16\xea\xc2~\x1bW\xc8Z\x04\x94\xaf\x97\xf2\xe4\xcay\x95\xc4\xcf\xcf\x9e;G\xf9`L\x18I'
DEBUG:localtuya.pytuya:decrypted result='{"dps":{"20":true,"21":"white","22":22,"23":0,"25":"000e0d0000000000000000c80000","26":0,"101":true}}'
AVAILABLE DPS ARE [{'20': True, '21': 'white', '22': 22, '23': 0, '25': '000e0d0000000000000000c80000', '26': 0, '101': True}]
INFO:localtuya:COMPLETE response from device bf6b8013c1c1e9b112tya1 [192.168.178.33].
INFO:localtuya:Detecting list of available DPS of device bf6b8013c1c1e9b112tya1 [192.168.178.33], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bf6b8013c1c1e9b112tya1","devId":"bf6b8013c1c1e9b112tya1"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:decode payload=b'\xde\xf6Va?\xf9\x93\xf4V\xfc\xd6\xbd+\xb8\x8a"W\xbc\xba\x00b<\x92zS\x9b\x8a\x95\xce\x1e\xecaT\xc6\xfd )l\x0e\xe4\x0e\xc9/\xddk\x14\xb5\xa0\x915\xd3q\x15>\xc5dA~\x1aP\xaa\x06S=\xa4\xb4C\xc1\xad\xcfg!li\xc2\x06\xcfh\xa9.\xc5(\x91\xd9\x16\xea\xc2~\x1bW\xc8Z\x04\x94\xaf\x97\xf2\xe4\xcay\x95\xc4\xcf\xcf\x9e;G\xf9`L\x18I'
DEBUG:localtuya.pytuya:decrypted result='{"dps":{"20":true,"21":"white","22":22,"23":0,"25":"000e0d0000000000000000c80000","26":0,"101":true}}'
AVAILABLE DPS ARE [{'20': True, '21': 'white', '22': 22, '23': 0, '25': '000e0d0000000000000000c80000', '26': 0, '101': True}]
INFO:localtuya:COMPLETE response from device bf6b8013c1c1e9b112tya1 [192.168.178.33].
INFO:localtuya:Detecting list of available DPS of device bf6b8013c1c1e9b112tya1 [192.168.178.33], protocol 3.3.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"bf6b8013c1c1e9b112tya1","devId":"bf6b8013c1c1e9b112tya1"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:decode payload=b'\xde\xf6Va?\xf9\x93\xf4V\xfc\xd6\xbd+\xb8\x8a"W\xbc\xba\x00b<\x92zS\x9b\x8a\x95\xce\x1e\xecaT\xc6\xfd )l\x0e\xe4\x0e\xc9/\xddk\x14\xb5\xa0\x915\xd3q\x15>\xc5dA~\x1aP\xaa\x06S=\xa4\xb4C\xc1\xad\xcfg!li\xc2\x06\xcfh\xa9.\xc5(\x91\xd9\x16\xea\xc2~\x1bW\xc8Z\x04\x94\xaf\x97\xf2\xe4\xcay\x95\xc4\xcf\xcf\x9e;G\xf9`L\x18I'
DEBUG:localtuya.pytuya:decrypted result='{"dps":{"20":true,"21":"white","22":22,"23":0,"25":"000e0d0000000000000000c80000","26":0,"101":true}}'
AVAILABLE DPS ARE [{'20': True, '21': 'white', '22': 22, '23': 0, '25': '000e0d0000000000000000c80000', '26': 0, '101': True}]
INFO:localtuya:COMPLETE response from device bf6b8013c1c1e9b112tya1 [192.168.178.33].
INFO:localtuya:TIMEOUT: No response from device bf6b8013c1c1e9b112tya1 [192.168.178.33] after 2 attempts.

Provide Home Assistant taceback/logs

Additional information

MeirSD commented 2 years ago

I was having the same issue and it was because the Brightness Lower Value defaults to 29. I selected the light in my integrations, hit configure, then submit. That took me to the config flow where I was able to change the Brightness Lower Value to 10 and that took care of it.

jant90 commented 2 years ago

It's not an issue with how I've configured my Tuya lights, I've already properly determined the boundary values for these bulbs and set them accordingly in the Tuya integration in HA.

Actually I now think the issue is a combination of Tuya and how HA core deals with brightness percent. When I dim the light using brightness percent to 1% I can't get to the true lowest brightness value of Tuya bulbs. But when using brightness value (which has a range of 0-255) and setting the bulb to 1 I can get it to dim further.

flippedcracker commented 1 year ago

I'm seeing this same issue. When I try to set my Tuya bulbs to the lowest brightness through HA (1%), it actually gets set to 22 or 23%. But I'm able to reduce it down to 1% in the Tuya app.

jant90 commented 1 year ago

@flippedcracker it's a bit annoying that it's not possible to do from the GUI but I did find a workaround to dim the light to their lowest values.

In Home Assistant, instead of using a brightness percentage (brightness_pct) of 1%, set the brightness (brightness) to 1 (which has a scale from 0-255). However, the GUI uses the brightness percentage by default which has a scale from 0-100% and it's not possible to dim below 1%. A brightness percentage of 1% is actually a brightness of 3 on the 0-255 scale.

You can test it with your bulbs by going to Developer Tools > Services and call the the Light: Turn on service with a value of 1, or in YAML:

service: light.turn_on
data:
  brightness: 1
target:
  entity_id: light.tuya_bulb

When you do this you will notice the GUI reports the light to be on, but at 0% brightness.

flippedcracker commented 1 year ago

@jant90 I'm controlling my lights using node-red, and when using brightness_pct, I would get 22-23% actual brightness (confirming in the Tuya Smart app). If I switched to just brightness, and use a value of 1, I would an actual brightness of either 13 or 17%. I will try using the Dev Tools and setting it in there and seeing where it ends up. Thanks.

jant90 commented 1 year ago

@flippedcracker I think you need to look at the border values for brightness you configured when adding the lights to the localtuya integration (so maybe remove and add them again). You may have set the bottom value for brightness too high and now HA won't go below that value you configured, even when setting brightness to 1.