diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 63aa4123ae..8b61e6aa38 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -415,4 +415,14 @@ optional parse_number(const std::string &str) { ///@} +/// @name Number manipulation +///@{ + +/// Remap a number from one range to another. +template T remap(U value, U min, U max, T min_out, T max_out) { + return (value - min) * (max_out - min_out) / (max - min) + min_out; +} + +///@} + } // namespace esphome