Map values

I’ve been looking at filters reading the docs over and over but I don’t get it.
On d1-mini, I am reading the ADC from a capacitive moisture sensor.
These are the values I am getting:
wet = 983
Dry = 2339
With Arduino IDE I would do map(sensorVal, 983, 2339, 100, 0)

How can I achieve this with EspHome ?
I curently have:

 sensor:
   - platform: adc
     raw: true
     pin: A0
     name: "Moisture sensor"
     filters:
       - multiply: 3.3

So you want a binary output? Either wet or dry? Use a lambda which is like “if over 1500 then dry else wet”.

I don’t want wet or dry, my goal is to have a value between 0 and 100 that will be equivalent (or close enough) to the % of humidity detected.

OK then I think you want

- calibrate_linear:
      - 2339 -> 0.0
      - 983 -> 100.0
1 Like

That works !

Thank you

1 Like