home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.8k stars 30.9k forks source link

Tuya: Fan with light fails to add/poll the fan properly, light works correctly #97538

Open WarrenSchultz opened 1 year ago

WarrenSchultz commented 1 year ago

The problem

Installed a new ceiling fan, added to existing Tuya dev account. Light on the fan works great in HA as well as the existing lights I have already working in HA.

The logs show two issues, and I've attached the API debug code below. Please let me know what additional data would be helpful.

What version of Home Assistant Core has the issue?

core-2023.7.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Tuya

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tuya

Diagnostics information

config_entry-tuya-316d98b503531be03fb470264599afd5.json.txt

Example YAML snippet

No response

Anything in the logs that might be useful for us?

`Logger: homeassistant.components.fan
Source: util/percentage.py:25
Integration: Fan (documentation, issues)
First occurred: 3:15:26 AM (10 occurrences)
Last logged: 12:45:22 PM

Error adding entities for domain fan with platform tuya
Error while setting up tuya platform for fan
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 504, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 788, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1006, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 742, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 812, in _async_write_ha_state
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 355, in state_attributes
    data[ATTR_PERCENTAGE] = self.percentage
                            ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 253, in percentage
    return ordered_list_item_to_percentage(self._speeds.range, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/percentage.py", line 25, in ordered_list_item_to_percentage
    raise ValueError(f'The item "{item}" is not in "{ordered_list}"')
ValueError: The item "1" is not in "['1', '2', '3', '4', '5', '6']"
`
and
`Logger: homeassistant.util.logging
Source: util/logging.py:168
First occurred: 3:17:46 AM (884 occurrences)
Last logged: 12:30:06 PM

Exception in async_write_ha_state when dispatching 'tuya_entry_update_eb4f1b6a49ef3099d4zmye': () Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 742, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 812, in _async_write_ha_state attr.update(self.state_attributes or {}) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 355, in state_attributes data[ATTR_PERCENTAGE] = self.percentage ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 253, in percentage return ordered_list_item_to_percentage(self._speeds.range, value) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/util/percentage.py", line 25, in ordered_list_item_to_percentage raise ValueError(f'The item "{item}" is not in "{ordered_list}"') ValueError: The item "1" is not in "['1', '2', '3', '4', '5', '6']"
Exception in update when dispatching 'ambient_station_data_update_B4:E6:2D:07:36:19': () Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/ambient_station/__init__.py", line 246, in update self._ambient.stations[self._mac_address][ATTR_LAST_DATA][ KeyError: 'humidity1'
Exception in update when dispatching 'ambient_station_data_update_B4:E6:2D:07:36:19': () Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/ambient_station/__init__.py", line 246, in update self._ambient.stations[self._mac_address][ATTR_LAST_DATA][ KeyError: 'humidity5'
Exception in update when dispatching 'ambient_station_data_update_B4:E6:2D:07:36:19': () Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/ambient_station/__init__.py", line 246, in update self._ambient.stations[self._mac_address][ATTR_LAST_DATA][ KeyError: 'temp1f'
Exception in async_write_ha_state when dispatching 'tuya_entry_update_eb4f1b6a49ef3099d4zmye': () Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 742, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 812, in _async_write_ha_state attr.update(self.state_attributes or {}) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 355, in state_attributes data[ATTR_PERCENTAGE] = self.percentage ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 253, in percentage return ordered_list_item_to_percentage(self._speeds.range, value) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/util/percentage.py", line 25, in ordered_list_item_to_percentage raise ValueError(f'The item "{item}" is not in "{ordered_list}"') ValueError: The item "3" is not in "['1', '2', '3', '4', '5', '6']"`

Additional information

From the API debug panel, these are the status and setting configuration values

`

switch | Boolean | "{true,false}" -- | -- | -- mode | Enum | { "range": [ "normal", "sleep", "nature" ] } fan_speed | Enum | { "range": [ "1", "2", "3", "4", "5", "6" ] } fan_direction | Enum | { "range": [ "forward", "reverse" ] } light | Boolean | "{true,false}" bright_value | Integer | { "min": 0, "max": 100, "scale": 0, "step": 1 } temp_value | Integer | { "min": 0, "max": 100, "scale": 0, "step": 1 } countdown_set | Enum | { "range": [ "cancel", "1h", "2h", "4h", "8h" ] }

`

home-assistant[bot] commented 1 year ago

