From c760218024b987584331c3f84485ea9b13ce0845 Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 16 Jul 2026 21:20:13 +0200 Subject: [PATCH] add UPTIME for HA UOM - #3146 --- src/core/emsdevicevalue.h | 1 + src/core/mqtt.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/core/emsdevicevalue.h b/src/core/emsdevicevalue.h index 25ca1875b..58154771d 100644 --- a/src/core/emsdevicevalue.h +++ b/src/core/emsdevicevalue.h @@ -81,6 +81,7 @@ class DeviceValue { HERTZ, // 27 - Hz - frequency CONNECTIVITY, // 28 - used in HA - connectivity TIMESTAMP, // 29 - used in HA - timestamp + UPTIME, // 30 - used in HA - uptime for boot time }; // TAG mapping - maps to DeviceValueTAG_s in emsdevicevalue.cpp diff --git a/src/core/mqtt.cpp b/src/core/mqtt.cpp index 5c77f7b9c..8063a2de8 100644 --- a/src/core/mqtt.cpp +++ b/src/core/mqtt.cpp @@ -587,7 +587,7 @@ void Mqtt::ha_status() { // These come from the info MQTT topic - and handled in the publish_ha_sensor_config function publish_system_ha_sensor_config(DeviceValueType::STRING, "Version", "version", DeviceValueUOM::NONE); - publish_system_ha_sensor_config(DeviceValueType::STRING, "Boot time", "bootTime", DeviceValueUOM::TIMESTAMP); + publish_system_ha_sensor_config(DeviceValueType::STRING, "Boot time", "bootTime", DeviceValueUOM::UPTIME); } // add sub or pub task to the queue. @@ -1178,7 +1178,7 @@ void Mqtt::add_ha_classes(JsonObject doc, const uint8_t device_type, const uint8 doc[uom_ha] = "L/h"; } else if (uom == DeviceValueUOM::L) { doc[uom_ha] = "L"; - } else if (uom == DeviceValueUOM::TIMESTAMP) { + } else if (uom == DeviceValueUOM::TIMESTAMP || uom == DeviceValueUOM::UPTIME) { // do nothing } else if (uom != DeviceValueUOM::NONE) { auto uom_str = EMSdevice::uom_to_string(uom); @@ -1280,6 +1280,10 @@ void Mqtt::add_ha_classes(JsonObject doc, const uint8_t device_type, const uint8 doc[sc_ha] = sc_ha_measurement; doc[dc_ha] = "timestamp"; break; + case DeviceValueUOM::UPTIME: + doc[sc_ha] = sc_ha_measurement; + doc[dc_ha] = "uptime"; + break; case DeviceValueUOM::MV: case DeviceValueUOM::VOLTS: doc[sc_ha] = sc_ha_measurement;