glenndehaan / ikea-tradfri-coap-docs

How can you communicate to your ikea tradfri gateway/hub through coap-client
MIT License
189 stars 21 forks source link

Possible Bug in RGB Bulb Firmware (v. 2.3.086) #31

Closed mclayan closed 2 years ago

mclayan commented 2 years ago

There may be a bug in the latest firmware of the RGB Bulb "TRADFRI bulb E14 CWS opal 600lm" that causes it to completely turn off when setting red colours via HSV (as used by the Home Assistant Tradfri integration). I'm not sure how they calculate the HSV values but I suspect that they use the UINT16 range as a scale (0 = 0%, 65535 = 100%). However, when passing any value above 65278 for Hue ("5707"), it just turns off. I detected that because Home Assistant always uses HSV values and passes e.g. '5708': 65279, '5707': 65535 for full red colour.

My assumption is that they use this convention to calculate HSV values:

HUE = VAL_5707 / 65535 * 360
SAT = VAL_5708 / 65535 * 100

Example:

$ coap-client -m put -u "$COAP_USER" -k "$COAP_PW" "coaps://$TF_GATEWAY/15001/65540" -e '{"3311": [{"5850": 1, "5708": 65535, "5707": 65279}]}'

Ideally this would set the bulb to a deep red, instead it will lead to the bulb being physically off but reporting as on ("5850": 1):

$ coap-client -m get -u "$COAP_USER" -k "$COAP_PW" "coaps://$TF_GATEWAY/15001/65540"
{
  "9001": "TRADFRI bulb 3",
  "3": {
    "0": "IKEA of Sweden",
    "1": "TRADFRI bulb E14 CWS opal 600lm",
    "2": "",
    "3": "2.3.086",
    "6": 1,
    "7": 10243,
    "8": 3
  },
  "9003": 65540,
  "9002": 1629536890,
  "9020": 1644754054,
  "9054": 0,
  "9019": 1,
  "5750": 2,
  "3311": [
    {
      "5710": 0,
      "5850": 1,
      "5849": 2,
      "5851": 224,
      "5707": 65279,
      "5708": 65535,
      "5709": 0,
      "5706": "f1e0b5",
      "9003": 0
    }
  ]
}

Also note the HEX color code "5706": "f1e0b5", which is something like beige (maybe a default colour).

They must have introduced this behaviour in the last FW update because until then my automations were working.

Maybe this would be worth mentioning in the documentation?

glenndehaan commented 2 years ago

That is indeed new behaviour. Unfortunately I have given up on the tradfri hardware. After several bugs/crashes and even hardware failures I switched to Philips Hue (yes yes I know you get what you paid for, but waking up in the middle of the night because all lights turned on since there was a firmware update was not fun anymore). I will make a note in the docs that this is going on, since previously the light would stay on but would return to the default color.