Hey there @tuya, @zlinoliver, @frenck, mind taking a look at this issue as it has been labeled with an integration (tuya) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `tuya` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign tuya` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


tuya documentation tuya source (message by IssueLinks)

issue-triage-workflows[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

WarrenSchultz commented 1 year ago

This is still an issue.

ivabarmar commented 1 year ago

A mí me ocurre lo mismo. En ninguno de los dispositivos con ventilador y luz funciona el ventilador, la luz sí funciona

Zbugsii commented 11 months ago

I have the same problem for two of the fans I have. Light works great. The controls from the Tuya IoT cloud works fine, but on HA the switch for the fan is grayed out and not able to be selected.

soubhik-khan commented 10 months ago

I have the same problem for two of the fans I have. Light works great. The controls from the Tuya IoT cloud works fine, but on HA the switch for the fan is grayed out and not able to be selected.

+1

jtmoore81 commented 9 months ago

I am having the same problem as you. The light portion works great but the fan entity has an error. Might be an issue with the Fan speed % ?

2024-02-07 15:01:00.799 ERROR (MainThread) [homeassistant.components.fan] Error adding entities for domain fan with platform tuya
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 533, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 782, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1325, in add_to_platform_finish
    self.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/fan/__init__.py", line 426, in state_attributes
    data[ATTR_PERCENTAGE] = self.percentage
                            ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 253, in percentage
    return ordered_list_item_to_percentage(self._speeds.range, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/percentage.py", line 32, in ordered_list_item_to_percentage
    raise ValueError(f'The item "{item}" is not in "{ordered_list}"')
ValueError: The item "2" is not in "['1', '2', '3', '4', '5', '6']"
2024-02-07 15:01:00.805 ERROR (MainThread) [homeassistant.components.fan] Error while setting up tuya platform for fan
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 352, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 533, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 782, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1325, in add_to_platform_finish
    self.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/fan/__init__.py", line 426, in state_attributes
    data[ATTR_PERCENTAGE] = self.percentage
                            ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 253, in percentage
    return ordered_list_item_to_percentage(self._speeds.range, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
MadMirza commented 7 months ago

same issue, I have multiple Fans w Lights, only then Light works and it works well, But the Fan is greyed out. Tried local Tuya for the Fan and it works, but wish it just works with Tuya cloud integration.

image
MadMirza commented 7 months ago

Logger: homeassistant.components.fan Source: helpers/entity_platform.py:576 integration: Fan (documentation, issues) First occurred: 4:30:30 AM (3 occurrences) Last logged: 4:30:30 AM

Error adding entity fan.living_room_fan_2 for domain fan with platform tuya
Error adding entity fan.wallace_room_fan_2 for domain fan with platform tuya
Error adding entity fan.master_bedroom_fan_2 for domain fan with platform tuya
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 576, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 865, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1328, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 992, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1113, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1052, in __async_calculate_state
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 426, in state_attributes
    data[ATTR_PERCENTAGE] = self.percentage
                            ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 253, in percentage
    return ordered_list_item_to_percentage(self._speeds.range, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/percentage.py", line 32, in ordered_list_item_to_percentage
    raise ValueError(f'The item "{item}" is not in "{ordered_list}"')
ValueError: The item "5" is not in "['1', '2', '3', '4', '5', '6']"
issue-triage-workflows[bot] commented 4 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

WarrenSchultz commented 4 months ago

Unfortunately, this issue still exists.

pqangel commented 4 months ago

if it sheds some light I have two tuya ceiling fans. Different brands. They both have the same interface yet one is working while the other is not.

Watching the APIs this is what I see in the debug options.

The one that works has fan speed declared like this:

fan_speed_percent | Integer | { "unit": "档", "min": 1, "max": 6, "scale": 0, "step": 1 } -- | -- | --

While the one that doesn't works looks like this:

fan_speed | Enum | { "range": [ "1", "2", "3", "4", "5", "6" ] } -- | -- | --

So basically one is an int and the other is an enum that is taking it's value as a string instead of an int.

Primea1 commented 3 months ago

Still having this same issue.

Zbugsii commented 3 months ago

Yes, still the same... fan portion is not working.

issue-triage-workflows[bot] commented 3 weeks ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

pqangel commented 2 weeks ago

Sadly this is still an issue. There was a related fix on 2024.10.2 with #127860 but sadly it didn't seems that the issue is fixed. I'm still getting the same error after updating to the latest version.

Here you can see the detailed error.

2024-10-30 22:48:12.112 ERROR (MainThread) [homeassistant.components.fan] Error adding entity fan.ceiling_fan_with_light for domain fan with platform tuya Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 595, in _async_add_entities await coro File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 909, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1366, in add_to_platform_finish self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1005, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1130, in _async_write_ha_state self.__async_calculate_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1069, in __async_calculate_state if state_attributes := self.state_attributes: ^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 255, in __getattribute__ return super().__getattribute__(__name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 522, in state_attributes data[ATTR_PERCENTAGE] = self.percentage ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 255, in __getattribute__ return super().__getattribute__(__name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 258, in percentage return ordered_list_item_to_percentage(self._speeds.range, value) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/util/percentage.py", line 29, in ordered_list_item_to_percentage raise ValueError(f'The item "{item}" is not in "{ordered_list}"') ValueError: The item "2" is not in "['1', '2', '3', '4', '5', '6']" 2024-10-30 22:48:13.072 WARNING (MainThread) [homeassistant.components.netatmo] Webhook not registered - https and port 443 is required to register the webhook 2024-10-30 22:48:30.036 ERROR (MainThread) [homeassistant.helpers.dispatcher] Exception in async_write_ha_state when dispatching 'tuya_entry_update_bfb7e686aea4514141tgo5': () Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1005, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1130, in _async_write_ha_state self.__async_calculate_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1069, in __async_calculate_state if state_attributes := self.state_attributes: ^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 255, in __getattribute__ return super().__getattribute__(__name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 522, in state_attributes data[ATTR_PERCENTAGE] = self.percentage ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 255, in __getattribute__ return super().__getattribute__(__name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/tuya/fan.py", line 258, in percentage return ordered_list_item_to_percentage(self._speeds.range, value) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/util/percentage.py", line 29, in ordered_list_item_to_percentage raise ValueError(f'The item "{item}" is not in "{ordered_list}"') ValueError: The item "2" is not in "['1', '2', '3', '4', '5', '6']"