Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fairy Lights with preset colors #337

Open
jaydensmith opened this issue Jan 23, 2021 · 2 comments · May be fixed by #844
Open

Fairy Lights with preset colors #337

jaydensmith opened this issue Jan 23, 2021 · 2 comments · May be fixed by #844

Comments

@jaydensmith
Copy link

I have some Tuya fairy lights that I'm trying to set up. The lights have no brightness controls, and you can only choose from a preset list of colors (see screenshot).

I've been able to get them to power off/on with the following config.

host: 192.168.1.202
device_id: 82005237600194dd6fce
local_key: 095573c690e00b9e
friendly_name: Tuya Fairy 1
protocol_version: "3.3"
entities:
  - platform: light
    friendly_name: Fairy Lights 1
    id: 20
    # color: 101 # Optional, usually 5 (RGB_HSV) or 24 (HSV), default: "none"
    scene: 102 # Optional, usually 6 (RGB_HSV) or 25 (HSV), default: "none"

If I set the color parameter, the entities become unavailable, as the integration doesn't support color changing lights with no brightness.

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 283, in async_update_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 322, in _async_write_ha_state
attr.update(self.state_attributes or {})
File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 433, in state_attributes
data[ATTR_BRIGHTNESS] = self.brightness
File "/config/custom_components/localtuya/light.py", line 176, in brightness
return map_range(
File "/config/custom_components/localtuya/light.py", line 90, in map_range
mapped = (value - from_lower) * (to_upper - to_lower) / (
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

The DPS response I get from the device is:

INFO:localtuya:Detecting list of available DPS of device 82005237600194dd6fce [192.168.1.202], protocol 3.1.
DEBUG:localtuya.pytuya:Sending command status (device type: type_0a)
DEBUG:localtuya.pytuya:paylod=b'{"gwId":"82005237600194dd6fce","devId":"82005237600194dd6fce"}'
DEBUG:localtuya.pytuya:DATA RECEIVED!
DEBUG:localtuya.pytuya:decode payload=b"\x1a,\x19.\x17\x98m\x8d\xccG\xac4C3\x9c\xdf\xa7\xb9/k\xe3\xed/C\x15ul\xdf'\x9d\x14\xe4\xb8\x97\xf4\xfbp\xea\x82w\xc5(e\xcc\xf1\x9a\x0e\xe9\x01\x05e\x0f\xb5\xe4\xca\xee \xa0\xeb\xa34\xfb~\xffr\xeap\xf1\xfb\x02\xca\x83\xa2\xe3\x1e|\x83v\\\xd7\x03\x85\xe3B\x96\x1e\xd2\xee$>\xfac\xb6\xaf[\xf9"
DEBUG:localtuya.pytuya:decrypted result='{"devId":"82005237600194dd6fce","dps":{"20":false,"101":"Color","102":"Bright"}}'
AVAILABLE DPS ARE [{'20': False, '101': 'R', '102': 'Bright'}]
INFO:localtuya:COMPLETE response from device 82005237600194dd6fce [192.168.1.202].
INFO:localtuya:TIMEOUT: No response from device 82005237600194dd6fce [192.168.1.202] after 2 attempts.

It seems that the 101 DPS is responsible for the color, and 102 for the scene.

The available list of colors responses are:

  • Color (cycles through all the colors)
  • R (red)
  • RG (yellow)
  • G (green)
  • GB (light blue)
  • B (blue)
  • RB (purple)
  • RGB (white)

The available list of scenes that I have working (the keys and values are the same):

SCENE_LIST_RGB_1000 = {
    "Bright": "Bright",
    "Gradually": "Gradually",
    "Star": "Star",
    "Flower": "Flower",
    "Marquee": "Marquee",
    "Fireworks": "Fireworks",
    "Meteor": "Meteor",
    "Stream": "Stream",
}

Ideally so the device can be color controlled by Google Home etc. I'd like to map segments of the color wheel to the preset colors. Do you think this is possible?

@ThomasCr
Copy link

maybe you can add output of tinytuya in monitor mode (example script is provided)
Think, this makes it more easy to find a solution for the integration.

Maybe you also have a look at #659

@CloCkWeRX
Copy link

CloCkWeRX commented May 31, 2022

Ah, I'm seeing:

Logger: homeassistant
Source: custom_components/localtuya/light.py:97
Integration: LocalTuya ([documentation](https://github.com/rospogrigio/localtuya/), [issues](https://github.com/rospogrigio/localtuya/issues))
First occurred: 10:02:36 PM (1 occurrences)
Last logged: 10:02:36 PM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 520, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 573, in _async_write_ha_state
    attr.update(self.state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 951, in state_attributes
    data[ATTR_BRIGHTNESS] = self.brightness
  File "/config/custom_components/localtuya/light.py", line 189, in brightness
    return map_range(
  File "/config/custom_components/localtuya/light.py", line 97, in map_range
    mapped = (value - from_lower) * (to_upper - to_lower) / (
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

Which I think is from my Genio LED strip.

8a1c6e0 seems kind of similar to this, just on a different attribute - but I'm seeing it on master.

CloCkWeRX added a commit to CloCkWeRX/localtuya-experimental that referenced this issue May 31, 2022
CloCkWeRX added a commit to CloCkWeRX/localtuya-experimental that referenced this issue May 31, 2022
@CloCkWeRX CloCkWeRX linked a pull request May 31, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants