tuya / tuya-home-assistant

Home Assistant integration for controlling Powered by Tuya (PBT) devices using Tuya Open API, maintained by the Home Assistant Community and Tuya Developer Team.
MIT License
860 stars 206 forks source link

AC shows incorrect temperature #15

Closed Zaiban closed 3 years ago

Zaiban commented 3 years ago

Hey, this is a great integration, however I have a small problem with my AC unit showing incorrect temps.

kuva

Inspecting the logs, I can see that the correct temps are visible there ("temp_set": 22, "temp_current": 21):

kuva

However in the UI, instead of the correct values, it shows "-17.8":

kuva

Also, trying to adjust the temp value in the UI is not working:

kuva

tsutsuku commented 3 years ago

@Zaiban Can you provide the device's specification from log, whick like this:

[tuya-openapi] Request: method = GET, url = https://openapi.tuyacn.com/v1.0/devices/vdevo162372586962985/specifications, params = None, body = None, headers = {'client_id': 'xxxxxxxxx', 'sign': '8CAE7BB56BCB387542497366C4D84BCD02F588FE2D3F5F351C20EA1A17981A68', 'sign_method': 'HMAC-SHA256', 'access_token': 'xxxxxxxxxxx', 't': '1624071158713', 'lang': 'en'} [tuya-openapi] Response: { "result": { "category": "wsdcg", "functions": [], "status": [ { "code": "va_temperature", "type": "Integer", "values": "{"unit":"℃","min":-1000,"max":6000,"scale":1,"step":1}" }, { "code": "va_humidity", "type": "Integer", "values": "{"unit":"%","min":0,"max":1000,"scale":1,"step":1}" }, { "code": "battery_percentage", "type": "Integer", "values": "{"unit":"%","min":0,"max":100,"scale":0,"step":1}" } ] }, "success": true, "t": 1624071158836 }

Zaiban commented 3 years ago

[tuya-openapi] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/devices/05005047483fda0efb25/specifications, params = None, body = None, headers = {'client_id': 'xxxx', 'sign': 'A5548D8F561BC8FC67C5172325A927A29645B45E1280376CE5883F22F4EDDC75', 'sign_method': 'HMAC-SHA256', 'access_token': 'xxxx', 't': '1624174087218', 'lang': 'en'} homeassistant_1 | [tuya-openapi] Response: { homeassistant_1 | "result": { homeassistant_1 | "category": "kt", homeassistant_1 | "functions": [ homeassistant_1 | { homeassistant_1 | "code": "fan_speed_enum", homeassistant_1 | "type": "Enum", homeassistant_1 | "values": "{\"range\":[\"low\",\"mid\",\"high\",\"auto\"]}" homeassistant_1 | }, homeassistant_1 | { homeassistant_1 | "code": "mode", homeassistant_1 | "type": "Enum", homeassistant_1 | "values": "{\"range\":[ \"cold\",\"hot\",\"wet\",\"wind\"]}" homeassistant_1 | }, homeassistant_1 | { homeassistant_1 | "code": "temp_set", homeassistant_1 | "type": "Integer", homeassistant_1 | "values": "{\"min\":16,\"unit\":\"℃\",\"scale\":0,\"max\":31,\"type\":\"value\",\"step\":1}" homeassistant_1 | }, homeassistant_1 | { homeassistant_1 | "code": "switch", homeassistant_1 | "type": "Boolean", homeassistant_1 | "values": "" homeassistant_1 | } homeassistant_1 | ], homeassistant_1 | "status": [ homeassistant_1 | { homeassistant_1 | "code": "temp_current", homeassistant_1 | "type": "Integer", homeassistant_1 | "values": "{\"min\":-20,\"scale\":0,\"unit\":\"℃\",\"max\":100,\"step\":1}" homeassistant_1 | }, homeassistant_1 | { homeassistant_1 | "code": "fan_speed_enum", homeassistant_1 | "type": "Enum", homeassistant_1 | "values": "{\"range\":[\"low\",\"mid\",\"high\",\"auto\"]}" homeassistant_1 | }, homeassistant_1 | { homeassistant_1 | "code": "mode", homeassistant_1 | "type": "Enum", homeassistant_1 | "values": "{\"range\":[ \"cold\",\"hot\",\"wet\",\"wind\"]}" homeassistant_1 | }, homeassistant_1 | { homeassistant_1 | "code": "temp_set", homeassistant_1 | "type": "Integer", homeassistant_1 | "values": "{\"min\":16,\"unit\":\"℃\",\"scale\":0,\"max\":31,\"type\":\"value\",\"step\":1}" homeassistant_1 | }, homeassistant_1 | { homeassistant_1 | "code": "switch", homeassistant_1 | "type": "Boolean", homeassistant_1 | "values": "{}" homeassistant_1 | } homeassistant_1 | ] homeassistant_1 | }, homeassistant_1 | "success": true, homeassistant_1 | "t": 1624174087235 homeassistant_1 | }

