You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Initially I posted my problem here, but I'm moving it here:
I have installed this tool in a virtual environment, and the MQTT integration in Home Assistant (HA) correctly identifies lots of sensors from it, however, it fails to read eg. temperature and humidity:
2023-10-13 20:48:47.316 INFO (MainThread) [homeassistant.components.mqtt.discovery] Component has already been discovered: sensor 167_telldus temperature, sending update
2023-10-13 20:48:47.320 INFO (MainThread) [homeassistant.components.mqtt.discovery] Component has already been discovered: sensor 167_telldus humidity, sending update
2023-10-13 20:49:04.245 INFO (MainThread) [homeassistant.components.mqtt.discovery] Component has already been discovered: sensor 136_telldus temperature, sending update
2023-10-13 20:49:18.333 INFO (MainThread) [homeassistant.components.mqtt.discovery] Component has already been discovered: sensor 199_telldus temperature, sending update
2023-10-13 20:49:18.376 ERROR (MainThread) [homeassistant.components.mqtt.models] Exception raised when updating state of sensor.199_temperaturehumidity_telldus_199_temperature, topic: 'telldus/199/temperature/state' with payload: b'{"temperature": "15.5"}'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 593, in state
numerical_value = float(value) # type:ignore[arg-type]
^^^^^^^^^^^^
ValueError: could not convert string to float: '{"temperature": "15.5"}'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/mqtt/models.py", line 305, in process_write_state_requests
entity.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 779, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 879, in _async_write_ha_state
state, attr = self._async_generate_attributes()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 820, in _async_generate_attributes
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 785, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 595, in state
raise ValueError(
ValueError: Sensor sensor.199_temperaturehumidity_telldus_199_temperature has device class 'temperature', state class 'None' unit '°C' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: '{"temperature": "15.5"}' (<class 'str'>)
The problem seems to be that the payload is the full string: {"temperature": "15.5"}, not just the number.
which has "state_value_template": "{{ value_json.temperature }}" in it, and as such the MQTT integration should be able to read it, right? What is going wrong here?
FWIW, I am able to get valid readings in HA with the following hack in telldus-core-mqtt main.py:
@@ -192,10 +199,25 @@ def sensor_event(protocol, model, id_, data_type, value, timestamp, cid):
topic = s.create_topic(id_, type_string)
data = s.create_topic_data(type_string, value)
+
+ # Special case for temperature and temperaturehumidity
+ if (
+ 'temperaturehumidity' in model
+ or data_type == const.TELLSTICK_TEMPERATURE
+ or data_type == const.TELLSTICK_HUMIDITY
+ ):
+ logging.debug(f'dbg: altering data for {model=}')
+ data = value
+
publish_mqtt(mqtt_sensor, topic, data)
It still sends a lot of data that HA cannot read, but in addition it sends pure float values that is read by HA.
Thank you for this tool!
Initially I posted my problem here, but I'm moving it here:
I have installed this tool in a virtual environment, and the MQTT integration in Home Assistant (HA) correctly identifies lots of sensors from it, however, it fails to read eg. temperature and humidity:
The problem seems to be that the payload is the full string:
{"temperature": "15.5"}
, not just the number.telldus-core-mqtt sends the following:
So, I guess that what we need to do is to identify temperature sensors and craft the payload a bit differently?
The text was updated successfully, but these errors were encountered: