You can use a filter with lambda in esphome to use the map function. The snipped is what I use for HX711
filters:
- lambda: |-
auto first_mass = 0.0;
auto first_value = 1176425;
auto second_mass = 122;
auto second_value = 1279801;
auto r = map(x, first_value, second_value, first_mass, second_mass);
if (r > 0) return r;
return 0;