DaveTiff
(Dave T)
July 25, 2023, 7:53pm
1
Hi, I have added a pressure sensor to my ESP Home D1 Mini, Range is 0.5V to 5V, 2.5V = 400kpa
- platform: adc
pin: A0
name: "Mains Water Pressure"
update_interval: 10s
filters:
- multiply: 3.3
This give me the voltage from the sensor, so I want to Subtract 0.5 (v) from the A/D and multiply by 400 and retrun the result to HA.
Would be grateful on some help. or a good YouTube Video on how you do calculations in ESP Home.
Kind regards Dave
Use the calibrate_linear
filter.
- platform: adc
pin: A0
name: "Mains Water Pressure"
update_interval: 10s
filters:
- multiply: 3.3
- calibrate_linear:
- 0.0 -> 0.0
- 2.5 -> 400
I would normally apply the filter to a Copy sensor , so you can monitor the raw values for a while and establish more datapoints.
nickrout
(Nick Rout)
July 25, 2023, 9:59pm
3
I would use the lambda filter
- platform: adc
pin: A0
name: "Mains Water Pressure"
update_interval: 10s
filters:
- lambda: return ((x * 3.3) - 0.5) * 400
unit_of_measurement: "kPa"
DaveTiff
(Dave T)
July 26, 2023, 7:25pm
4
Thank you both for the replies, although I write software in assembler & C I dont understand calibrate_linear, will need to read up on it.
But happy with the lambda
Regards, Dave
DaveTiff
(Dave T)
July 26, 2023, 7:29pm
5
Hi just tried your code and got this error, did it as a screen dump so you can see the spacing
nickrout
(Nick Rout)
July 26, 2023, 7:49pm
6
Silly me, there is supposed to be ; at the end of the lambda line. Might also need .0 on the 400
- lambda: return ((x * 3.3) - 0.5) * 400.0;
Sorry about that, and see Sensor Component — ESPHome
DaveTiff
(Dave T)
July 27, 2023, 7:32am
7
Thanks, now working, also thanks for the link
re Dave
1 Like
Nicko1
(Nick)
October 15, 2023, 2:25am
8
Hi @DaveTiff
What’s does multiply 3.3 do?
I have a similar pressure sensor measuring pressure at the bottom of my water tank, It’s all so a 0.5 to 5V signal
looking to convert to 0-100%
Thanks
JulianDH
(Julian Hall)
October 15, 2023, 9:15am
9
Post #2 above has yaml. Calibrate_linear
You measure the voltage when empty and then when full and then use it in the filter
DaveTiff
(Dave T)
October 15, 2023, 9:45am
10
To cope with the scaling, see https://esphome.io/components/sensor/adc.html?highlight=esp32+d
This component prints the voltage as seen by the chip pin. On the ESP8266, this is always 0.0V to 1.0V Some development boards like the Wemos D1 mini include external voltage divider circuitry to scale down a 3.3V input signal to the chip-internal 1.0V. If your board has this circuitry, add a multiply filter to get correct values:
Nicko1
(Nick)
November 4, 2023, 5:36am
11
Ok Thanks I see now, I’m using ESP32 thats way i was a little confused.