PaulAnnekov / tuyaha

Implements the special Tuya Home Assistant API.
Other
141 stars 106 forks source link

Teckin SB50 bulb turns off if brightness percent less than 12% or brightness value less than 29 #12

Open gadgetchnnel opened 4 years ago

gadgetchnnel commented 4 years ago

I raised this issue over in the Home Assistant repo (here) but it seems more an issue with this library than Home Assistant. When I try setting the brightness percent of a Teckin SB50 bulb to less than 12% (which maps to a brightness value of around 30) this turns the light off instead of setting the brightness. When setting the brightness directly, rather than as a percentage, the minimum it allows appears to be 29 and anything less than this will turn the light off.

Here are the examples from the HA issue:

Working example:

- service: light.turn_on
   data:
     entity_id: light.bedside_light
     brightness_pct: 12

This will set the light to the expected brightness.

Not working example:

- service: light.turn_on
   data:
     entity_id: light.bedside_light
     brightness_pct: 11

This will simply turn off the light.

If a colour is also included, as with the

I have worked around this temporarily in my HA instance by overriding the Tuya component to map the brightness from the range of 0-255 to the range 28-255.

I don't know if this is specific to the Teckin SB50 bulbs or if it affects other Tuya bulbs

leoetlino commented 4 years ago

I don't know if this is specific to the Teckin SB50 bulbs or if it affects other Tuya bulbs

Nope, I have the same issue with the Maxcio YX-L01P-E14 bulbs. Coincidentally, the threshold seems to be the same on my end; anything lower than 28 turns off the light.

mhirsch commented 4 years ago

An LED is a diode and requires a certain forward bias voltage to emit light. There is likely a programmable constant current supply in the bulb. If the current supply goes too low the voltage across the LEDs in the bulb will drop below the bias voltage. The manufacturer likely scaled the output range of the supply from 0 to I_max, rather than I_bias (min current to light the LED) to I_max. If that's true, then as far as the bulb firmware is concerned the bulb is "on" -- just at a threshold below which is needed to produce light from the LED. Perhaps the tuya app has a database of bulb bias voltages and re-scales the input level? But more likely you'll find that the bulb behaves the same way in the tuya app.

gadgetchnnel commented 4 years ago

Perhaps the tuya app has a database of bulb bias voltages and re-scales the input level? But more likely you'll find that the bulb behaves the same way in the tuya app.

It seems like the former, because (before I started using a custom version of the HA Tuya component that I modified to map the brightness) when I set the brightness to 12% in Home Assistant it would show as 2% in the Smart Life app.

vapuri commented 4 years ago

I can confirm that I see the same behavior with a tuya compatible smart dimmer (https://www.feit.com/product/smart-wi-fi-dimmer/). I verified it with the latest HA version 0.103.6 and set the brightness levels of 29-255 via the light.turn_on service. Anything lower than 29 will turn the lights connected to the dimmer off - the behavior is consistent with LED bulbs or incandescent. If I set the brightness to 12%, it shows 1% in the Smart Life App.

Also, when used with the lovelace light card (https://www.home-assistant.io/lovelace/light/), the behavior when trying to use the dimming functionality is erratic and doesn't function properly - I'm guessing due to the same underlying problem.

PaulAnnekov commented 4 years ago

Hi, fellows. So @bessarabov proposed a fix for this issue (https://github.com/PaulAnnekov/tuyaha/pull/21), but his ranges are different (https://github.com/PaulAnnekov/tuyaha/pull/21/files). Can you test his solution?

fellipute commented 4 years ago

Im having the same issues with some Tuya lightbulbs from a Brazilian company (Geonav). If I set the lights to < 12% they shut down. Any updates on this?

PaulAnnekov commented 4 years ago

@FellipeBr I have replied to a comment in the related PR.