tsutsuku commented 3 years ago

@Zaiban Get it. This bug will be fixed soon.

ishioni commented 3 years ago

Waiting for a fix for this as well

tsutsuku commented 3 years ago

@Zaiban @ishioni this issue is fixed in v1.3, which release today.

ishioni commented 3 years ago

@Zaiban @ishioni this issue is fixed in v1.3, which release today.

It seems you've deleted the version field in manifest.json. This will not work in the current version of Home Assisstant!

2021-06-30 14:31:05 ERROR (SyncWorker_0) [homeassistant.loader] The custom integration 'tuya_v2' does not have a valid version key (None) in the manifest file and was blocked from loading. See https://developers.home-assistant.io/blog/2021/01/29/custom-integration-changes#versions for more details
2021-06-30 14:31:07 ERROR (MainThread) [homeassistant.setup] Setup failed for tuya_v2: Integration not found.
ishioni commented 3 years ago

@tsutsuku After fixing the missing version, multiple errors, including the original climate one

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/tuya_v2/fan.py", line 72, in async_setup_entry
    await async_discover_device(device_ids)
  File "/config/custom_components/tuya_v2/fan.py", line 56, in async_discover_device
    _LOGGER(f"fan add-> {dev_ids}")
TypeError: 'Logger' object is not callable
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/tuya_v2/humidifier.py", line 42, in async_setup_entry
    _LOGGER("humidifier init")
TypeError: 'Logger' object is not callable
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 383, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 588, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 615, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 368, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 402, in _async_write_ha_state
    state = self._stringify_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 374, in _stringify_state
    state = self.state
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 176, in state
    return self.hvac_mode
  File "/config/custom_components/tuya_v2/climate.py", line 298, in hvac_mode
    return TUYA_HVAC_TO_HA[self.tuya_device.status.get(DPCODE_MODE)]
KeyError: '3'
tsutsuku commented 3 years ago

@ishioni LOGGER problem fixed. About KeyError: '3', can you provide the device's specifications from log?

ishioni commented 3 years ago

@tsutsuku Sure. It's running in cool mode when mode = 3. I played with the API and i have mode 1 = heat 2 = dry 3 = cool 4 = fan It looks like the device specification doesn't match up with what it's reporting

