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

Add support for 8 Functions String Light Control Adaptor #1630

Merged
merged 2 commits into from Feb 12, 2024

Conversation

BenJamesAndo
Copy link
Contributor

Information about DPS mappings

{
  "result": {
    "model": "{\"modelId\":\"000001canw\",\"services\":[{\"actions\":[],\"code\":\"\",\"description\":\"\",\"events\":[],\"name\":\"默认服务\",\"properties\":[{\"abilityId\":20,\"accessMode\":\"rw\",\"code\":\"switch_led\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-dp_powe\",\"attribute\":\"3\"},\"name\":\"开关\",\"typeSpec\":{\"type\":\"bool\",\"typeDefaultValue\":false}},{\"abilityId\":21,\"accessMode\":\"rw\",\"code\":\"work_mode\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-dp_mode\"},\"name\":\"模式\",\"typeSpec\":{\"range\":[\"white\",\"colour\",\"scene\",\"music\"],\"type\":\"enum\",\"typeDefaultValue\":\"white\"}},{\"abilityId\":22,\"accessMode\":\"rw\",\"code\":\"bright_value\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-liangdu1\",\"attribute\":\"2\"},\"name\":\"亮度值\",\"typeSpec\":{\"max\":1000,\"min\":10,\"scale\":0,\"step\":1,\"type\":\"value\",\"typeDefaultValue\":10}},{\"abilityId\":25,\"accessMode\":\"rw\",\"code\":\"scene_data\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-shoucang\"},\"name\":\"场景\",\"typeSpec\":{\"maxlen\":255,\"type\":\"string\",\"typeDefaultValue\":\"\"}},{\"abilityId\":26,\"accessMode\":\"rw\",\"code\":\"countdown\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-a_nav_timer\",\"attribute\":\"2\"},\"name\":\"倒计时\",\"typeSpec\":{\"max\":86400,\"min\":0,\"scale\":0,\"step\":1,\"type\":\"value\",\"typeDefaultValue\":0}},{\"abilityId\":27,\"accessMode\":\"rw\",\"code\":\"music_data\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-dp_mic\"},\"name\":\"音乐灯\",\"typeSpec\":{\"maxlen\":255,\"type\":\"string\",\"typeDefaultValue\":\"\"}},{\"abilityId\":28,\"accessMode\":\"rw\",\"code\":\"control_data\",\"description\":\"\",\"extensions\":{\"iconName\":\"icon-dp_box2\"},\"name\":\"调节\",\"typeSpec\":{\"maxlen\":255,\"type\":\"string\",\"typeDefaultValue\":\"\"}},{\"abilityId\":101,\"accessMode\":\"ro\",\"code\":\"scene_list\",\"description\":\"场景值上报下发\",\"name\":\"场景配置\",\"typeSpec\":{\"maxlen\":255,\"type\":\"string\",\"typeDefaultValue\":\"\"}},{\"abilityId\":102,\"accessMode\":\"rw\",\"code\":\"scene_select\",\"description\":\"\",\"name\":\"场景选择\",\"typeSpec\":{\"maxlen\":255,\"type\":\"string\",\"typeDefaultValue\":\"\"}},{\"abilityId\":103,\"accessMode\":\"rw\",\"code\":\"scene_combine\",\"description\":\"\",\"name\":\"循环场景自定义\",\"typeSpec\":{\"maxlen\":255,\"type\":\"string\",\"typeDefaultValue\":\"\"}},{\"abilityId\":104,\"accessMode\":\"rw\",\"code\":\"scene_factory\",\"description\":\"\",\"name\":\"场景重置\",\"typeSpec\":{\"max\":255,\"min\":0,\"scale\":1,\"step\":1,\"type\":\"value\",\"typeDefaultValue\":0,\"unit\":\"\"}}]}]}"
  },
  "success": true,
  "t": 1707286919474,
  "tid": "331d33d6c58111eea98786a4630ece50"
}

Product

      "name": "8 Functions Light",
      "product_id": "swzi5fagtytgxe0f",
      "product_name": "Comon Lights",

Information about how the device functions

https://www.realchristmastrees.com.au/wifi-tuya-app-control-adaptor

The device is ambiguously labelled Wifi Tuya App Control Adaptor. It allows smart control of 2 wire single colour string lights. It's by the brand Lexi Lighting.

image

image

8 Functions Light Combination - All
This is scene_combine. I left them all on in the scene.

