SonoffLAN icon indicating copy to clipboard operation
SonoffLAN copied to clipboard

B02 and B05 color temperature ranges wrong

Open SirDester opened this issue 2 years ago • 6 comments

Hello @AlexxIT I just bought two B05-BL-A60 rgb light bulbs and I had some problems making them work with color temperature slider on HA. I think the issue can be related to #766 (already closed).

I'm using version 3.0.5 of your repository.

Looking at sonoff SDK reference https://sonoff.tech/sonoff-diy-developer-documentation-b02-bl-b05-bl-http-api/

It seems that the "CT" parameter must have a range of [0,100] but in your code the conversion from mireds is done like [153,500] -> [0,255]. So whenever you set the color with ltype=white the range is wrong and any value past 100 gives an error in integration.

2022-07-06 11:15:04 WARNING (MainThread) [custom_components.sonoff.core.ewelink.local] xxxxxxxxxx => Local4 | {'cmd': 'dimmable', 'ltype': 'white', 'white': {'br': 100, 'ct': 255}} <= {'sequence': '1657098904000', 'encrypt': True, 'seq': 6, 'error': 400}

I think you can fix this by changing the conversion max values from 255 to 100. I tried making changes on my local file and it seems to work.

https://github.com/AlexxIT/SonoffLAN/blob/c317407a09e5c5e9aaf2a95e044e5afb5a367dec/custom_components/sonoff/light.py#L324 https://github.com/AlexxIT/SonoffLAN/blob/c317407a09e5c5e9aaf2a95e044e5afb5a367dec/custom_components/sonoff/light.py#L335 https://github.com/AlexxIT/SonoffLAN/blob/c317407a09e5c5e9aaf2a95e044e5afb5a367dec/custom_components/sonoff/light.py#L385 https://github.com/AlexxIT/SonoffLAN/blob/c317407a09e5c5e9aaf2a95e044e5afb5a367dec/custom_components/sonoff/light.py#L400

I never did a pull request, I try to learn how to do it and attach here if I succeed :)

Regards. Maurizio

SirDester avatar Jul 06 '22 10:07 SirDester

Perhaps I did it: #892

SirDester avatar Jul 06 '22 10:07 SirDester

What UIID have your bulb?

AlexxIT avatar Jul 07 '22 10:07 AlexxIT

This is what I extracted from cloud configuration json:

  "extra": {
    "uiid": 136,
    "description": "20211223010",
    "brandId": "5c4c1aee3a7d24c7100be054",
    "apmac": "xx:xx:xx:xx:xx:xx",
    "mac": "xx:xx:xx:xx:xx:xx",
    "ui": "RGB五色灯_支持2.4G轻智能",
    "modelInfo": "611e0d429d679662bd8defd0",
    "model": "BL1-ALL-LED",
    "manufacturer": "深圳松诺技术有限公司",
    "chipid": "7CB94C81D0E1"
  },
  "brandName": "SONOFF",
  "brandLogo": "https://eu-ota.coolkit.cc/logo/q62PevoglDNmwUJ9oPE7kRrpt1nL1CoA.png",
  "showBrand": true,
  "productModel": "B05-BL"

(I removed what I think were sensitive data mac and apmac)

SirDester avatar Jul 07 '22 10:07 SirDester

@SirDester Sorry for the OT, how did you connect B05-BL-A60 to HA? I installed SonoffLAN but it doesn't find my light bulb

Carbocode avatar Aug 18 '22 09:08 Carbocode

@SirDester Sorry for the OT, how did you connect B05-BL-A60 to HA? I installed SonoffLAN but it doesn't find my light bulb

Hello, I simply added the 2 bulbs to the EWeLink mobile app and then forced a new sync on SonoffLAN from the cloud. Then I applied the suggested changes to sources to manage the right ranges for color temperature.

SirDester avatar Aug 20 '22 13:08 SirDester

@bwp91 what do you think about this?

Because in all other places I can see ct=255 for UIID 104 (Sonoff B05-B): https://github.com/CoolKit-Technologies/ha-addon/blob/master/eWeLink_Smart_Home/dist/controller/CloudUIID104Controller.js

I can't find anything about UIID 136 (Sonoff B05-BL).

