custom-components / climate.programmable_thermostat

Programmable thermostat that let you have a smart thermostat on budget.
The Unlicense
113 stars 35 forks source link

unable to handle initial 'unknown' value of temperature sensors #45

Open litinoveweedle opened 2 years ago

litinoveweedle commented 2 years ago

When after HA reload values of linked sensors are not yet known, integrations is not able to handle this situation correctly and raise error as bellow.

Proposal: correct input sanitation shall be implemented to only update integration temperature if:

is_number(states(sensors.given_sensor))

Logger: custom_components.programmable_thermostat.climate
Source: custom_components/programmable_thermostat/climate.py:526
Integration: Programmable Thermostat (documentation)
First occurred: 9:00:15 PM (2 occurrences)
Last logged: 9:00:16 PM

climate.Heating TO1 - Unable to update current temperature from sensor: could not convert string to float: ''
climate.Heating TO2 - Unable to update current temperature from sensor: could not convert string to float: ''
Logger: homeassistant
Source: custom_components/programmable_thermostat/climate.py:340
Integration: Programmable Thermostat (documentation)
First occurred: 11:38:09 PM (2 occurrences)
Last logged: 11:38:09 PM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/programmable_thermostat/climate.py", line 340, in _async_target_changed
    self._restore_temp = float(new_state.state)
ValueError: could not convert string to float: ''
MapoDan commented 2 years ago

Ciao,

this is strange.. The software is managing it with a function that a guy added to the code that is _getStateSafe What I see is that the value received is not 'unknown' or 'unavailable', but an empty string.

If you have an idea how to fix this, feel free to send a pull request. Otherwise I'll have a look when I have time, but in this moment I'm pretty busy on some personal topics

Daniele

litinoveweedle commented 2 years ago

Hello, it actually depends on the way, how given sensor is updated. Previously I have no checks in my sensor REST API templating, so if sensor device was not yet ready templating returned error on conversion to float and sensors had value of string 'Unknown' To avoid that, I updated template of the sensors, to update only if device value is number / float:

value_template: "{{ value_json.Data.Value | int if 'Data' in value_json and 'Value' in value_json.Data and is_number(value_json.Data.Value)}}"

But now if sensor device is not yet ready, sensor is updated with empty string - as you correctly observed.

The issue in both cases is, that there is no way, how I can postpone thermostat init to wait until linked sensors is initialized with some meaningful value and therefore without triggering described problem. Maybe there could/should be defined/documented sensor initial value (probably undefined / None), which thermostat integration silently process as 'wait for init' without triggering error.

There is same issue reported even for native thermostat integration: https://github.com/home-assistant/core/issues/22535

If you have any other idea how to get rid of these errors...