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

BT devices not available after restarting HA #1322

Closed
3 tasks done
soeoeb opened this issue Mar 21, 2024 · 31 comments
Closed
3 tasks done

BT devices not available after restarting HA #1322

soeoeb opened this issue Mar 21, 2024 · 31 comments
Assignees
Labels
bug Something isn't working wait for feedback

Comments

@soeoeb
Copy link

soeoeb commented Mar 21, 2024

  • Model name of your Devices: ME167 Wireless Smart Radiator Thermostat (tuya)

  • Output from Home Assistant Developer Tools state e.g.:
    State of climate.bt_test: unavailable

hvac_modes:

  • heat
  • "off"
    min_temp: 5
    max_temp: 35
    target_temp_step: 1
    friendly_name: BT Test
    supported_features: 385
  • Output from Home Assistant Device Diagnostic from BT:
{
  {
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2024.3.1",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.12.2",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Berlin",
    "os_name": "Linux",
    "os_version": "6.6.20-haos",
    "supervisor": "2024.03.0",
    "host_os": "Home Assistant OS 12.1",
    "docker_version": "24.0.7",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "better_thermostat": {
      "version": "1.4.0",
      "requirements": []
    },
    "hacs": {
      "version": "1.34.0",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    },
    "homee": {
      "version": "2.9.2",
      "requirements": [
        "pymee==1.11.1",
        "websockets==11.0.1"
      ]
    },
    "localtuya": {
      "version": "5.2.1",
      "requirements": []
    },
    "em6": {
      "version": "1.0.0",
      "requirements": []
    }
  },
  "integration_manifest": {
    "domain": "better_thermostat",
    "name": "Better Thermostat",
    "after_dependencies": [
      "climate"
    ],
    "codeowners": [
      "@kartoffeltoby"
    ],
    "config_flow": true,
    "dependencies": [
      "climate",
      "recorder"
    ],
    "documentation": "https://github.com/KartoffelToby/better_thermostat",
    "iot_class": "local_push",
    "issue_tracker": "https://github.com/KartoffelToby/better_thermostat/issues",
    "requirements": [],
    "version": "1.4.0",
    "is_built_in": false
  },
  "data": {
    "info": {
      "name": "BT Test",
      "temperature_sensor": "sensor.temperatursensor_1_temperatur",
      "off_temperature": 20,
      "humidity_sensor": "sensor.temperatursensor_1_luftfeuchtigkeit",
      "window_sensors": "binary_sensor.kontaktsensor_tur",
      "tolerance": 1.0,
      "outdoor_sensor": null,
      "weather": null,
      "cooler": null,
      "window_off_delay": 0,
      "window_off_delay_after": 1,
      "model": "p3dbf6qs"
    },
    "thermostat": {
      "climate.seb_s_heizung": {
        "name": "Seb's Heizung",
        "state": "heat_cool",
        "attributes": {
          "hvac_modes": [
            "off",
            "heat_cool",
            "heat_cool",
            "heat"
          ],
          "min_temp": 5.0,
          "max_temp": 35.0,
          "target_temp_step": 1.0,
          "preset_modes": [
            "off"
          ],
          "current_temperature": 18.0,
          "temperature": 33.5,
          "preset_mode": null,
          "friendly_name": "Seb's Heizung",
          "supported_features": 17
        },
        "bt_config": {
          "calibration": "target_temp_based",
          "calibration_mode": "heating_power_calibration",
          "protect_overheating": false,
          "no_off_system_mode": true,
          "heat_auto_swapped": true,
          "child_lock": false,
          "homaticip": false
        },
        "bt_adapter": "tuya",
        "bt_integration": "tuya",
        "model": "p3dbf6qs"
      }
    },
    "external_temperature_sensor": {
      "entity_id": "sensor.temperatursensor_1_temperatur",
      "state": "18.6",
      "attributes": {
        "state_class": "measurement",
        "unit_of_measurement": "\u00b0C",
        "device_class": "temperature",
        "friendly_name": "Temperatursensor 1 Temperatur"
      },
      "last_changed": "2024-03-21T13:45:00.793079+00:00",
      "last_updated": "2024-03-21T13:45:00.793079+00:00",
      "context": {
        "id": "01HSGM41KSNJF5JNS0Y9MAXW0K",
        "parent_id": null,
        "user_id": null
      }
    },
    "window_sensor": {
      "entity_id": "binary_sensor.kontaktsensor_tur",
      "state": "off",
      "attributes": {
        "device_class": "door",
        "friendly_name": "Kontaktsensor 1 T\u00fcr"
      },
      "last_changed": "2024-03-21T13:56:46.520191+00:00",
      "last_updated": "2024-03-21T13:56:46.520191+00:00",
      "context": {
        "id": "01HSGMSJSR8PECRZGTJR3ZPMFM",
        "parent_id": null,
        "user_id": null
      }
    }
  }
}
}

