ollo69 / ha_tuya_custom

Tuya Custom Component for testing
Apache License 2.0
39 stars 18 forks source link

Keep the color set and change the saturation value #9

Closed SmartM-ui closed 3 years ago

SmartM-ui commented 4 years ago

Hi! I have seen that it is not possible to keep the color set of the Tuya bulbs on Home Assistant and to change the color saturation (it is possible to do it only on the white temperature). In addition, the RGB color value shown in the card always remains at 255 255 255 whatever the color set (see photo). Screenshot_2020-07-05_1

I found an old post on github where the problem was solved. I tried to replace the code, but the bulbs were no longer recognized. I try to attach the code, with reference to the post, maybe together we can find the way.

https://github.com/home-assistant/core/issues/28602#issuecomment-567585526

Change from. import DATA_TUYA, TuyaDevice

to from. import DATA_TUYA, TuyaDevice, DOMAIN

Change the hs_color property to this:

@property def hs_color (self): "" "Return the hs_color of the light." "" if "entity_data" in self.hass.data [DOMAIN] and self.tuya.object_id () in self.hass.data [DOMAIN] ["entity_data"]: return self.hass.data [DOMAIN] ["entity_data"] [self.tuya.object_id ()] ["color"] else: return tuple (map (int, self.tuya.hs_color ()))

and in the turn_on method change this:

    if ATTR_HS_COLOR in kwargs:
        self.tuya.set_color (kwargs [ATTR_HS_COLOR])

to this:

    if ATTR_HS_COLOR in kwargs:
        self.tuya.set_color (kwargs [ATTR_HS_COLOR])
        if not "entity_data" in self.hass.data [DOMAIN]:
          self.hass.data [DOMAIN] = {"entity_data": {}}
        self.hass.data [DOMAIN] ["entity_data"] [self.tuya.object_id ()] = {"color": kwargs [ATTR_HS_COLOR]}

This keeps track of the current color in hass.data. This will obviously only work if you only control the lights through Home Assistant.

SmartM-ui commented 4 years ago

@nao-pon Hi, I don't understand if you have already found the fix and I have to try to put your repository back and try. Let me know, thanks!

SmartM-ui commented 4 years ago

Hi @ollo69 and @nao-pon, I tried to replace the two files indicated, but the problem remains.
The color on Home Assistant is lost each time the bulb is turned on or off (even if the bulb actually stays on the last color set) and saturation is not variable. In the bulb control panel, the rgb value remains fixed at 255, 255, 255, the hs color value remains fixed at 0, 0, the xy color value remains fixed at 0.323, 0.329

Good night, see you tomorrow

nao-pon commented 3 years ago

@SmartM-ui Change to my repository and try. Don't forget to reboot HA. 😄

skynet01 commented 3 years ago

I tried your repository @nao-pon, I am not getting the color options wheel in my tuya lights. Have you tried using the updated light.py file from here that solves this issue: https://gist.github.com/gadgetchnnel/c29503d7f1acbda17c64a70bb985de69

ollo69 commented 3 years ago

Funny story... I just bought 1 light Tuya compatible from Amazon (Bakibo Smart WiFi Led) Seems that Amazon made a mistake and send me a kit of 2 light instead a single one. Ok, no problem I have 2 now, so I can start my test. Connected the light, registered in SmartLive and surprise, Tuya API report the light as switch, so I'm just able to switch it on and off. Honestly I think that this API is too much unreliable, we should find an alternative solution as try to reverse enginering the SmartLive app...

SmartM-ui commented 3 years ago

@SmartM-ui Change to my repository and try. Don't forget to reboot HA. 😄

@nao-pon @ollo69 Incredible!!! It works. GREAT

The settings and colors if they are controlled by Home Assistant are also reported on the smart life app, while the commands on the colors that are given via smart life are not shown on Home Assistant.

By turning the bulb off and on again, the color on Home Assistant remains set as in reality and also the display of the color RGB, HS color and XY Color, varies with the change of the set color.

As for the color saturation slider, is it possible to implement it? The color temperature slider now present in the color palette on Home Assistant, varies the shade of white (warm / cold). Even when the color is set, if I press on the color temperature slider, the light bulb turns white.

Congratulations again!

SmartM-ui commented 3 years ago

Funny story... I just bought 1 light Tuya compatible from Amazon (Bakibo Smart WiFi Led) Seems that Amazon made a mistake and send me a kit of 2 light instead a single one. Ok, no problem I have 2 now, so I can start my test. Connected the light, registered in SmartLive and surprise, Tuya API report the light as switch, so I'm just able to switch it on and off. Honestly I think that this API is too much unreliable, we should find an alternative solution as try to reverse enginering the SmartLive app...

2x1, better than the real Amazon Prime offers :-)

I also have Bakibo bulbs registered on Smart Life (not on Tuya app), but they are correctly seen as "light" in Home Assistant.

I have your same problem for Teckin sockets that are seen as switches in Home Assistant and I have not been able to replace from switch to socket!

ollo69 commented 3 years ago

Well, socket is correct that is managed as switch, in HA the socket entity does not exist. Imho this is related to product release date. Newer device are not properly managed by this API and the situation is destined to get worse. We have to find alternative solution.

SmartM-ui commented 3 years ago

Well, socket is correct that is managed as switch, in HA the socket entity does not exist. Imho this is related to product release date. Newer device are not properly managed by this API and the situation is destined to get worse. We have to find alternative solution.

Ah OK! I wanted to solve the problem because in the Alexa app, the same four Teckin sockets, I see them divided into 4 in the sockets section and the same 4 in the switches section (imported from HA). By now I have made a reason :-)

SmartM-ui commented 3 years ago

Hi @nao-pon and @ollo69 , entering the parameter 191 (instead of 19) in the json parameter to show the color palette, the slider for the white point (which does not work) is also shown.

Screenshot_2020-07-07_1

Is it possible to assign the slider of the value for the white point for the (warm / cold) and try to attribute the saturation (which is still not changed) to the color temperature slider?

Thank you