diff --git a/esphome/components/text_sensor/filter.cpp b/esphome/components/text_sensor/filter.cpp index 52c2bd394e..d9afaf80f1 100644 --- a/esphome/components/text_sensor/filter.cpp +++ b/esphome/components/text_sensor/filter.cpp @@ -90,8 +90,10 @@ MapFilter::MapFilter(const std::initializer_list &mappings) : mapp optional MapFilter::new_value(std::string value) { for (const auto &mapping : this->mappings_) { - if (mapping.from == value) - return mapping.to.str(); + if (mapping.from == value) { + value.assign(mapping.to.c_str(), mapping.to.size()); + return value; + } } return value; // Pass through if no match }