Looks like @SirDester using only LAN mode because this.

I don't want to break cloud for this model.

AlexxIT avatar Sep 24 '22 19:09 AlexxIT

For UIID 136 i use a colour temperature scale of 0,255. I think I only implemented cloud mode for this model. Will need to check. Could be that local mode uses 0,100 and cloud mode uses 0,255 but this wouldn’t make much sense for the incoming notifications as you wouldn’t know which scale to use!

Interestingly, the bulb with UIID 137 uses a scale of 0-100 for colour temperature (cloud mode).

I’m not sure the protocols for lan mode for 136.

bwp91 avatar Sep 25 '22 14:09 bwp91

Hello, I really don't understand this behaviour of these bulbs. I can't find any information on protocols for 136 other than the official documentation, but as @AlexxIT said if it's not so trustfull it's better to check elsewhere.

I assure that the only way I can achieve the right color is changing the scale to [0,100], any other value past 100 to 255 gives me an error as told in the log entry in the first post.

I confirm I'm using LAN only mode, but as @bwp91 it's really strange that protocol can change between Cloud and LAN mode... but nothing is impossible.

If I can suggest a way to exit this issue (but I'm not so able to code it, so I leave to @AlexxIT if he has the time...) is to set a configuration flag where you put min and max CT for the bulb so you can change it in yaml config file, with default values to [0,255].

Another way (I think this requires more coding) is to use different ranges for LAN and CLOUD mode, but for this we must be sure that the problem is really the difference in protocols, perhaps the configuration way is safer.

Thanks for discussion for now.

SirDester avatar Sep 26 '22 11:09 SirDester

@AlexxIT Moreover, if you need any other logging/debug information tell me what to do, I'm at your disposal.

SirDester avatar Sep 26 '22 11:09 SirDester

@SirDester you need to log how this bulb works in only cloud mode. You also can log commands from mobile ewelink app. You will see them in Hass logs.

AlexxIT avatar Sep 26 '22 13:09 AlexxIT

Ok, I tried putting the addon to Cloud only, using the range [0,100] with my code changes, and this is the debug log I get when I try to switch color to red and then to white using Google Home (red command is given with RGB [255,0,0] while white command is given with CT)

2022-09-26 19:48:55 [D] x => Cloud4 | {'ltype': 'color', 'color': {'br': 100, 'r': 255, 'g': 0, 'b': 0}} | 1664214535000
2022-09-26 19:48:55 [D] x => Cloud4 | 1664214535001
2022-09-26 19:48:55 [D] x <= Cloud3 | {'version': 8, 'rssi': -58, 'fwVersion': '1.4.1', 'switch': 'on', 'ltype': 'color', 'white': {'br': 100, 'ct': 86}, 'remoteCtrlList': [], 'lightScenes': [], 'color': {'br': 100, 'r': 255, 'g': 0, 'b': 0}} | 1664214535001
2022-09-26 19:49:03 [D] x => Cloud4 | {'ltype': 'white', 'white': {'br': 100, 'ct': 86}} | 1664214543000
2022-09-26 19:49:03 [D] x => Cloud4 | 1664214543001
2022-09-26 19:49:03 [D] x <= Cloud3 | {'version': 8, 'rssi': -58, 'fwVersion': '1.4.1', 'switch': 'on', 'ltype': 'white', 'white': {'br': 100, 'ct': 86}, 'remoteCtrlList': [], 'lightScenes': [], 'color': {'br': 100, 'r': 255, 'g': 0, 'b': 0}} | 1664214543001

The I reverted the code with your original one and did exactly the same things (switch to red, switch to white)

2022-09-26 20:00:07 [D] x => Cloud4 | {'ltype': 'color', 'color': {'br': 100, 'r': 255, 'g': 0, 'b': 0}} | 1664215207000
2022-09-26 20:00:07 [D] x => Cloud4 | 1664215207001
2022-09-26 20:00:07 [D] x <= Cloud3 | {'version': 8, 'rssi': -60, 'fwVersion': '1.4.1', 'switch': 'on', 'ltype': 'color', 'white': {'br': 100, 'ct': 86}, 'remoteCtrlList': [], 'lightScenes': [], 'color': {'br': 100, 'r': 255, 'g': 0, 'b': 0}} | 1664215207001
2022-09-26 20:00:15 [D] x => Cloud4 | {'ltype': 'white', 'white': {'br': 100, 'ct': 220}} | 1664215215000
2022-09-26 20:00:15 [W] Cloud ERROR: {'error': 400, 'deviceid': 'x', 'apikey': '9538aef0-c7bf-41d8-801f-ad3a637e7902', 'sequence': '1664215215000'}

As you can see the first one white is translated to CT:86 and is accepted by the bulb, the second one is translated to CT:220 and it gives error (the light remains red)

Last I changed color a few times in a row from EWeLink app using CT and moving from total cold to total warm white, and this is the log reported by HASS:

2022-09-26 20:10:51 [D] x <= Cloud3 | {'ltype': 'white', 'white': {'ct': 22, 'br': 100}} | 1664215876557
2022-09-26 20:10:51 [D] x <= Cloud3 | {'ltype': 'white', 'white': {'ct': 0, 'br': 100}} | 1664215876758
2022-09-26 20:10:51 [D] x <= Cloud3 | {'ltype': 'white', 'white': {'ct': 0, 'br': 100}} | 1664215877083
2022-09-26 20:10:54 [D] x <= Cloud3 | {'ltype': 'white', 'white': {'ct': 4, 'br': 100}} | 1664215880041
2022-09-26 20:10:55 [D] x <= Cloud3 | {'ltype': 'white', 'white': {'ct': 28, 'br': 100}} | 1664215880259
2022-09-26 20:10:55 [D] x <= Cloud3 | {'ltype': 'white', 'white': {'ct': 72, 'br': 100}} | 1664215880458
2022-09-26 20:10:55 [D] x <= Cloud3 | {'ltype': 'white', 'white': {'ct': 100, 'br': 100}} | 1664215880673
2022-09-26 20:10:55 [D] x <= Cloud3 | {'ltype': 'white', 'white': {'ct': 100, 'br': 100}} | 1664215880876

The value sent by the app is always between 0 to 100

Hope this helps. Regards.

SirDester avatar Sep 26 '22 18:09 SirDester

This is very strange because I have a user who states everything is working well, and my plugin uses a range 0-255.

https://github.com/bwp91/homebridge-ewelink/issues/358

bwp91 avatar Sep 26 '22 18:09 bwp91

Alas these are the only tests I can do and the only evidence I can bring of this color temperature range :( I also saw there was a new 1.5.1 firmware, installed it right now but (as i thought) the logs are the same.

SirDester avatar Sep 26 '22 21:09 SirDester

Ignore all my previous comments 🤦🏼‍♂️

This uiid model 136 uses a colour temperature scale of 0-100 for both lan and cloud 🙂

bwp91 avatar Oct 01 '22 20:10 bwp91

Oh good to know !

If I'm not indiscrete... how did you reach this verdict ? I'm just curious :)

SirDester avatar Oct 01 '22 21:10 SirDester

Using the ewelink app to change the colour temperature to both ends of the scale and checking the incoming logs for both lan and cloud.

Both report the whitest end as ct:100 (and obviously the yellowest value as ct:0)

bwp91 avatar Oct 01 '22 21:10 bwp91

Ok thanks for reporting.

SirDester avatar Oct 01 '22 21:10 SirDester

I'm having similar type issues with the B05 bulbs. Color and brightness work great but temperature does not seem to work at all (or it's working but not using the correct scale maybe like above?)

Can I provide any info to get this addresses?

emeyedeejay avatar Dec 03 '22 12:12 emeyedeejay

Sorry for very-very long delay. Should be fixed in latest master version. Will be in the next release

AlexxIT avatar Mar 31 '23 07:03 AlexxIT

Sorry for very-very long delay. Should be fixed in latest master version. Will be in the next release

Awesome! Thanks a stack man.

emeyedeejay avatar Mar 31 '23 08:03 emeyedeejay

No problem man, I was modifying the code on my installation by myself every new release, it was not so hard and long. Thanks for your work !

SirDester avatar Mar 31 '23 09:03 SirDester

https://github.com/AlexxIT/SonoffLAN/releases/tag/v3.5.1

AlexxIT avatar Mar 31 '23 11:03 AlexxIT