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
69.03k stars 28.28k forks source link

Tuya integration no longer updates HA State #114100

Open amithkk opened 1 month ago

amithkk commented 1 month ago

The problem

The Tuya integration no longer updates state on HA. This means that a light, for instance can be "turned on" from HA but the state continues to show that it is turned off. This also makes it impossible to turn off a light from the dashboard. (The "turn off" service works fine)

This is the new version of the Tuya integration which directly connects to the SmartLife app via a pairing code and is not connected to the Tuya IoT Cloud (therefore, this is not an issue of the app trial expiring on the Tuya Cloud)

There seems to be an error in the logs that is relevant. Perhaps the format of the data returned by the Tuya API has changed:

2024-03-24 15:15:18.953 ERROR (MainThread) [homeassistant.util.logging] Exception in async_write_ha_state when dispatching 'tuya_entry_update_d7c88c9a319ecbb5efipav': ()
Traceback (most recent call last):
  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/light/__init__.py", line 1215, in state_attributes
    color_temp_kelvin = self.color_temp_kelvin
                        ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 977, in color_temp_kelvin
    if self._attr_color_temp_kelvin is None and (color_temp := self.color_temp):
                                                               ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/light.py", line 684, in color_temp
    self._color_temp.remap_value_to(
  File "/usr/src/homeassistant/homeassistant/components/tuya/base.py", line 63, in remap_value_to
    return remap_value(value, self.min, self.max, to_min, to_max, reverse)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/util.py", line 15, in remap_value
    value = from_max - value + from_min
            ~~~~~~~~~^~~~~~~
TypeError: unsupported operand type(s) for -: 'int' and 'str'

What version of Home Assistant Core has the issue?

core-2024.3.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

tuya

Link to integration documentation on our website

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

Diagnostics information

home-assistant_tuya_2024-03-24T09-45-26.004Z.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 1 month 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. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


tuya documentation tuya source (message by IssueLinks)

Chobnob commented 1 month ago

Exactly the same issue as described on Raspberry Pi4 with 24.3.1

skygek commented 1 month ago

Точно такая же проблема, как описана в Raspberry

F8VPE commented 1 month ago

I do have the same problem on a RPI4, I cannot see if it's turned on, to turn it off I have to click two times. In SmartLife everything is okay. When I use LocalTuya it do works normally with exception of groups.yaml, when I swith this entity off it works but on screen it's returning to the on-state while the lamps staying off. The problem exist after the last update 24.3.3 so I don't think it's a Tuya problem. Also my electricity meters won't update anymore, in SmartLife they do normally.

F8VPE commented 1 month ago

problem solved since last update (04-2024)

amithkk commented 1 month ago

@F8VPE Can still reproduce issue on 2024.4.3. The same error is logged as well

2024-04-14 15:15:41.616 ERROR (MainThread) [homeassistant.util.logging] Exception in async_write_ha_state when dispatching 'tuya_entry_update_d7c88c9a319ecbb5efipav': ()
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1119, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1058, in __async_calculate_state
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 1205, in state_attributes
    data[ATTR_BRIGHTNESS] = self.brightness
                            ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/light.py", line 657, in brightness
    brightness = self._brightness.remap_value_to(brightness)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/base.py", line 64, in remap_value_to
    return remap_value(value, self.min, self.max, to_min, to_max, reverse)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/tuya/util.py", line 17, in remap_value
    return ((value - from_min) / (from_max - from_min)) * (to_max - to_min) + to_min
             ~~~~~~^~~~~~~~~~
TypeError: unsupported operand type(s) for -: 'str' and 'int'
F8VPE commented 1 month ago

@amithkk I'm still using the Tuya cloud but with the last update of march I've got simulair problems. With 2024.4.3. everything is working normal again. Have to say that I changed the most entities using LocalTuya, works quicker and worked also before the latest update. Also the thermostats and electricity meters are working again now. You may try using the cloud again to find out if your problems are gone. If so contact Tuya directly.

gautamkrishnar commented 1 month ago

@F8VPE the underlying problem is. not yet fixed. Migrating to tuya local is an option but tuya team basically had re-written the extension in their last update to make it work locally similar to tuya local. Now it do not need a cloud api key. that's where the problems actually started.

F8VPE commented 1 month ago

Thanks Gautam , I will still using the cloud untill this is problem is repaired.

amithkk commented 1 week ago

Bumping this, since it's still completely broken