KartoffelToby / better_thermostat

This custom component for Home Assistant will add crucial features to your climate-controlling TRV (Thermostatic Radiator Valves) to save you the work of creating automations to make it smart. It combines a room-temperature sensor, window/door sensors, weather forecasts, or an ambient temperature probe to decide when it should call for heat and automatically calibrate your TRVs to fix the imprecise measurements taken in the radiator's vicinity.
https://better-thermostat.org
GNU Affero General Public License v3.0
713 stars 124 forks source link

BT devices not available after restarting HA #1322

Open soeoeb opened 3 months ago

soeoeb commented 3 months ago

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

RLB7777 commented 3 months ago

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 commented 2 months ago

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

UweTo commented 2 months ago

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

tco99ttocs commented 2 months ago

for me the same, also with BT Version 1.5.0

Wave89 commented 2 months ago

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 commented 2 months ago

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 ;-) https://github.com/KartoffelToby/better_thermostat/issues/1333

giovacode commented 2 months ago

i had too many problems with 1.5.0 also with 1.5.1

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

buhralex commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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

UweTo commented 1 month ago

Workaround for my Tuya devices TRV SALCAR TRV801W) System:

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 commented 1 month ago

@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 commented 1 month ago

@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 commented 1 month ago

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 commented 1 month ago

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.