Open mgartin opened 11 months ago
Ok, so I dug a bit further. I'm not sure the problem is that a pure float should be sent. It might be that we shouldn't end up at this place in the HA integration: https://github.com/home-assistant/core/blob/5ed8de83484c88f38bfe3b27692500b992e3f0e8/homeassistant/components/sensor/__init__.py#L621
For some reason the HA code fails to do the right thing, even though telldus-core-mqtt has sent the following:
2023-10-14 09:35:44,007 60 INFO: Send "{"device": {"name": "247_temperaturehumidity", "identifiers": ["247_temperaturehumidity"], "model": "temperaturehumidity", "manufacturer": "fineoffset"}, "unique_id": "247_telldus_temperature", "name": "telldus_247_temperature", "state_topic": "telldus/247/temperature/state", "state_value_template": "{{ value_json.temperature }}", "device_class": "temperature", "unit_of_measurement": "°C"}" to topic "homeassistant/sensor/247_telldus/temperature/config"
2023-10-14 09:35:44,008 60 INFO: Send "{"temperature": "20.4"}" to topic "telldus/247/temperature/state"
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?