diff --git a/esphome/core/helpers.cpp b/esphome/core/helpers.cpp index ede1640af2..f7bc6c5bee 100644 --- a/esphome/core/helpers.cpp +++ b/esphome/core/helpers.cpp @@ -589,7 +589,7 @@ size_t value_accuracy_to_buf(std::span buf, float size_t value_accuracy_with_uom_to_buf(std::span buf, float value, int8_t accuracy_decimals, StringRef unit_of_measurement) { size_t len = value_accuracy_to_buf(buf, value, accuracy_decimals); - if (unit_of_measurement.empty()) { + if (len == 0 || unit_of_measurement.empty()) { return len; } char *end = buf_append_sep_str(buf.data() + len, buf.size() - len, ' ', unit_of_measurement.c_str(),