From 9a4073e606551f162130259134f3e95d9b644d30 Mon Sep 17 00:00:00 2001 From: Ian Hubbertz Date: Sat, 7 Dec 2024 21:33:46 +0100 Subject: [PATCH] Fix "Unit of Measurement" for BME280 temperature The Unit of Measurement ("tempScale") of the MQTT message is set for each published measurement - but not for the homeassistant discovery. Thus, openhab (and mabye other systems?) don't recognize the value as "Number" - so it uses String instead. This is somehow annoying when trying to configure the sensor channel to be linked to an existing item in OpenHAB. (Items that are created automatically or with "Add point to model" can be configured in a way that the String is transformed to Number or Number:Temperature, but existing Items cannot be linked). When a "Unit of Measurement" is set in HomeAssistant discovery, the HA binding of OpenHAB notices that the MQTT String is a number and automatically converts it. --- usermods/BME280_v2/usermod_bme280.h | 1 + 1 file changed, 1 insertion(+) diff --git a/usermods/BME280_v2/usermod_bme280.h b/usermods/BME280_v2/usermod_bme280.h index 9168f4229..aa6d003f3 100644 --- a/usermods/BME280_v2/usermod_bme280.h +++ b/usermods/BME280_v2/usermod_bme280.h @@ -444,6 +444,7 @@ public: configComplete &= getJsonValue(top[F("PublishAlways")], PublishAlways, false); configComplete &= getJsonValue(top[F("UseCelsius")], UseCelsius, true); configComplete &= getJsonValue(top[F("HomeAssistantDiscovery")], HomeAssistantDiscovery, false); + tempScale = UseCelsius ? "°C" : "°F"; DEBUG_PRINT(FPSTR(_name)); if (!initDone) {