mjg59 / python-broadlink

Python module for controlling Broadlink RM2/3 (Pro) remote controls, A1 sensor platforms and SP2/3 smartplugs
MIT License
1.38k stars 479 forks source link

Add missing device codes for LB27 R1 Smart Bulbs #644

Closed madmat777 closed 2 years ago

madmat777 commented 2 years ago

Context

Add two missing product ids for LB27 R1 Smart Bulbs

Proposed change

Adding in the missing codes.

Type of change

Additional information

Checklist

felipediel commented 2 years ago

Thank you!

manunited10 commented 2 years ago

Hi, I have an LB27 R1 in hand whose devtype is 25676 (0x644C). How could we add support for it?

felipediel commented 2 years ago

Hi. Already added, coming soon.

manunited10 commented 2 years ago

Hi. Already added, coming soon.

Beautiful

felipediel commented 2 years ago

Hi @madmat777. Did you test 0x644C? Are you sure this is an LB2, and not LB1?

madmat777 commented 2 years ago

@felipediel yes, I manually adjusted the code and then used python to run the commands to get the status. I ordered a box of 10 LB27's and had one that was not working, it had this different code. I'm obviously not sure if it was a mistake by them but it was marked as a LB27 on the box.

felipediel commented 2 years ago

No problem, I will change to LB1. Thank you!

manunited10 commented 2 years ago

confirming this works properly on broadlink-0.18.1

devtype=25676=0x644c 
name='Smart Bulb'
model='LB27 R1'
manufacturer='Broadlink'

Thank you guys

manunited10 commented 2 years ago

Sorry I'm bringing this discussion up again. Just wondering if the same package is used in Home Assistant as well? If yes, (and since recently my light is being recognised automatically by Home Assistant), there's something wrong with setting temperature of the light. Regardless of what I set, it always stays in a specific temperature.

manunited10 commented 2 years ago

Alright, I cloned home-assistant core repo from github and took a look at it. I think the problem is in module

homeassistant/components/broadlink/light.py
in lines 80 and 110

where we have

self._attr_color_temp = round((data["colortemp"] - 2700) / 100 + 153)

and

state["colortemp"] = (color_temp - 153) * 100 + 2700

While the formulas are reverse of each other (which is ok), the calculations don't seem right to me. I tested with broadlink repo and the color-temperature of my light can go from 2700 to 6500 (it will be clipped up/down if we give higher/lower numbers by mistake). So I guess the two lines of code above don't make sense while the color temperature slide bar on the HA-gui (pictures below) can get values from 153 to 500. Well I can see 153 in the above lines of code, but the calculations look senseless to me. image image

manunited10 commented 2 years ago

I investigated more and edited light.py (through custom_components) and I changed those two lines to:

# from color-temp to mired e.g. 6500 -> 153, 2700 -> 370
self._attr_color_temp = round(1e6 / data["colortemp"])

and

# from mired to color-temp, e.g. 153 -> 6500, 370-> 2700 , 500 -> 2000
state["colortemp"] = round(1e6 / color_temp)

And this works.

Please note that in the color temperature slider bar above, temperature is limited from 153 mired to 500 mired which is equal to 6500 Kelvin to 2000 K. However, the bulb that I have in hand, LB27 R1 (with devtype=25676=0x644C), the possible color temperature is from 6500K to 2700K (equal to 153 to 370 mired). This means by above config if we set the slider to the end, it will go back to 370 in a second - which makes sense. I couldn't find where we could change the slider's maximum value yet.

What do you think @felipediel ?