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

Climates TypeError #28

Open
panic2k opened this issue Jun 25, 2021 · 19 comments
Open

Climates TypeError #28

panic2k opened this issue Jun 25, 2021 · 19 comments
Labels
bug Something isn't working

Comments

@panic2k
Copy link

panic2k commented Jun 25, 2021

2021-06-25 20:11:08 ERROR (MainThread) [homeassistant.components.climate] Error while setting up tuya_v2 platform for climate
Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 258, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 383, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/lib/python3.9/site-packages/homeassistant/helpers/entity_platform.py", line 499, in _async_add_entity
capabilities=entity.capability_attributes,
File "/usr/lib/python3.9/site-packages/homeassistant/components/climate/init.py", line 190, in capability_attributes
ATTR_HVAC_MODES: self.hvac_modes,
File "/var/lib/hass/custom_components/tuya_v2/climate.py", line 261, in hvac_modes
modes = json.loads(self.tuya_device.function.get(DPCODE_MODE, {}).values).get(
File "/usr/lib/python3.9/json/init.py", line 339, in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not builtin_function_or_method

@panic2k
Copy link
Author

panic2k commented Jun 26, 2021

climate.py
test = '{"range":["auto", "cold", "hot", "wet", "wind", "eco", "floor_heat", "floor_heat_and_heat"]}'
modes = json.loads(test).get("range")

When I change line 261 to something like this above the entity is available. Maybe it's just an JSON decode error. I could not get _LOGGER.debug messages in log for better debugging. However, after this change the state of the device is not showing up correctly.
I still hope this helps a little bit.

2021-06-26 13:15:42 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/homeassistant/helpers/entity.py", line 355, in async_update_ha_state
self._async_write_ha_state()
File "/usr/lib/python3.9/site-packages/homeassistant/helpers/entity.py", line 402, in _async_write_ha_state
state = self._stringify_state()
File "/usr/lib/python3.9/site-packages/homeassistant/helpers/entity.py", line 374, in _stringify_state
state = self.state
File "/usr/lib/python3.9/site-packages/homeassistant/components/climate/init.py", line 176, in state
return self.hvac_mode
File "/var/lib/hass/custom_components/tuya_v2/climate.py", line 256, in hvac_mode
return TUYA_HVAC_TO_HA[self.tuya_device.status.get(DPCODE_MODE)]
KeyError: None

@SgtBatten
Copy link

SgtBatten commented Jun 30, 2021

@panic2k I am having issues with my Kogan Branded Heater.

It works in the Tuya v1 integration in that I can control the temperature and turn it on or off.
I installed the tuya v2 integration hoping to gain the fan speed functionality which was missing from v1. My heater is a panel heater with 2 fan modes, high or low. Maybe they are not referred to as fan speed but it is like or high or low power mode essentially. In any case, v1 doesn't give me an attribute or entity for this.

After installing tuya v2 my other devices which work on v1 also seems to work in v2. My heater however shows as a device with zero entities and therefore I have no control of anything, so it is worse than v1.

I have exactly the same error a your first one in my HA log about line 261.

I also do not get any debug logs working using my usual method.

logger:
  default: warning
  logs:
    custom_components.tuya_v2: debug

@tsutsuku
Copy link
Collaborator

@SgtBatten Logs supported in v1.3.
Can you provide your device's specifications from the log?

@SgtBatten
Copy link

SgtBatten commented Jul 1, 2021

@tsutsuku I will gladly assist with this investigation.

In the log I have found a few items which may be what you are referring to. If you are after a specific parameter please let me know.

"category": "qn",

"model": "",

"product_id": "ynjanlglr4qa6dxf",
"product_name": "Panel heater",
2021-07-01 10:12:45 ERROR (MainThread) [custom_components.climate] Error adding entities for domain climate with platform tuya_v2
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 499, in _async_add_entity
capabilities=entity.capability_attributes,
File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 190, in capability_attributes
ATTR_HVAC_MODES: self.hvac_modes,
File "/config/custom_components/tuya_v2/climate.py", line 305, in hvac_modes
modes = json.loads(self.tuya_device.function.get(DPCODE_MODE, {}).values).get(
File "/usr/local/lib/python3.8/json/__init__.py", line 341, in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not builtin_function_or_method
2021-07-01 10:12:45 ERROR (MainThread) [custom_components.climate] Error while setting up tuya_v2 platform for climate
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 258, in _async_setup_platform
await asyncio.gather(*pending)
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 499, in _async_add_entity
capabilities=entity.capability_attributes,
File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 190, in capability_attributes
ATTR_HVAC_MODES: self.hvac_modes,
File "/config/custom_components/tuya_v2/climate.py", line 305, in hvac_modes
modes = json.loads(self.tuya_device.function.get(DPCODE_MODE, {}).values).get(
File "/usr/local/lib/python3.8/json/__init__.py", line 341, in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not builtin_function_or_method

@danielp370
Copy link

Hi, I also have a 'qn' heater. It only responds to limited commands so it also sees the same errors above for any command that the API does not support including min temp, modes, etc. I got it to work and show the entities by quickly hacking up climate.py to ignore those errors, and adding some support for 'on' (via modes). I'd like to have a go and implement this properly - however, I'm not sure how you'd like to go about it. I was thinking of creating a heater.py, but it sounds like there are qn heaters with fans etc, and if so perhaps tweaking climate.py is better?

Here is what my qn heater does support:

Function set:

Code Type Values
switch Boolean {true,false}
level Enum {"range":["1","2"]}
countdown_set Enum {"range":["cancel","1h","2h","4h"]}

State set:

switch Boolean {true,false}
level Enum {"range":["1","2"]}
countdown_set Enum {"range":["cancel","1h","2h","4h"]}

@SgtBatten
Copy link

I am very new to HA in general but also very keen to learn and decent at picking up things with good examples.
@danielp370 How can i provide the equivalent info for my heater or help you get this working.

To clarify, mine may not have a fan necessarily. It just has two modes high and low in the kogan/tuya app. high mode heats up faster is all i can really tell you. The Kogan website describes it as two heat settings.

@panic2k
Copy link
Author

panic2k commented Jul 20, 2021

As i've found out, i have a air conditioner with type kt.
There are no modes announced from the API, the device specification in answer from the API seems to be incomplete.
It's not an issue from Tuya_V2 integration. :-/

{
"active_time": 1624648461,
"biz_type": 18,
"category": "kt",
"create_time": 1624648461,
"icon": "smart/icon/ay15105372588696Qo9c/9ad2228ea92cbee431855939d26c62ab.png",
"id": "bfb91179c47704014ajuni",
"ip": "xyz",
"lat": "",
"local_key": "asdf",
"lon": "",
"name": "Air Condition-A011_F",
"online": true,
"owner_id": "28503226",
"product_id": "5pcdieqpi0dfolle",
"product_name": "Air Condition-A011_F",
"status": [
{
"code": "switch",
"value": false
},
{
"code": "temp_set",
"value": 23
},
{
"code": "temp_current",
"value": 23
},
{
"code": "lock",
"value": false
},
{
"code": "swing",
"value": false
},
{
"code": "temp_unit_convert",
"value": "c"
},
{
"code": "temp_set_f",
"value": 61
},
{
"code": "temp_current_f",
"value": 21
}
],
"sub": false,
"time_zone": "+02:00",
"uid": "eu1617290092467bc4x8",
"update_time": 1626787473,
"uuid": "12a1c87c3d4e87d8"
}


2021-07-20 14:03:39 DEBUG (SyncWorker_2) [tuya iot] Request: method = GET, url = https://openapi.tuyaeu.com/v1.0/devices/bfb91179c47704014ajuni/specifications, params = None, body = None, headers = {'client_id': 'pj453rjxao4cymwnpruq', >2021-07-20 14:03:39 DEBUG (SyncWorker_2) [tuya iot] Response: {
"result": {
"category": "kt",
"functions": [
{
"code": "switch",
"type": "Boolean",
"values": "{}"
},
{
"code": "temp_set",
"type": "Integer",
"values": "{"unit":"℃","min":16,"max":32,"scale":0,"step":1}"
},
{
"code": "lock",
"type": "Boolean",
"values": "{}"
},
{
"code": "swing",
"type": "Boolean",
"values": "{}"
},
{
"code": "temp_unit_convert",
"type": "Enum",
"values": "{"range":["c","f"]}"
},
{
"code": "temp_set_f",
"type": "Integer",
"values": "{"unit":"℉","min":61,"max":90,"scale":0,"step":1}"
}
],
"status": [
{
"code": "switch",
"type": "Boolean",
"values": "{}"
},
{
"code": "temp_set",
"type": "Integer",
"values": "{"unit":"℃","min":16,"max":32,"scale":0,"step":1}"
},
{
"code": "temp_current",
"type": "Integer",
"values": "{"unit":"℃","min":0,"max":99,"scale":0,"step":1}"
},
{
"code": "lock",
"type": "Boolean",
"values": "{}"
},
{
"code": "swing",
"type": "Boolean",
"values": "{}"
},
{
"code": "temp_unit_convert",
"type": "Enum",
"values": "{"range":["c","f"]}"
},
{
"code": "temp_set_f",
"type": "Integer",
"values": "{"unit":"℉","min":61,"max":90,"scale":0,"step":1}"
},
{
"code": "temp_current_f",
"type": "Integer",
"values": "{"unit":"℉","min":0,"max":99,"scale":0,"step":1}"
}
]
},
"success": true,
"t": 1626789819654
}

@alann81
Copy link

alann81 commented Jul 24, 2021

Also using a kt air conditioner, following error in logs using v1.4.0:

Logger: homeassistant.components.climate
Source: custom_components/tuya_v2/climate.py:353
Integration: Climate (documentation, issues)
First occurred: 5:13:45 PM (2 occurrences)
Last logged: 5:13:45 PM

Error adding entities for domain climate with platform tuya_v2
Error while setting up tuya_v2 platform for climate
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 499, in _async_add_entity
capabilities=entity.capability_attributes,
File "/usr/src/homeassistant/homeassistant/components/climate/init.py", line 219, in capability_attributes
ATTR_HVAC_MODES: self.hvac_modes,
File "/config/custom_components/tuya_v2/climate.py", line 353, in hvac_modes
modes = json.loads(self.tuya_device.function.get(DPCODE_MODE, {}).values).get(
File "/usr/local/lib/python3.9/json/init.py", line 339, in loads
raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not builtin_function_or_method

Device details from log:

{
"active_time": 1611567783,
"biz_type": 0,
"category": "kt",
"create_time": 1611557820,
"icon": "smart/icon/ay15253387844269Sg99/d5401b2b8f67cffe2a26530c926f4876.png",
"id": "REDACTED",
"ip": "REDACTED",
"lat": "REDACTED",
"local_key": "REDACTED",
"lon": "REDACTED",
"name": "Garage Air Conditioner",
"online": true,
"owner_id": "REDACTED",
"product_id": "mhod7aykax0wbivn",
"product_name": "Kogan Smarter Home™ 2.6kW Portable Air Conditioner",
"status": [
{
"code": "switch",
"value": false
},
{
"code": "temp_set",
"value": 22
},
{
"code": "temp_current",
"value": 19
},
{
"code": "windspeed",
"value": "1"
}
],
"sub": false,
"time_zone": "REDACTED",
"uid": "REDACTED",
"update_time": 1627108950,
"uuid": "REDACTED"
},

@panic2k
Copy link
Author

panic2k commented Jul 24, 2021

Yes, it's the same issue. No modes are submitted from API for your device. Therefore Tuya_V2 rises the TypeError.

@tsutsuku tsutsuku added the bug Something isn't working label Jul 26, 2021
@thewolf-oz
Copy link

I get the same with a different 'qn' category panel heater (Arlec heater from Australia)

@SgtBatten
Copy link

SgtBatten commented Sep 10, 2021

I am using the tuya v1 integration for my panel heater and have set up a scene for high and low power modes. Seems to work for my use case except that the scene indicator is only one-way communication so if it gets changed on the device or using the tuya app, HA doesn't know.

Will be great once this is properly integrated in v2

@SgtBatten
Copy link

SgtBatten commented Oct 10, 2021

Now that tuya v2 is the official integration this issue is more significant as i've lost the ability to turn the heater on and off which i had in v1

Any solutions @tsutsuku ?

@danielp370
Copy link

danielp370 commented Oct 10, 2021 via email

@SgtBatten
Copy link

you tried tuya-local?

I have not, though it doesn't look like it supports climates yet?

@danielp370
Copy link

danielp370 commented Oct 12, 2021 via email

@some-guy-in-oz
Copy link

As mentioned by others, your device isn't reporting what modes it supports which is causing that error. This is out of the control of the Tuya Devs. You could try using the patched version of climate to see if that helps. You're probably better off using the HACS version of Tuya V2 rather than the official as the HACS version will always be more recent. Take a copy of your existing climate.py in case you want to restore it!
climate.zip

@jandy123
Copy link

jandy123 commented Dec 23, 2021

I also have a problem with a qn heater. Tuya v2 integration is useless in this case, since although the device is detected, it has no entities. The culprit is the Tuya cloud binding/detection. The device is seen as a simple switch wiht json instruction set

[
  {
    "code": "switch",
    "value": false
  }
]

Another device but with a newer Tuya firmware is detected correctly and works fine with Tuya v2 api. The instruction set is:

 [
  {
    "code": "c_f",
    "value": "C"
  },
  {
    "code": "temp_set_f",
    "value": 32
  },
  {
    "code": "temp_set",
    "value": 22
  },
  {
    "code": "switch",
    "value": false
  }
]

The wired and ugly part is that I cannot perform a firmware update in the official tuya app, which I have no clue why...

====
For now I use the old Tuya integration, but when hassio won't be compatible anymore, I'll have a problem.

Any ideas what I can try? Somebody else with the same problem?

@frenck
Copy link
Collaborator

frenck commented Feb 3, 2022

Yesterday, Home Assistant 2022.2 was released.
Could you try upgrading to that version and see if the issue has been resolved?

If not, Home Assistant 2022.2 contains a new diagnostic tool. There is now a "Download Diagnostics" button on each Tuya device on the device page. Clicking that button will download diagnostics information for that specific device. Drag the downloaded file into this issue. It will help with finding out what the problem is.

@JanLankhorst
Copy link

Hi @frenck ,
I am having the same problem as described above. Installed a new Vonroc Heater based on TuYa. It's working fine with the SmartLife App. I managed to install the Tuya integration based on the doc's, created project etc.etc. HA sees the heater, defines it as Entity: climate... No on /off present.

Any clue?

Diagnostics below:

{
"home_assistant": {
"installation_type": "Home Assistant OS",
"version": "2023.7.3",
"dev": false,
"hassio": true,
"virtualenv": false,
"python_version": "3.11.4",
"docker": true,
"arch": "x86_64",
"timezone": "Europe/Amsterdam",
"os_name": "Linux",
"os_version": "6.1.39",
"supervisor": "2023.07.1",
"host_os": "Home Assistant OS 10.4",
"docker_version": "23.0.6",
"chassis": "embedded",
"run_as_root": true
},
"custom_components": {
"alarmo": {
"version": "v1.9.10",
"requirements": []
},
"hacs": {
"version": "1.32.1",
"requirements": [
"aiogithubapi>=22.10.1"
]
},
"entsoe": {
"version": "0.0.1",
"requirements": [
"entsoe-py==0.5.8"
]
},
"energyscore": {
"version": "1.3.3",
"requirements": []
},
"asusrouter": {
"version": "0.21.1",
"requirements": [
"asusrouter==0.20.3"
]
},
"afvalbeheer": {
"version": "5.2.7",
"requirements": [
"rsa",
"pycryptodome"
]
},
"zha_toolkit": {
"version": "v0.9.5",
"requirements": [
"pytz"
]
},
"nordpool": {
"version": "0.0.14",
"requirements": [
"nordpool>=0.2",
"backoff"
]
},
"scheduler": {
"version": "v0.0.0",
"requirements": []
},
"schedule_state": {
"version": "0.18.1",
"requirements": [
"portion==2.3.0"
]
}
},
"integration_manifest": {
"domain": "tuya",
"name": "Tuya",
"codeowners": [
"@tuya",
"@zlinoliver",
"@frenck"
],
"config_flow": true,
"dependencies": [
"ffmpeg"
],
"dhcp": [
{
"macaddress": "105A17*"
},
{
"macaddress": "10D561*"
},
{
"macaddress": "1869D8*"
},
{
"macaddress": "381F8D*"
},
{
"macaddress": "508A06*"
},
{
"macaddress": "68572D*"
},
{
"macaddress": "708976*"
},
{
"macaddress": "7CF666*"
},
{
"macaddress": "84E342*"
},
{
"macaddress": "D4A651*"
},
{
"macaddress": "D81F12*"
}
],
"documentation": "https://www.home-assistant.io/integrations/tuya",
"integration_type": "hub",
"iot_class": "cloud_push",
"loggers": [
"tuya_iot"
],
"requirements": [
"tuya-iot-py-sdk==0.6.6"
],
"is_built_in": true
},
"data": {
"endpoint": "https://openapi.tuyaeu.com",
"auth_type": 0,
"country_code": "31",
"app_type": "smartlife",
"mqtt_connected": true,
"disabled_by": null,
"disabled_polling": false,
"name": "Vonroc Smart Heater",
"model": "GPH-XA-HEMAN",
"category": "qn",
"product_id": "igx4agetzjknlnhr",
"product_name": "Vonroc Smart Heater",
"online": true,
"sub": false,
"time_zone": "+02:00",
"active_time": "2023-08-03T17:53:34+00:00",
"create_time": "2023-08-03T17:53:34+00:00",
"update_time": "2023-08-03T17:53:41+00:00",
"function": {
"lock": {
"type": "Boolean",
"value": {}
},
"light": {
"type": "Boolean",
"value": {}
},
"countdown_set": {
"type": "Enum",
"value": {
"range": [
"cancel",
"1h",
"2h",
"3h",
"4h",
"5h",
"6h"
]
}
}
},
"status_range": {
"lock": {
"type": "Boolean",
"value": {}
},
"light": {
"type": "Boolean",
"value": {}
},
"countdown_set": {
"type": "Enum",
"value": {
"range": [
"cancel",
"1h",
"2h",
"3h",
"4h",
"5h",
"6h"
]
}
}
},
"status": {
"lock": false,
"light": true,
"countdown_set": "cancel"
},
"home_assistant": {
"name": "Vonroc Smart Heater",
"name_by_user": null,
"disabled": false,
"disabled_by": null,
"entities": [
{
"disabled": false,
"disabled_by": null,
"entity_category": null,
"device_class": null,
"original_device_class": null,
"icon": null,
"original_icon": null,
"unit_of_measurement": null,
"state": {
"entity_id": "climate.vonroc_smart_heater",
"state": "off",
"attributes": {
"hvac_modes": [],
"min_temp": 7,
"max_temp": 35,
"target_temp_step": 1.0,
"current_temperature": null,
"friendly_name": "Badkamer_Verwarming",
"supported_features": 0
},
"last_changed": "2023-08-03T19:09:06.796719+00:00",
"last_updated": "2023-08-03T19:09:06.796719+00:00"
}
},
{
"disabled": false,
"disabled_by": null,
"entity_category": "config",
"device_class": null,
"original_device_class": null,
"icon": null,
"original_icon": null,
"unit_of_measurement": null,
"state": {
"entity_id": "light.vonroc_smart_heater_backlight",
"state": "on",
"attributes": {
"supported_color_modes": [
"onoff"
],
"color_mode": "onoff",
"friendly_name": "Vonroc Smart Heater Backlight",
"supported_features": 0
},
"last_changed": "2023-08-03T18:31:19.372219+00:00",
"last_updated": "2023-08-03T18:31:19.372219+00:00"
}
},
{
"disabled": false,
"disabled_by": null,
"entity_category": "config",
"device_class": null,
"original_device_class": null,
"icon": null,
"original_icon": "mdi:account-lock",
"unit_of_measurement": null,
"state": {
"entity_id": "switch.vonroc_smart_heater_child_lock",
"state": "off",
"attributes": {
"icon": "mdi:account-lock",
"friendly_name": "Vonroc Smart Heater Child lock"
},
"last_changed": "2023-08-03T18:31:19.499523+00:00",
"last_updated": "2023-08-03T18:31:19.499523+00:00"
}
}
]
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants