I have an MQTT temperature sensor publishing to target_sensor in the Climate Module. It appears that the Climate Module requires current_temperature to be a floating number whereas the MQTT returned temperature is a string. I currenlty get the error:
homeassistant.components.climate.generic_thermostat: Unable to update from sensor: could not convert string to float: ‘unknown’
Can anybody help me convert the MQTT sensor reading to floating number. I have tried to create a MQTT_Thermostat where I added “float” to the generic Thermostat code as below but this does not appear to work for me
try:
self._cur_temp = float(self.hass.config.units.temperature(
state.state, unit))
except ValueError as ex:
_LOGGER.error('Unable to update from sensor: %s', ex)
Are you sure the mqtt message actually contains a number. This error suggests to me that the string in the mqtt message is actually the string ‘unknown’.
Can you subscribe to the topic using mosquitto_sub and print out the message?
The temperatures can be displayed graphically in HA (see below) , so it is tracking it as a number sometimes.
This leaves me struggling with what to do. I am contemplating publishing the MQTT to another sensor, then using an an automation/script to read that when it changes state to feed that to the Climate Module target_sensor, but that seems to be a bit of an unnecessary work around!
Taking a step back, you need to decide what the heater should do when the temperature is unknown.
In a simple scenario, to be safe, just turn the heater off. If you have previous readings, you might ignore the latest reading and use the previous reading. I’m not familiar with the generic thermostat, so I don’t know what that does.
I also think you should check that this is actually the problem by getting a text output of the message.
Thanks for the pointer (again:slight_smile:). The solution was in two parts, the formating of the temperature sensor and the removal of the coercion to temperature format in the code.
Part 1: - I had set up the target sensor like this:
It was the inclusion of the unit_of _measurement which was causing the issue. As I still wanted the hall temperature as a sensor, I created a new sensor pointing at the same data but without the formatting:
Part 2: - This did not solve the issue on its own, I had to change the coding of the HA “Generic Thermostat” and create a custom component where I removed the code that formatted the number into a temperature format:
try:
self._cur_temp = float(state.state)
except ValueError as ex:
_LOGGER.error('Unable to update from sensor: %s', ex)
It’s weird. I set this up for the first time yesterday. Even though HA spits out an error, it seems to work OK. Error only happens once at startup and then all OK and I’m using the standard component, not the modifications you’re suggesting.
I had the same problem, then I realized the degree symbol was “weird”: I had “ºC” from some cut&paste (in terminal it is underlined), but when I re-typed it, it became “°C” and everything went in place.
Thanks for that. It is the definitive solution. I did as you suggested and it worked first time. NB: you still get the error on startup, but not after that.
The module is still a bit quirky as the Heat/Idle logic is not quite right as you can see from the screen shot below. The heating is off, but shows as Heat when you reset the target temperature. Just a bid odd, but it works correctly other than from what is shown on screen.
This can happen during start up. If the thermostat ask for the temperature before it is ready. So nothing to worry about if it only happens during startup