2021-06-30 14:42:03 DEBUG (SyncWorker_0) [tuya iot] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/users/eu16247999663850kJLB/devices, params = None, body = None, headers = {'client_id': 'CENSORED', 'sign': '4C7EF6FFB30E7D92F66C9A158F0FF3A1324981EA8768EFC8603CC6794096D99B', 'sign_method': 'HMAC-SHA256', 'access_token': 'CENSORED', 't': '1625056923156', 'lang': 'en'}
2021-06-30 14:42:03 DEBUG (SyncWorker_0) [tuya iot] Response: {
"result": [
{
"active_time": 1624800048,
"biz_type": 0,
"category": "kt",
"create_time": 1624459589,
"icon": "smart/icon/1493368574_0.png",
"id": "4875044784cca893e465",
"ip": "CENSORED",
"lat": "CENSORED",
"local_key": "CENSORED",
"lon": "CENSORED",
"name": "Paulina AC",
"online": true,
"owner_id": "33144346",
"product_id": "jsf9spFEoWRFozCC",
"product_name": "Portable Air Conditioner",
"status": [
{
"code": "switch",
"value": true
},
{
"code": "mode",
"value": "3"
},
{
"code": "temp_set",
"value": 24
},
{
"code": "windspeed",
"value": "0"
},
{
"code": "c_f",
"value": false
},
{
"code": "temp_set_f",
"value": 55
}
],
"sub": false,
"time_zone": "+01:00",
"uid": "eu16247999663850kJLB",
"update_time": 1624953572,
"uuid": "4875044784cca893e465"
}
],
"success": true,
"t": 1625056923219
}
2021-06-30 14:42:03 DEBUG (SyncWorker_0) [tuya iot] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/devices/4875044784cca893e465/specifications, params = None, body = None, headers = {'client_id': 'CENSORED', 'sign': '7739852EF23C2037DA273BD617FEEB14A66FE3E08269264F6915BACDDB42C1DC', 'sign_method': 'HMAC-SHA256', 'access_token': 'CENSORED', 't': '1625056923238', 'lang': 'en'}
2021-06-30 14:42:03 DEBUG (SyncWorker_0) [tuya iot] Response: {
"result": {
"category": "kt",
"functions": [
{
"code": "switch",
"type": "Boolean",
"values": "{}"
},
{
"code": "mode",
"type": "Enum",
"values": "{\"range\":[\"auto\",\"cold\",\"hot\",\"wet\",\"wind\"]}"
},
{
"code": "temp_set",
"type": "Integer",
"values": "{\"min\":13,\"unit\":\"℃\",\"scale\":0,\"max\":32,\"step\":1}"
},
{
"code": "windspeed",
"type": "Enum",
"values": "{\"range\":[\"1\",\"2\",\"3\",\"0\"]}"
},
{
"code": "c_f",
"type": "Enum",
"values": "{\"range\":[\"C\",\"F\"]}"
},
{
"code": "temp_set_f",
"type": "Integer",
"values": "{\"unit\":\"℉\",\"min\":55,\"max\":90,\"scale\":0,\"step\":1}"
}
],
"status": [
{
"code": "switch",
"type": "Boolean",
"values": "{}"
},
{
"code": "temp_set",
"type": "Integer",
"values": "{\"min\":13,\"unit\":\"℃\",\"scale\":0,\"max\":32,\"step\":1}"
},
{
"code": "c_f",
"type": "Enum",
"values": "{\"range\":[\"C\",\"F\"]}"
},
{
"code": "windspeed",
"type": "Enum",
"values": "{\"range\":[\"1\",\"2\",\"3\",\"0\"]}"
},
{
"code": "mode",
"type": "Enum",
"values": "{\"range\":[\"auto\",\"cold\",\"hot\",\"wet\",\"wind\"]}"
},
{
"code": "temp_set_f",
"type": "Integer",
"values": "{\"unit\":\"℉\",\"min\":55,\"max\":90,\"scale\":0,\"step\":1}"
}
]
},
"success": true,
"t": 1625056923279
}
tsutsuku commented 3 years ago

@ishioni It seems something wrong with this product's specification. We will fix it soon.

tsutsuku commented 3 years ago

@ishioni Can you try again?

ishioni commented 3 years ago

@tsutsuku Updated to master - version is there now, and no more logging errors, but api still returns numerical mode values. Should i power cycle the device?

{
  "result": [
    {
      "code": "switch",
      "value": true
    },
    {
      "code": "mode",
      "value": "3"
    },
    {
      "code": "temp_set",
      "value": 24
    },
    {
      "code": "windspeed",
      "value": "0"
    },
    {
      "code": "c_f",
      "value": false
    },
    {
      "code": "temp_set_f",
      "value": 55
    }
  ],
  "success": true,
  "t": 1625059014381
}
ishioni commented 3 years ago

