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

Zigbee Thermostat KTWKQ03ES (lumi.airrtc.tcpecn02) unavailable, parsing error? #1262

Closed
lizhaobibi opened this issue Jan 13, 2024 · 19 comments
Closed
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@lizhaobibi
Copy link

lizhaobibi commented Jan 13, 2024

Just added a new Thermostat, which I think is supported by this integration. But it keeps shows as "Climate Unavailable", and the logs show an Error when parsing the MQTT msgs.
Could you take a look?

Thanks.

**HASS 2024.1.2
Xiaomi Gateawy3 v3.3.5
Xiaomi Multimode Gateway (CN) 1.5.6
Lumi Thermostat KTWKQ03ES Firmware: 20
**

Here is the logs:

This error originated from a custom integration.

Logger: custom_components.xiaomi_gateway3.core.gateway
Source: custom_components/xiaomi_gateway3/core/gateway/base.py:108 
Integration: Xiaomi Gateway 3 (documentation, issues) 
First occurred: 2:43:41 PM (19 occurrences) 
Last logged: 2:48:35 PM

192.168.50.124 | ERROR processing MQTT: zigbee/send b'{"cmd":"report","id":109,"did":"lumi.158d0003cd7015","time":1705128421794,"rssi":-51,"zseq":32,"params":[{"res_name":"14.2.85","value":271588181},{"res_name":"14.8.85","value":0},{"res_name":"14.9.85","value":27},{"res_name":"14.10.85","value":3},{"res_name":"3.2.85","value":21},{"res_name":"3.1.85","value":1}],"dev_src":"0"}'
192.168.50.124 | ERROR processing MQTT: zigbee/send b'{"cmd":"report","id":109,"did":"lumi.158d0003cd7015","time":1705128428994,"rssi":-51,"zseq":34,"params":[{"res_name":"14.2.85","value":271588186},{"res_name":"14.8.85","value":0},{"res_name":"14.9.85","value":27},{"res_name":"14.10.85","value":3},{"res_name":"3.2.85","value":22},{"res_name":"3.1.85","value":1}],"dev_src":"0"}'
192.168.50.124 | ERROR processing MQTT: zigbee/send b'{"cmd":"report","id":109,"did":"lumi.158d0003cd7015","time":1705128429634,"rssi":-51,"zseq":36,"params":[{"res_name":"14.2.85","value":271588186},{"res_name":"14.8.85","value":0},{"res_name":"14.9.85","value":27},{"res_name":"14.10.85","value":3},{"res_name":"3.2.85","value":22},{"res_name":"3.1.85","value":1}],"dev_src":"0"}'
192.168.50.124 | ERROR processing MQTT: zigbee/send b'{"cmd":"report","id":2000000188,"did":"lumi.158d0003cd7015","time":1705128438954,"rssi":-51,"zseq":38,"params":[{"res_name":"14.2.85","value":271588183},{"res_name":"14.8.85","value":0},{"res_name":"14.9.85","value":27},{"res_name":"14.10.85","value":3},{"res_name":"3.2.85","value":21},{"res_name":"3.1.85","value":1}],"dev_src":"0"}'
192.168.50.124 | ERROR processing MQTT: zigbee/send b'{"cmd":"heartbeat","id":2000000200,"time":1705128514214,"rssi":-51,"params":[{"did":"lumi.158d0003cd7015","time":1705128514214,"zseq":43,"res_list":[{"res_name":"8.0.2006","value":38},{"res_name":"8.0.2002","value":58},{"res_name":"8.0.2022","value":20},{"res_name":"8.0.2023","value":52},{"res_name":"8.0.2228","value":2048},{"res_name":"14.2.85","value":271588183},{"res_name":"8.0.2007","value":196}]}]}'
Traceback (most recent call last):
  File "/config/custom_components/xiaomi_gateway3/core/gateway/__init__.py", line 170, in mqtt_message
    await self.dispatcher_send(SIGNAL_MQTT_PUB, msg=msg)
  File "/config/custom_components/xiaomi_gateway3/core/gateway/base.py", line 108, in dispatcher_send
    await handler(**kwargs)
  File "/config/custom_components/xiaomi_gateway3/core/gateway/lumi.py", line 56, in lumi_mqtt_publish
    await self.lumi_process_lumi(msg.json)
  File "/config/custom_components/xiaomi_gateway3/core/gateway/lumi.py", line 103, in lumi_process_lumi
    payload = device.decode_lumi(data[k])
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/xiaomi_gateway3/core/device.py", line 368, in decode_lumi
    self.available = True
    ^^^^^^^^^^^^^^
  File "/config/custom_components/xiaomi_gateway3/core/device.py", line 133, in available
    self.update_available()
  File "/config/custom_components/xiaomi_gateway3/core/device.py", line 450, in update_available
    entity.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 941, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1062, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1001, in __async_calculate_state
    attr.update(self.state_attributes or {})
                ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 369, in state_attributes
    hass, self.target_temperature_high, temperature_unit, precision
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/backports/functools.py", line 70, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 449, in target_temperature_high
    return self._attr_target_temperature_high
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 338, in _getter
    return getattr(o, private_attr_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'XiaomiClimate' object has no attribute '__attr_target_temperature_high'
@vermut
Copy link

vermut commented Jan 23, 2024

I can confirm that zigbee KTWKQ03ES (lumi.airrtc.tcpecn02) by Aqara worked before and became broken couple of weeks ago with error above.

Fix from PR worked for me, changing TARGET_TEMPERATURE_RANGE to TARGET_TEMPERATURE

_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE

@vermut
Copy link

vermut commented Jan 23, 2024

I can also mention that OFF mode is not parsed correctly. Changing mode from HEAT to OFF works on device (it gets switched off) but Hass widget shows the last mode (HEAT or COLD depending what was enable when I turned it off).

Logbook looks like this (turning on and off couple of times):

January 23, 2024
X changed to January 23, 2024 at 10:00
10:00:40 - Now
X changed to January 23, 2024 at 09:59
09:59:47 - 1 minute ago
X changed to January 23, 2024 at 09:59
09:59:43 - 1 minute ago
X changed to January 23, 2024 at 09:59
09:59:40 - 1 minute ago
X changed to Heat triggered by service Climate: Set HVAC mode

@lizhaobibi
Copy link
Author

lizhaobibi commented Jan 23, 2024

Yes, I have the same experience with the pending PR. I believe this “state” issue might exist much longer than we thought as it was mentioned in here.

@Joee-D
Copy link
Contributor

Joee-D commented Jan 24, 2024

@vermut @lizhaobibi

Let's continue the discussion in this issue.
The problem may be that the device does not use the mode value but switch status to reflect its ON/OFF state.
https://home.miot-spec.com/spec/lumi.airrtc.tcpecn02
I had a similar problem when I adapt my HVAC device.
You may try the following modifications to see if it works as expected.

/custom_components/xiaomi_gateway3/core/converters/devices.py

{
    # https://github.com/AlexxIT/XiaomiGateway3/issues/101
    "lumi.airrtc.tcpecn02": ["Aqara", "Thermostat S2 CN", "KTWKQ03ES"],
    "spec": [
        # BoolConv("power", mi="3.1.85", xiaomi="power_status"),
        ClimateConv("climate", "climate", mi="14.2.85"),
+       BoolConv("power", mi="3.1.85"),
        Converter("current_temp", mi="3.2.85"),
        MapConv("hvac_mode", mi="14.8.85", map={0: "heat", 1: "cool", 15: "off"}),
        MapConv("fan_mode", mi="14.10.85", map={
            0: "low", 1: "medium", 2: "high", 3: "auto"
        }),
        ClimateTempConv("target_temp", mi="14.9.85"),
    ],
}, 

/custom_components/xiaomi_gateway3/climate.py

class XiaomiClimate(XEntity, ClimateEntity):
    _attr_fan_mode = None
    _attr_fan_modes = [FAN_LOW, FAN_MEDIUM, FAN_HIGH, FAN_AUTO]
    _attr_hvac_mode = None
    _attr_hvac_modes = [HVACMode.OFF, HVACMode.COOL, HVACMode.HEAT]
    _attr_precision = PRECISION_WHOLE
    _attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.FAN_MODE
    _attr_temperature_unit = UnitOfTemperature.CELSIUS
    # support only KTWKQ03ES for now
    _attr_max_temp = 30
    _attr_min_temp = 17
    _attr_target_temperature_step = 1
+   _enabled = None
+   _mode = None

    @callback
    def async_set_state(self, data: dict):
+       self._enabled = data.get("power")
        self._attr_current_temperature = data.get("current_temp")
        self._attr_fan_mode = data.get("fan_mode")
-       self._attr_hvac_mode = data.get("hvac_mode")
+       self._mode = data.get("hvac_mode")
        # better support HomeKit
        # https://github.com/AlexxIT/XiaomiGateway3/issues/707#issuecomment-1099109552
        self._attr_hvac_action = ACTIONS.get(self._attr_hvac_mode)
        # fix scenes with turned off climate
        # https://github.com/AlexxIT/XiaomiGateway3/issues/101#issuecomment-757781988
        self._attr_target_temperature = data.get("target_temp", 0)
+       self._attr_hvac_mode = self._mode if self._enabled else HVACMode.OFF

You can collect and parse the log if it still not work or has other problems, as I do not have your KTWKQ03ES device.

@lizhaobibi
Copy link
Author

Got a chance to try it out today, the code works just fine and solve the state issue. Is it possible to push it to mainstream as part of your pending PR too? @Joee-D

@Joee-D
Copy link
Contributor

Joee-D commented Jan 31, 2024

Got a chance to try it out today, the code works just fine and solve the state issue. Is it possible to push it to mainstream as part of your pending PR too? @Joee-D

1431109

@AlexxIT AlexxIT added the enhancement New feature or request label Feb 19, 2024
@AlexxIT AlexxIT self-assigned this Feb 19, 2024
@ptbsare
Copy link

ptbsare commented Mar 12, 2024

hi,any updates on this issue?
Can confirm this issue not fixed in the latest release
ha 2024.3.0

@ptbsare
Copy link

ptbsare commented Mar 13, 2024

PR #1255 Fixed this.

@AlexxIT AlexxIT added this to the v4.0.0 milestone Mar 24, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Mar 31, 2024

@AlexxIT AlexxIT closed this as completed Mar 31, 2024
@vermut
Copy link

vermut commented Apr 5, 2024

Looks good in 4.0.1. I had to pair them again (even if they were connected in Mi Home app)

@ptbsare
Copy link

ptbsare commented Apr 6, 2024

hi @AlexxIT , I noticed that the temperature history of this device was abnormal.(went between 0 and 30+C° continually during which the climate was turned off)
Any ideas?
v4.0.2
Latest HA.
Tried delete and re-pair the device. Same result.

@ptbsare
Copy link

ptbsare commented Apr 6, 2024

IMG_20240406_171826

@AlexxIT
Copy link
Owner

AlexxIT commented Apr 6, 2024

You can collect logs. It's very difficult to support so complex device without it

@ptbsare
Copy link

ptbsare commented Apr 6, 2024

cat home-assistant_xiaomi_gateway3_2024-04-06T15-14-23.648Z.log |grep lumi.158d0004054c4f > tcpecn02.log

hi @AlexxIT The log is pretty long. You can find it here, thanks : D
tcpecn02.log

@ptbsare
Copy link

ptbsare commented Apr 6, 2024

The initial support for this device was added here. #101 (year 2020)
Maybe some additional info can be found.

@AlexxIT
Copy link
Owner

AlexxIT commented Apr 6, 2024

I think state updates fixed in latest master version

@AlexxIT
Copy link
Owner

AlexxIT commented Apr 7, 2024

@ptbsare
Copy link

ptbsare commented Apr 7, 2024

hi @AlexxIT v4.0.3 fixed the history issue.
but I noticed that I cannot set target temperature in the HA ui. (target termperature not changed)
logs below
tcpecn02.2.log

I set target temperature to 21°C at around 2024-04-07 23:23

@AlexxIT
Copy link
Owner

AlexxIT commented Apr 8, 2024

Looks like setting target temp never worked. Fixed in latest master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants