I have recently assembled the components for a Soil Capacitance Sensor, which I have configure using EPSHome. I am pleased to announce that the sensor appears to be working and it provides an output which changes depending on the moisture level.
The issue I am having is the output it provides is in volts and I would like to output this in a more friendly reading as a percentage.
I have done some experiments and have determined that when submerged in water the output is 1.31v and when the sensor is dry it is 2.79v
I believe I can achieve the outcome I am looking for by using a template sensor with a lambda filter however despite my best efforts to research how to achieve this I haven’t been able to locate anything workable.
I would like my lambda to output 100% if the sensor reports a reading of 1.31v or below, and 0% if the sensor reports a reading of 2.79v or above. Then based on these min and max values calculate a percentage value for any reading in-between.
Hi there,
(I just started with some easy automation with Home Assistant) is there any way to have a calibration feature in Home Assistant for future calibration? These capacitive sensors run out of calibration really quickly… I was wondering about an easy way to calibrate them for the UI.
Thanks!
It looks like your sensor measures much lower voltage than 1.3 V for wet. How did you get your calibration? You can fix the range by using the following lambda, but you should fix your calibration first.
- lambda: |
if (x < 0) return 0;
else if (x > 100) return 100;
else return (x);
You forgot that the Wemos boards have an external converter to put the 0.0-1.0 V range and spread it between 0.0-3.3V of real voltage.
So you need first a multiply filter of 3.3.
Then there’s the question which voltage the sensor is running at: I gpt some of the 2.0 Version. They can either run at 3.3 V or 5 V. Depending on the supplied voltage for VCC on them they’ll likely have a different voltage at the analog output.
thanks a bunch this works for me using an esp32 and a capacitive soil moisture sensor. just had to remove all the stuff below attenuation line to get the raw readings to get my 0 and 100 values. I have a question about the filters - median : window_size: 7 send_every: 4 send_first_at: 1" first what do these values correspond to? is this a timing thing where it skips sending data? I am using my esp 32 in a constant power environment so it should not need to sleep or worry about updating too much.