Description

Every time I restart HA or reboot the system, my BT devices stop working (reporting "not available"). The real thermostats keep working just fine. After "making my devices stop working" I am getting a error message in HA system protocols:

Logger: homeassistant
Source: components/tuya/base.py:277
First occurred: 15:30:17 (1 occurrences)
Last logged: 15:30:17

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/better_thermostat/climate.py", line 833, in startup
await control_trv(self, trv)
File "/config/custom_components/better_thermostat/utils/controlling.py", line 210, in control_trv
await set_hvac_mode(self, heater_entity_id, _new_hvac_mode)
File "/config/custom_components/better_thermostat/utils/bridge.py", line 84, in set_hvac_mode
return await self.real_trvs[entity_id]["adapter"].set_hvac_mode(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/better_thermostat/adapters/generic.py", line 122, in set_hvac_mode
await self.hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 2319, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 905, in entity_service_call
single_response = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in _handle_entity_call
result = await task
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/climate/init.py", line 696, in async_set_hvac_mode
await self.hass.async_add_executor_job(self.set_hvac_mode, hvac_mode)
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/tuya/climate.py", line 297, in set_hvac_mode
self._send_command(commands)
File "/usr/src/homeassistant/homeassistant/components/tuya/base.py", line 277, in _send_command
self.device_manager.send_commands(self.device.id, commands)
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/manager.py", line 93, in send_commands
return self.device_repository.send_commands(device_id, commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/device.py", line 180, in send_commands
self.api.post(f"/v1.1/m/thing/{device_id}/commands", None, {"commands": commands})
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/customerapi.py", line 192, in post
return self.__request("POST", path, params, body)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/customerapi.py", line 121, in __request
raise Exception(f"network error:({ret['code']}) {ret['msg']}")
Exception: network error:(2008) command or value not support

In some cases I was able to "fix" the devices by reconfiguring the integration entry and changing values like tolerance on p. 1 or auto heat swap / alternative off mode on p. 2 of the config form, restarting HA and then repeat the reconfiguration process:

image image

But most of the times, the only way to "fix" BT was to completely delete all integration entities, remove the HACCS integration, reinstalling BT and reconfiguring devices (restarting HA after every step). Why my workaround worked some time and why it didn't any other time is beyond me.

Steps to Reproduce

  1. Set up BT integration entity/device.
  2. Restart HA.
  3. Frustration.

Expected behavior:
For my set up BT devices to remain available.

Actual behavior:
BT devices not responding.

image

Versions

HA versions:
Core: 2024.3.1
Supervisor: 2024.03.0
Operating System: 12.1
Frontend: 20240307.0

BT version:
Better Thermostat Firmware: 1.4.0

Additional Information

Don't know if that's of any help but this is the output of HA dev tools regarding the entity state when the entity is available:
State of climate.bt_test

hvac_modes:

  • heat
  • "off"
    min_temp: 5
    max_temp: 35
    target_temp_step: 1
    current_temperature: 18.6
    temperature: 19.5
    hvac_action: heating
    window_open: false
    call_for_heat: true
    last_change: "2024-03-21T12:43:12.424240"
    saved_temperature: null
    humidity: 65
    main_mode: null
    tolerance: 1
    heating_power: 0.01
    errors: "[]"
    batteries: >-
    {"binary_sensor.kontaktsensor_tur": {"battery": "72.0", "battery_id":
    "sensor.kontaktsensor_batterie"}}
    friendly_name: BT Test
    supported_features: 385

When trying to investigate what's happening I stumbled upon two reoccurring errors in the HA protocol that happen when BT devices are working/available.

  1. Seems to occur every time right after "fixing" a device by my workaround or setting up a completely new device:

Logger: homeassistant
Source: components/tuya/base.py:277
First occurred: 15:40:13 (2 occurrences)
Last logged: 15:43:04

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/better_thermostat/climate.py", line 833, in startup
await control_trv(self, trv)
File "/config/custom_components/better_thermostat/utils/controlling.py", line 210, in control_trv
await set_hvac_mode(self, heater_entity_id, _new_hvac_mode)
File "/config/custom_components/better_thermostat/utils/bridge.py", line 84, in set_hvac_mode
return await self.real_trvs[entity_id]["adapter"].set_hvac_mode(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/better_thermostat/adapters/generic.py", line 122, in set_hvac_mode
await self.hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 2319, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 905, in entity_service_call
single_response = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in _handle_entity_call
result = await task
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/climate/init.py", line 696, in async_set_hvac_mode
await self.hass.async_add_executor_job(self.set_hvac_mode, hvac_mode)
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/tuya/climate.py", line 297, in set_hvac_mode
self._send_command(commands)
File "/usr/src/homeassistant/homeassistant/components/tuya/base.py", line 277, in _send_command
self.device_manager.send_commands(self.device.id, commands)
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/manager.py", line 93, in send_commands
return self.device_repository.send_commands(device_id, commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/device.py", line 180, in send_commands
self.api.post(f"/v1.1/m/thing/{device_id}/commands", None, {"commands": commands})
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/customerapi.py", line 192, in post
return self.__request("POST", path, params, body)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/customerapi.py", line 121, in __request
raise Exception(f"network error:({ret['code']}) {ret['msg']}")
Exception: network error:(2008) command or value not support

  1. Happens every time I change the intended room temperature of the BT device (via HomeBridge entity as well as via directly in HA/HA companion app):

This error originated from a custom integration.

Logger: custom_components.better_thermostat.utils.controlling
Source: custom_components/better_thermostat/utils/controlling.py:46
integration: Better Thermostat (documentation, issues)
First occurred: 15:45:30 (2 occurrences)
Last logged: 15:47:22

better_thermostat BT Test: ERROR controlling: climate.seb_s_heizung
Traceback (most recent call last):
File "/config/custom_components/better_thermostat/utils/controlling.py", line 46, in control_queue
_temp = await control_trv(self, trv)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/better_thermostat/utils/controlling.py", line 210, in control_trv
await set_hvac_mode(self, heater_entity_id, _new_hvac_mode)
File "/config/custom_components/better_thermostat/utils/bridge.py", line 84, in set_hvac_mode
return await self.real_trvs[entity_id]["adapter"].set_hvac_mode(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/better_thermostat/adapters/generic.py", line 122, in set_hvac_mode
await self.hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 2319, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service
return await target(service_call)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 905, in entity_service_call
single_response = await _handle_entity_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in _handle_entity_call
result = await task
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/climate/init.py", line 696, in async_set_hvac_mode
await self.hass.async_add_executor_job(self.set_hvac_mode, hvac_mode)
File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/tuya/climate.py", line 297, in set_hvac_mode
self._send_command(commands)
File "/usr/src/homeassistant/homeassistant/components/tuya/base.py", line 277, in _send_command
self.device_manager.send_commands(self.device.id, commands)
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/manager.py", line 93, in send_commands
return self.device_repository.send_commands(device_id, commands)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/device.py", line 180, in send_commands
self.api.post(f"/v1.1/m/thing/{device_id}/commands", None, {"commands": commands})
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/customerapi.py", line 192, in post
return self.__request("POST", path, params, body)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/tuya_sharing/customerapi.py", line 121, in __request
raise Exception(f"network error:({ret['code']}) {ret['msg']}")
Exception: network error:(2008) command or value not support

@soeoeb soeoeb added the new bug incoming bug issue label Mar 21, 2024
@RLB7777
Copy link

RLB7777 commented Mar 24, 2024

I’ve got this too. Using BT with Tuya valves. Any restart of HA (update, power cycle etc) results in the BT instances becoming unavailable even though the Tuya valves still work within the Tuya integration.

The workaround noted by @soeoeb works for me - I manually reconfigure each BT instance making a small change to the sensitivity threshold, and it comes back on line. Weirdly, reloading BT doesn’t help. It needs to be reconfigured and there needs to be an actual change to the configuration, however small. Nor does hitting configure and then saving without a change help.

@tbrasser
Copy link

Facing the same issue, but not only on BT, also on versatile_thermostat. Probably something changed recently in climate or loading in core?

@UweTo
Copy link

UweTo commented Apr 16, 2024

Same Situation here with my two Tuya valves (SALCAR TRV801W). The Rademacher Valves are working.

@tco99ttocs
Copy link

for me the same, also with BT Version 1.5.0

@Wave89
Copy link

Wave89 commented Apr 21, 2024

For me it's the same. I can solve the problem temporarily, if I reconfigure the component with a new value, e.g. increase "the outdoor temperature when the thermostat turns off" and it keeps available until the temperature sensor is unavailable for a short time or until a reboot.

@SvenGeukens
Copy link

This could also be useful to look at. I kicked out all the window switches in the BT that where not working anymore. After this, they work again, just without the window detection. After the debugging, I hope I can switch them back ;-) #1333

@giovacode
Copy link

i had too many problems with 1.5.0 also with 1.5.1

  • device unavailable (as described here)
  • cannot change targetted heater anymore
  • cannot control setted heater
  • entity ids names are doubled like: room1_heat_thermostat_room1_heat_thermostat

i went back to 1.4.0 , then recreated all devices => all problems gone
ha v2024.4.4

@buhralex
Copy link

I had the same problem with my Bosch BTH-RA thermostats.
I have been uninstalling and upgrading for the last few days without success until I found a possible solution to the problem.

I saw that in Z2M under Details the system mode for my devices was not set. After I clicked on one of the available options, my devices were available again in BT.

@drdiablo1337
Copy link

I had the same problem with my Bosch BTH-RA thermostats. I have been uninstalling and upgrading for the last few days without success until I found a possible solution to the problem.

I saw that in Z2M under Details the system mode for my devices was not set. After I clicked on one of the available options, my devices were available again in BT.

Thanks for the tip, that's exactly it, BT hasn't been working for days (since I noticed it). Now it works again. Nevertheless, I will test and set up the “Advanced Heating Control” blueprint soon. A BT has already failed one or two times, the first time it was due to an unavailable external sensor because there was no connection and now I think after the update to HA 24.5.x or a restart.

@tco99ttocs
Copy link

for its not working like this, so thats maybe only a workaround for some devices!

@UweTo
Copy link

UweTo commented May 24, 2024

Workaround for my Tuya devices TRV SALCAR TRV801W)
System:

  • Core2024.5.4
  • Supervisor2024.05.1
  • Operating System12.3
  • Frontend20240501.1
  • Better Thermostat 1.5.1

Hardware Raspberry PI 4

I have inserted some lines of code to the module /homeassistant/custom_components/better_thermostat/utils/controlling.py

after line 213.

Now the Tuya TRV are active again even after a restart of HA.

        #
        # Begin Workaround
        #
        
                
            _LOGGER.debug(
                f"better_thermostat {self.name}: TO TRV set_hvac_mode: {heater_entity_id} from: {_trv.state} to: {_new_hvac_mode} WA1"
            )
            
        if _new_hvac_mode == HVACMode.HEAT: 
            _new_hvac_mode = HVACMode.HEAT_COOL
              
            _LOGGER.debug(
                f"better_thermostat {self.name}: TO TRV set_hvac_mode: {heater_entity_id} from: {_trv.state} to: {_new_hvac_mode} WA2"
            ) 
        #
        # End Workaround
        #

Background: The devices return an error when the HVAC mode is set to HEAT. Therefore, the workaround for this case is to set the HVAC mode to HEAT_COOL.

@tco99ttocs
Copy link

@UweTo looks good. Is it possible to write down some of the code before and after your workaround! If i go to line 213, there is still the "_logger.debug" -line! So with some additional lines i have a better overview:)

@UweTo
Copy link

UweTo commented May 24, 2024

@tco99ttocs:

workaround with additional lines:

        # send new HVAC mode to TRV, if it changed
        
        
        if (
            _new_hvac_mode is not None
            and _new_hvac_mode != _trv.state
            and (
                (_no_off_system_mode is True and _new_hvac_mode != HVACMode.OFF)
                or (_no_off_system_mode is False)
            )
        ):
            
        #
        # Begin Workaround
        #

        
            _LOGGER.debug(
                f"better_thermostat {self.name}: TO TRV set_hvac_mode: {heater_entity_id} from: {_trv.state} to: {_new_hvac_mode} WA1"
            )
            
        if _new_hvac_mode == HVACMode.HEAT: 
            _new_hvac_mode = HVACMode.HEAT_COOL
              
            _LOGGER.debug(
                f"better_thermostat {self.name}: TO TRV set_hvac_mode: {heater_entity_id} from: {_trv.state} to: {_new_hvac_mode} WA2"
            ) 
        #
        # End Workaround
        #

@UweTo
Copy link

UweTo commented Jun 1, 2024

Update of my workaround:
Module: /homeassistant/custom_components/better_thermostat/utils/controlling.py

The HVAC mode is now only changed for devices that are provided via the Tuya integration.

The workaround is inserted after line 214.

Works for me with 2 valves that are provided via the Tuya integration. The other of my valves are provided via the Rademacher integration and continue to work as before.

        # send new HVAC mode to TRV, if it changed
        
        
        if (
            _new_hvac_mode is not None
            and _new_hvac_mode != _trv.state
            and (
                (_no_off_system_mode is True and _new_hvac_mode != HVACMode.OFF)
                or (_no_off_system_mode is False)
            )
        ):
  # Line 214          
        #
        # Begin Workaround
        #

            wa_integration = self.real_trvs[heater_entity_id]["integration"]
            wa_hvac_mode = _new_hvac_mode
        
            _LOGGER.debug(
                f"better_thermostat {self.name}: TO TRV_1 set_hvac_mode: {heater_entity_id} from: {_trv.state} to: {_new_hvac_mode} Integration: {wa_integration} WA1"
            )
        
        if _new_hvac_mode == HVACMode.HEAT and wa_integration.find("tuya") != -1: 
            _new_hvac_mode = HVACMode.HEAT_COOL
            _LOGGER.debug(
                f"better_thermostat {self.name}: TO TRV_2 set_hvac_mode: {heater_entity_id} from: {_trv.state} to: {_new_hvac_mode} instead of {wa_hvac_mode} Integration: {wa_integration} WA2"
            )
            _LOGGER.info(
                "better_thermostat %s: Integration %s. Setting HVAC_Mode to %s",
                self.name,
                wa_integration,
                _new_hvac_mode,
            )
        #
        # End Workaround
        #

@CaptMilkbeard
Copy link

i had too many problems with 1.5.0 also with 1.5.1

  • device unavailable (as described here)
  • cannot change targetted heater anymore
  • cannot control setted heater
  • entity ids names are doubled like: room1_heat_thermostat_room1_heat_thermostat

i went back to 1.4.0 , then recreated all devices => all problems gone ha v2024.4.4

I did exactly the same thing, back to 1.4.0 and after restarting everything works as before.

@Panoramiac
Copy link

I have the same issue, but think another root cause. After the restart of HA some BTs are not available, but some are working:
image

The ZHA devices themselves are all fine. When I restart the BT component, it workes fine:
image

In the log file I see this error (Click).
2024-11-06 15:37:17.251 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/zha/zigbee/cluster_handlers/__init__.py", line 67, in wrap_zigpy_exceptions
    yield
  File "/usr/local/lib/python3.12/site-packages/zha/zigbee/cluster_handlers/__init__.py", line 85, in wrapper
    return await RETRYABLE_REQUEST_DECORATOR(func)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/zigpy/util.py", line 136, in retry
    return await func()
           ^^^^^^^^^^^^
  File "/config/custom_zha_quirks/ts0601_trv_zonnsmart.py", line 381, in write_attributes
    await ZONNSMARTManufClusterSelf[
  File "/usr/local/lib/python3.12/site-packages/zhaquirks/tuya/__init__.py", line 521, in write_attributes
    await super().command(
  File "/usr/local/lib/python3.12/site-packages/zigpy/quirks/__init__.py", line 254, in command
    return await self.request(
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/zigpy/zcl/__init__.py", line 378, in request
    return await self._endpoint.request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/zigpy/endpoint.py", line 265, in request
    return await self.device.request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/zigpy/device.py", line 334, in request
    await send_request()
  File "/usr/local/lib/python3.12/site-packages/zigpy/application.py", line 834, in request
    await self.send_packet(
  File "/usr/local/lib/python3.12/site-packages/zigpy_znp/zigbee/application.py", line 1100, in send_packet
    raise DeliveryError(
zigpy.exceptions.DeliveryError: Request failed after 5 attempts: <Status.NWK_NO_ROUTE: 205>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/zha/helpers.py", line 1286, in handler
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/zha/number.py", line 88, in async_set_native_value
    await self.entity_data.entity.async_set_native_value(value=value)
  File "/usr/local/lib/python3.12/site-packages/zha/application/platforms/number/__init__.py", line 173, in async_set_native_value
    await self._analog_output_cluster_handler.async_set_present_value(float(value))
  File "/usr/local/lib/python3.12/site-packages/zha/zigbee/cluster_handlers/general.py", line 161, in async_set_present_value
    await self.write_attributes_safe(
  File "/usr/local/lib/python3.12/site-packages/zha/zigbee/cluster_handlers/__init__.py", line 614, in write_attributes_safe
    res = await self.write_attributes(attributes, manufacturer=manufacturer)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/zha/zigbee/cluster_handlers/__init__.py", line 84, in wrapper
    with wrap_zigpy_exceptions():
  File "/usr/local/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/usr/local/lib/python3.12/site-packages/zha/zigbee/cluster_handlers/__init__.py", line 76, in wrap_zigpy_exceptions
    raise ZHAException(message) from exc
zha.exceptions.ZHAException: Failed to send request: Request failed after 5 attempts: <Status.NWK_NO_ROUTE: 205>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/better_thermostat/climate.py", line 858, in startup
    await control_trv(self, trv)
  File "/config/custom_components/better_thermostat/utils/controlling.py", line 260, in control_trv
    await set_offset(self, heater_entity_id, _calibration)
  File "/config/custom_components/better_thermostat/adapters/delegate.py", line 91, in set_offset
    return await self.real_trvs[entity_id]["adapter"].set_offset(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/better_thermostat/adapters/generic.py", line 146, in set_offset
    await self.hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2761, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2804, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 996, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1068, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/number/__init__.py", line 122, in async_set_value
    await entity.async_set_native_value(native_value)
  File "/usr/src/homeassistant/homeassistant/components/zha/helpers.py", line 1288, in handler
    raise HomeAssistantError(err) from err
homeassistant.exceptions.HomeAssistantError: Failed to send request: Request failed after 5 attempts: <Status.NWK_NO_ROUTE: 205>

Here is the full log:
home-assistant_better_thermostat_2024-11-06T14-38-43.406Z.log

Let me know when you need more log out put to better understand the issue.

@KartoffelToby
Copy link
Owner

Pls try the 1.7.0 Beta 1

@lexi1970
Copy link

I have The Same Problem. Also with 1.7.0 Beta 1. After restart ha all my Bt Thermostats From Tuya are Not available .

@Panoramiac
Copy link

Pls try the 1.7.0 Beta 1

With the beta right now they work stable (need to knock on wood). Sorry to reply back so late. I did not find this thread beside the others I am active in. What also helped to dramatically increase the stability of my zigbee network was to replace the USB 2.0 hub with a long USB 2.0 extension cable @lexi1970. After that fix only the reboot issue was left which seems to be solved in my case.

@1970lexi
Copy link

1970lexi commented Nov 20, 2024

hello
thank you. but i have already tried the beta. there is exactly the same problem. after restarting ha the better thermostats are not available. i then have to remove a sensor. save it. and add the sensor again then it works again. i usually use the weather sensor. if i leave out the weather sensor then i also have the same problem when i restart.

they are Tuya thermostats without Zigbee. only my temperature sensors are zigbee2mqtt

@UweTo
Copy link

UweTo commented Nov 20, 2024

Hello, here #1322 (comment) I have described a workaround that works for my Tuya valves.
However, as this requires changes to be made in a Better Thermostat module and these have to be updated with each new version, I have now worked out a different solution for myself.
I have created a Quirk module and placed it in the corresponding folder of Better Thermostat. I no longer have to make any code changes for new versions of BT. All I need to do is copy the Quirk module back into the relevant folder and restart.
It also works for me with the current version 1.7.0-beta1.
If required, I can post the code of the Quirk module here.

hello thank you. but i have already tried the beta. there is exactly the same problem. after restarting ha the better thermostats are not available. i then have to remove a sensor. save it. and add the sensor again then it works again. i usually use the weather sensor. if i leave out the weather sensor then i also have the same problem when i restart.

they are Tuya thermostats without Zigbee. only my temperature sensors are zigbee2mqtt

@lexi1970
Copy link

That would be nice if you could post the code

@UweTo
Copy link

UweTo commented Nov 20, 2024

That would be nice if you could post the code

Here is the code that must be in this directory: /homeassistant/custom_components/better_thermostat/model_fixes/WiFi Smart Thermostat.py

WiFi Smart Thermostat is the name of the adapter model. You can find the name via Integrations->Tuya->Click on one of the Tuya thermostats. Then you will see this:
image

On my test system Raspberry PI the name to use is “WiFi Smart Thermostat”, on my production system based on X64 it is “1q1grefcvygxzc7w”. The Quirks file on my Raspberry is therefore called WiFI Smart Thermostat.py, on my X64 system 1q1grefcvygxzc7w.py.
The content of the files is identical.

import logging
from homeassistant.components.climate.const import HVACMode

_LOGGER = logging.getLogger(__name__)

def fix_local_calibration(self, entity_id, offset):
    return offset


def fix_target_temperature_calibration(self, entity_id, temperature):
    return temperature


async def override_set_hvac_mode(self, entity_id, hvac_mode):
    
    _LOGGER.debug(
        f"better_thermostat {self.device_name}: TRV {entity_id} device quirk hvac WiFi Smart Thermostat active"
    )
    
    if hvac_mode == HVACMode.HEAT or hvac_mode == HVACMode.AUTO:
       hvac_mode = HVACMode.HEAT_COOL
        
    
    await self.hass.services.async_call(
        "climate",
        "set_hvac_mode",
        {"entity_id": entity_id, "hvac_mode": hvac_mode},
        blocking=True,
        context=self.context,
    )
        
    return True


async def override_set_temperature(self, entity_id, temperature):
    return False

@lexi1970
Copy link

Oh je. Das klingt kompliziert.

oh dear, that sounds complicated

@UweTo
Copy link

UweTo commented Nov 20, 2024 via email

@Panoramiac
Copy link

hello thank you. but i have already tried the beta. there is exactly the same problem. after restarting ha the better thermostats are not available. i then have to remove a sensor. save it. and add the sensor again then it works again. i usually use the weather sensor. if i leave out the weather sensor then i also have the same problem when i restart.

they are Tuya thermostats without Zigbee. only my temperature sensors are zigbee2mqtt

Ich habe aufgehört den externen Wetterdienst zu verwenden, das macht auch immer wieder Probleme. Ich hätte das oben gestern nicht schreiben dürfen. Heute morgen war ein Fenstersensor im Schlafzimmer weg. Ergo Schlafzimmer kalt da TRV aus. Im gesamten Haus waren die Heizungen zu kalt obwohl BT lief. Der Offset Parameter in den TRVs war wieder extrem groß (-54), ich denke die TRVs können mit solchen Werten nicht umgehen.
Screenshot_20241120_063810_Home Assistant

@lexi1970
Copy link

lexi1970 commented Nov 20, 2024

So viele deutsche hier. Klasse. Englisch ist immer ein Problem.
bei mir klappts auch nicht wenn ich den aussensensor oder wetterdaten weglasse.

Ich weiß nicht genau wo ich den Code einfügen soll. Oben gibts du einen anderen Pfad an als im Kommentar 1322

und auch wo genau im Code.
das übersteigt meine Kenntnis komplett

@folfy
Copy link
Collaborator

folfy commented Dec 21, 2024

Mode "heat_cool" on devices without mode "heat" is still not considered in v1.7.0b1, issues still open, will look into it

@folfy
Copy link
Collaborator

folfy commented Dec 21, 2024

Will be looking for an active tester for a proper fix (BT automatically falling back to heat_cool, if heat mode is not supported by the TRV) - Let me know if anyone is still following along and willing to help.

Fix in PR #1533 available and waiting for testing/feedback (this is based on v1.7.0b1).

folfy added a commit to folfy/better_thermostat that referenced this issue Dec 21, 2024
KartoffelToby added a commit that referenced this issue Jan 3, 2025
Bugfix - Support devices only having mode heat_cool instead of heat (#1322)
@folfy folfy added bug Something isn't working wait for feedback and removed new bug incoming bug issue labels Jan 9, 2025
@folfy
Copy link
Collaborator

folfy commented Jan 9, 2025

Should be fixed in v1.7.0b2 - Please test, and if not working, provide logs.

diagnostic data
IMPORTANT:
Download and paste the diagnostic data from your Better Thermostat Entity(s) below. (not working in v1.6.1 and v1.7.0b1 - please update)
https://www.home-assistant.io/docs/configuration/troubleshooting/#download-diagnostics

debug log
Depending on how complicated you issue is, it might be necessary to enable debug logging for BT,
reproduce the issue, and then upload this logfile here.
https://www.home-assistant.io/docs/configuration/troubleshooting/#enabling-debug-logging

@folfy
Copy link
Collaborator

folfy commented Jan 21, 2025

Should be working acc. to #1531 and didn't receive any further feedback indicating issues here, so closing this

@folfy folfy closed this as completed Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wait for feedback
Projects
None yet
Development

No branches or pull requests