8 Functions Light In Waves
In addition to setting the brightness, you can also set the speed of the modes/effects. 1st dot is slowest, 4th dot is fastest. The circular arrow icon means it will loop through all 4 speeds.

8 Functions Light Steady On
Steady On is simply on with no effects.

8 Functions Light Music Mode
Music mode uses your phones speaker to affect the lights. There are three modes, 1,2 & 3. It seems the higher numbers sustain the noise effect to the lights for longer.

Possible improvements

I'm not sure what scene_factory, music_data or control_data does.

Each scene value also contains the brightness and speed. That's why I created multiple speed options for each scene. Based upon what you said here #309 (comment). It would be nice if there was some way to have another input to select the speed, then simply select the scene.

I've also noticed when the brightness gets adjusted via the Tuya Smart Life app it doesn't update in Home Assistant. All the scenes I made are 100% brightness. If it isn't currently set to 100% brightness and I select a scene, it does in fact go to 100% brightness, but the value doesn't update in Home Assistant. It does show the correct brightness in Smart Life.

BenJamesAndo and others added 2 commits February 8, 2024 21:55
- Avoid names starting with numbers, as they may have problems in some obscure places
- use branding in product name
- use light effect for mode instead of a separate select entity
- remove scale from brightness as it is no longer needed (make-all#1444)
@make-all make-all merged commit 57e51e9 into make-all:main Feb 12, 2024
4 checks passed
make-all added a commit that referenced this pull request Feb 12, 2024
@BenJamesAndo
Copy link
Contributor Author

Hey @make-all thanks for merging this :)
I've just tested it though and unfortunately it doesn't work properly. I can no longer turn on/off the light or change the brightness and it's greyed out. It seems having the effect string as a primary_entity throws it off. If I remove the following then it starts working again.

    - id: 21
      type: string
      name: effect
      mapping:
        - dps_val: scene
          value: Scene
        - dps_val: music
          value: Music

Below is the error log

ERROR (MainThread) [custom_components.tuya_local.device] String light controller receive loop terminated by exception unsupported operand type(s) for |: 'list' and 'set'
Traceback (most recent call last):
File "/config/custom_components/tuya_local/device.py", line 218, in receive_loop
entity.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 989, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1110, in _async_write_ha_state
state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1049, in __async_calculate_state
attr.update(self.state_attributes or {})
^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 1129, in state_attributes
self.__validate_color_mode(color_mode, legacy_supported_color_modes, effect)
File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 1093, in __validate_color_mode
effect_color_modes = supported_color_modes | {ColorMode.ONOFF}
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for |: 'list' and 'set'

Also seems we need to keep

       mapping:
        - scale: 3.92

otherwise I get the following errors

File "/config/custom_components/tuya_local/helpers/device_config.py", line 933, in get_values_to_set
raise ValueError(f"{self.name} ({value}) must be between {mn} and {mx}")
ValueError: brightness (3) must be between 10 and 1000

@make-all
Copy link
Owner

You have installed the config into an older install of tuya_local. The brightness change needs the latest HEAD.

@make-all
Copy link
Owner

I think the "TypeError: unsupported operand type(s) for |: 'list' and 'set'" error is the same HA 2024.2.0 problem that was fixed in the Tuya Local 2024.2.0 release, so both these should be OK in the latest HEAD.

@BenJamesAndo
Copy link
Contributor Author

I've updated to latest version. TypeError: unsupported operand type(s) for |: 'list' and 'set' error has been fixed and I can switch between Scene and Music mode.
The light scaling is still off and I can't go below 9% without getting the error ValueError: brightness (3) must be between 10 and 1000
I'm running HA 2024.2.1 and Tuya Local 2024.2.0

@BenJamesAndo
Copy link
Contributor Author

Wait scrap that. I restarted HA and it's all working now. Thanks so much for your help! All working perfectly now.

@make-all
Copy link
Owner

Your second to last comment above is expected if you install this config on the latest release (Tuya Local 2024.2.0)
The change to use the new HA scaling utils for brightness was made after that release, so your last comment should only be true if you use the lastest HEAD. I just tried now, and it seems HACS has broken updating to a specific version, and you now have to go through Developer Tools to do it, but it works with their suggested new method.

@BenJamesAndo
Copy link
Contributor Author

Yes HACS does sometimes seem to take a while to notify me of new Tuya-Local updates. I manually downloaded the custom_components folder and pasted it into my HA install. So I suppose I'm technically running Tuya Local 2024.2.1 beta.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants