better_thermostat
better_thermostat copied to clipboard
Homeassistant crashes when controlling Betterthermostat
Prerequisites
- [ Shelly HT PLUS/Panasonic HVAC, but also Shelly HT PLUS/Thermostatic radiator valve (ME167)] Model name of your Devices
- [ 2024-01-13T16:45:00.509562852+01:00 2024-01-13 16:45:00.509 ERROR (MainThread) [custom_components.better_thermostat.utils.controlling] better_thermostat Büro Klima: ERROR controlling: climate.buro 2024-01-13T16:45:00.509571087+01:00 Traceback (most recent call last): 2024-01-13T16:45:00.509573712+01:00 File "/config/custom_components/better_thermostat/utils/controlling.py", line 46, in control_queue 2024-01-13T16:45:00.509576147+01:00 _temp = await control_trv(self, trv) 2024-01-13T16:45:00.509578281+01:00 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2024-01-13T16:45:00.509580264+01:00 File "/config/custom_components/better_thermostat/utils/controlling.py", line 85, in control_trv 2024-01-13T16:45:00.509582448+01:00 await update_hvac_action(self) 2024-01-13T16:45:00.509584482+01:00 File "/config/custom_components/better_thermostat/events/trv.py", line 249, in update_hvac_action 2024-01-13T16:45:00.509592687+01:00 self.bt_target_temp > self.cur_temp + self.tolerance 2024-01-13T16:45:00.509594982+01:00 TypeError: '>' not supported between instances of 'NoneType' and 'float']
Output from Home Assistant Developer Tools state e.g.
- [ not possible, also produces crash] Output from Home Assistant Device Diagnostic from BT
{
not possible, crash
}
Description
Since Homeassistant 2024.1.3 Betterthermostat crashes when controlling devices or when trying to enable debug
Steps to Reproduce
- Start Homeassistant
- Try to enable Heat on Betterthermostat Thermostat
- unresponsive web interface, docker restart fixes homeassistant
Expected behavior:
Enabling Heat
Actual behavior:
HA crash
Versions
HA 2024.1.3, BT 1.4 and tried with BT 1.5 latest beta
Additional Information
maybe its not a btt error, i think its a underlying problem of the hvac/tuya trv
https://github.com/sockless-coding/panasonic_cc/issues/161 and one of my one tuya thermostat is out of battery
maybe these two underlying problems crash homeassistant
yeah same here with tado:
2024-01-14 16:30:01.626 ERROR (MainThread) [custom_components.better_thermostat.utils.controlling] better_thermostat Better Badkamer: ERROR controlling: climate.badkamer_tado_thermostaat Traceback (most recent call last): File "/config/custom_components/better_thermostat/utils/controlling.py", line 53, in control_queue _temp = await control_trv(self, trv) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/better_thermostat/utils/controlling.py", line 92, in control_trv await update_hvac_action(self) File "/config/custom_components/better_thermostat/events/trv.py", line 256, in update_hvac_action self.bt_target_temp > self.cur_temp + self.tolerance TypeError: '>' not supported between instances of 'NoneType' and 'float'
according to chatgpt 4 (don't slap me haha)
The error message you're encountering is a TypeError, indicating that a comparison is being made between a NoneType and a float. This happens in the update_hvac_action function, specifically at the line where it checks if self.bt_target_temp is greater than self.cur_temp + self.tolerance.
The error suggests that self.bt_target_temp is None, which cannot be compared with a float. To fix this error, you need to ensure that self.bt_target_temp is assigned a proper float value before this comparison is made, or you need to add a check to handle the case where it might be None.
trv.py.zip i let ChatGPT fix it for me.. replace the file in /custom_components/better_thermostat/events/
same for me with tuya tv-02 devices using z2m. Tryed BT 1.4. as well as 1.5 beta 4.
Hope to have found a relevant snippet from the log:
2024-01-22 21:54:34.455 ERROR (MainThread) [custom_components.better_thermostat.utils.controlling] better_thermostat Wohnbereich Heizen: ERROR controlling: climate.esszimmer_heizung Traceback (most recent call last): File "/config/custom_components/better_thermostat/utils/controlling.py", line 53, in control_queue _temp = await control_trv(self, trv) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/better_thermostat/utils/controlling.py", line 273, in control_trv _tvr_has_quirk = await override_set_temperature( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/better_thermostat/model_fixes/model_quirks.py", line 93, in override_set_temperature return await self.real_trvs[entity_id]["model_quirks"].override_set_temperature( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/better_thermostat/model_fixes/TV02-Zigbee.py", line 71, in override_set_temperature await self.hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2186, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 272, in handle_service return await service.entity_service_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 864, in entity_service_call raise HomeAssistantError( homeassistant.exceptions.HomeAssistantError: Entity climate.esszimmer_heizung does not support this service.
So this issue is a pretty heavy issue. It just makes it completely unusable. @KartoffelToby do you have time / plans to fix this or is it not possible right now? Otherwise I'll need to dive in and check the code, but perhaps it's much faster for you to see where to fix it.
maybe its not a btt error, i think its a underlying problem of the hvac/tuya trv
https://github.com/sockless-coding/panasonic_cc/issues/161
and one of my one tuya thermostat is out of battery
maybe these two underlying problems crash homeassistant
It was like i suspected, the two individual problems (thermometer/thermostat reachabilitiy) lead to the crash.
I have the same problem with my Honeywell Lyric T6 which is on netpower. I use a Sonoff Temperature sensor as external sensor. So I will dive into this, but other people also indicated this issue. Either way Home Assistant should not crash, with the only option being to restart.
So this issue is a pretty heavy issue. It just makes it completely unusable. @KartoffelToby do you have time / plans to fix this or is it not possible right now? Otherwise I'll need to dive in and check the code, but perhaps it's much faster for you to see where to fix it.
So I dug into this a bit because I really wanted it working. What I discovered was the whenever HAOS restarted for whatever reason, the Better Thermostat card has no value for target temperature set. This meant when it got to line 256 (self.bt_target_temp > self.cur_temp + self.tolerance), self.bt_target_temp was "None". Comparing the "None" to the cur_temp resulted in a failure and therefore a crash. I can't tell you why it causes HAOS to crash out like that. But... what I did do to resolve was add a couple of new lines at line 221:
if self.bt_target_temp is None:
self.bt_target_temp = 5.0
Now, when HAOS first starts up, this script runs, and the bt_target_temp is set to 5C. This is reflected on the better thermostat card. And no more errors or crashing.
I'm sure there may be a deeper rooted problem, or a more elegant way of fixing this up - but my coding knowledge is quite basic so is a good temporary fix as far as I'm concerned :)
EDIT: Typos. Also to add, I've been running like this for over a week now and it's been great!
So this issue is a pretty heavy issue. It just makes it completely unusable. @KartoffelToby do you have time / plans to fix this or is it not possible right now? Otherwise I'll need to dive in and check the code, but perhaps it's much faster for you to see where to fix it.
So I dug into this a bit because I really wanted it working. What I discovered was the whenever HAOS restarted for whatever reason, the Better Thermostat card has no value for target temperature set. This meant when it got to line 256 (self.bt_target_temp > self.cur_temp + self.tolerance), self.bt_target_temp was "None". Comparing the "None" to the cur_temp resulted in a failure and therefore a crash. I can't tell you why it causes HAOS to crash out like that. But... what I did do to resolve was add a couple of new lines at line 221:
if self.bt_target_temp is None: self.bt_target_temp = 5.0
Now, when HAOS first starts up, this script runs, and the bt_target_temp is set to 5C. This is reflected on the better thermostat card. And no more errors or crashing.
I'm sure there may be a deeper rooted problem, or a more elegant way of fixing this up - but my coding knowledge is quite basic so is a good temporary fix as far as I'm concerned :)
EDIT: Typos. Also to add, I've been running like this for over a week now and it's been great!
Interesting! Will probably open up a fork for this! Do you have a file where you put this?
Yeah my fix is in a few post above 👍🏻
Could you make a PR for that? Then it can be merged in the next release.
@joeblack2k @wtom I added the "Fix" in the Beta 1.5.0 V5 but this is only a fix for the symthoms, we need to find out why the vars are empty at this point.
Not really fixing it for me, but still I'm not deep into this. I have downloadet the last version of the beta 5, checking trv.py code if the "none" fix i includet. Seems to be.
I think this is the relevant log to the event, forcing ha not to respond and only respond by restarting the container:
2024-02-09 11:47:59.195 DEBUG (MainThread) [custom_components.better_thermostat.calibration] better_thermostat Wohnbereich Heizung: climate.esszimmer_heizung - new local calibration: -1.0 | external_temp: 19.3, trv_temp: 14.7, calibration: -5.0 2024-02-09 11:47:59.196 DEBUG (MainThread) [custom_components.better_thermostat.utils.controlling] better_thermostat Wohnbereich Heizung: TO TRV set_hvac_mode: climate.esszimmer_heizung from: off to: heat 2024-02-09 11:47:59.198 DEBUG (MainThread) [custom_components.better_thermostat.model_fixes.TV02-Zigbee] better_thermostat Wohnbereich Heizung: TRV climate.esszimmer_heizung device quirk hvac trv02-zigbee active 2024-02-09 11:47:59.198 ERROR (MainThread) [custom_components.better_thermostat.utils.controlling] better_thermostat Wohnbereich Heizung: ERROR controlling: climate.esszimmer_heizung Traceback (most recent call last): File "/config/custom_components/better_thermostat/utils/controlling.py", line 53, in control_queue _temp = await control_trv(self, trv) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/better_thermostat/utils/controlling.py", line 216, in control_trv _tvr_has_quirk = await override_set_hvac_mode( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/better_thermostat/model_fixes/model_quirks.py", line 87, in override_set_hvac_mode return await self.real_trvs[entity_id]["model_quirks"].override_set_hvac_mode( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/better_thermostat/model_fixes/TV02-Zigbee.py", line 42, in override_set_hvac_mode await self.hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2186, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 272, in handle_service return await service.entity_service_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 864, in entity_service_call raise HomeAssistantError( homeassistant.exceptions.HomeAssistantError: Entity climate.esszimmer_heizung does not support this service. 2024-02-09 11:47:59.204 DEBUG (MainThread) [custom_components.better_thermostat.calibration] better_thermostat Wohnbereich Heizung: climate.wohnzimmer_heizung - new local calibration: -3.0 | external_temp: 19.3, trv_temp: 16.9, calibration: -5.0 2024-02-09 11:47:59.204 DEBUG (MainThread) [custom_components.better_thermostat.utils.controlling] better_thermostat Wohnbereich Heizung: TO TRV set_hvac_mode: climate.wohnzimmer_heizung from: off to: heat 2024-02-09 11:47:59.205 DEBUG (MainThread) [custom_components.better_thermostat.model_fixes.TV02-Zigbee] better_thermostat Wohnbereich Heizung: TRV climate.wohnzimmer_heizung device quirk hvac trv02-zigbee active 2024-02-09 11:47:59.205 ERROR (MainThread) [custom_components.better_thermostat.utils.controlling] better_thermostat Wohnbereich Heizung: ERROR controlling: climate.wohnzimmer_heizung Traceback (most recent call last): File "/config/custom_components/better_thermostat/utils/controlling.py", line 53, in control_queue _temp = await control_trv(self, trv) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/better_thermostat/utils/controlling.py", line 216, in control_trv _tvr_has_quirk = await override_set_hvac_mode( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/better_thermostat/model_fixes/model_quirks.py", line 87, in override_set_hvac_mode return await self.real_trvs[entity_id]["model_quirks"].override_set_hvac_mode( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/better_thermostat/model_fixes/TV02-Zigbee.py", line 42, in override_set_hvac_mode await self.hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2186, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 272, in handle_service return await service.entity_service_call( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 864, in entity_service_call raise HomeAssistantError( homeassistant.exceptions.HomeAssistantError: Entity climate.wohnzimmer_heizung does not support this service.
Same issue here with HA 2024.3.3 and Sonoff TRVZB. This error shows up in the following situation in my case: Restarting HA and trying to set BT temperature or switch without the underlying climate entity being available. In my case some zigbee connection issues caused the same situation by restarting ZHA and BT devices.
I found that BT is running into an infinite retry loop that locks HA. Even though it's not the root cause, it's better to use a finite number of retries with some backoff.