@tsutsuku Wow, it just stated returning mode = cold. But now we have yet another error! Looks like you're expecting for the AC to return the current room temperature? Mine doesn't provide that, just the target temperature

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 383, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 588, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 615, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 368, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 404, in _async_write_ha_state
    attr.update(self.state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 225, in state_attributes
    self.current_temperature,
  File "/config/custom_components/tuya_v2/climate.py", line 225, in current_temperature
    return self.tuya_device.status.get(DPCODE_TEMP_CURRENT_F, 0) * 1.0 / (10 ** self.get_temp_current_scale())
  File "/config/custom_components/tuya_v2/climate.py", line 145, in get_temp_current_scale
    self.tuya_device.status_range.get(__dp_temp_current).values
AttributeError: 'NoneType' object has no attribute 'values'
tsutsuku commented 3 years ago

@ishioni Is there room temperature in app?

ishioni commented 3 years ago

@tsutsuku No. I've commented out lines 219-225

    # @property
    # def current_temperature(self) -> float:
    #     """Return the current temperature."""
    #     # return 0
    #     if self.__is_celsius():
    #         return self.tuya_device.status.get(DPCODE_TEMP_CURRENT, 0) * 1.0 / (10 ** self.get_temp_current_scale())
    #     return self.tuya_device.status.get(DPCODE_TEMP_CURRENT_F, 0) * 1.0 / (10 ** self.get_temp_current_scale())

And it started to work, but now the temperature is still off. I can control the mode though! Looks like you're treating the temperature as fahrenheit, even though it's celsius. My device has a property c_f which tells if it's in celsius or fahrenheit, and has a separate property temp_set_f for returning the fahrenheit values

Screenshot 2021-06-30 at 15 34 35

Screenshot_20210630-153458

tsutsuku commented 3 years ago

@ishioni We treat code temp_unit_convert as Temperature unit switching. But your ac is c_f. Also the c_f's value "false" is not correct, which should be "C" or "F" as specifications. We will fix it soon.

https://developer.tuya.com/en/docs/iot/s?id=K9gf48r2iqa7m

ishioni commented 3 years ago

@tsutsuku Server side change again?

I've patched the DPCODE_TEMP_UNIT_CONVERT var to use c_f and changed the if condition in __is_celsius and it does work perfectly! Waiting for v1.5 which fixes all of this :)

tsutsuku commented 3 years ago

@ishioni Server side change again.

ishioni commented 3 years ago

@tsutsuku Also, while we're at it. My AC unit has a swing feature, but it's not represented in the api at all. Anything we could do about that? Screenshot_20210630-162700

tsutsuku commented 3 years ago

@ishioni You can replace "fan_speed_enum" with "windspeed" according to AC's Standard Instruction Set https://developer.tuya.com/en/docs/iot/f?id=K9gf46qujdmwb

ishioni commented 3 years ago

@ishioni You can replace "fan_speed_enum" with "windspeed" according to AC's Standard Instruction Set https://developer.tuya.com/en/docs/iot/f?id=K9gf46qujdmwb

Yeah, that adds speed settings, but I'm talking about swing modes - DPCODE_SWITCH_VERTICAL. The device supports it, but the api doesn't report it at all

tsutsuku commented 3 years ago

@ishioni Your device's swing feature is not in the standard instruction set. So it can not be supported.

tsutsuku commented 3 years ago

AC‘s standard instruction set : https://developer.tuya.com/en/docs/iot/s?id=K9gf48r2iqa7m

Zaiban commented 3 years ago

Seems to be working now after upgrading to 1.3. Thanks a lot!

Swing is not working, though that is not a issue for me. I'll close this as the original issue is now fixed.

ishioni commented 3 years ago

@tsutsuku Looks like all my issues have been fixed with 1.3.1, but my AC still returns true/false for c_f. You said it would be a server-side change, so I'm pinging for that. Without it i have to adjust climate.py to work with true/false

ishioni commented 2 years ago

@tsutsuku Hi! Sorry for necroposting, but my device STILL returns true/false for c_f instead of c or f. You told me this was a server-side change, but it never occured. This blocks me from using the official intergration in home assistant as well :c