Soil Moisture sensor calibration

Hi All,
Have searched hi and low to resolve this and have found spatters of info but nothing definative.

I have a couple of soil moisture sensors (single and dual pronged) connected to 2 nodemcu’s. Each one reports moisture via mqtt and all works well.

The issue that Im failing to get representing realistic % outputs to a gauge card.

This code gets me a reading which is pretty much straight on the nodemcu information gui:

  • platform: mqtt
    name: “Garden2 Moisture”
    state_topic: “outside/garden2/tele/SENSOR”
    value_template: “{{ value_json[‘ANALOG’].A0 /10 }}”
    unit_of_measurement: “%”

The readings however are reversed (the more moisture the lower the percentage of moisture according to the gauge and when completly dry I get something like 78% and when submerged in a class of water it drops to around 45%

The operation of the sensor works fine but the calibration is driving me nuts. I have tried something I found by @wellsy which after doing some calculations is something like:

value_template: “{{ (170.967718 - states(‘sensor.your_sensor’) | float * 0.3225806) | round(0) }}”

However the code works but the % readings are way out.

Does anyone have any yaml showing how they have setup soil moisture sensors. It would be really appreciated.

Thanks
Peter

Assuming it is a linear relationship you have these points:

%actual, %reading
0,78
100,45

This gives the following linear equation:

%actual = -3* (%reading) + 236.4

Or

value_template: “{{ ( 236.4 - (states(‘sensor.your_sensor’) | float *3 ) | round(0) }}”

If that is till giving you odd readings it’s probably not a linear relationship an you need more data points (50%, 75%, etc).

Thanks tom_l and thankyou.

Unfortunately the check config doesnt like this at all.

It wont run.

In future, an error message from the log would help.

However I can see the issue. I wrote this on a tablet and it has substituted the incorrect quotation types. Also I missed a bracket. Try this (changing your sensor obviously):

value_template: "{{ ( 236.4 - (states('sensor.your_sensor') | float *3 )) | round(0) }}"

ok that config checked fine. reboot.

Percentage readings are jumping from:
04720% to 439% when wet
various and upto 129092% when dry.

The gui from the nodemcu is constant 425 wet and 735 when dry. absolutly solid unlike the gauge.

Now … log files. Please accept my apologise for being a total knob but where (what name) would they be in. Im running hassio on a ubuntu VM. Cant see anything worth reporting in the homeassistant directory or the /var/log … would the log file Im looknig for have a specific name.

/usr/share/hassio/homassistant/ has home-assistant.log however that has only 3 lines in it tailing it showed nothing happenning.

post mesasge… I believe the percentage of moisture is growing with time
its currently 5144188906671%

sorry

The % values you reported seem to be out by a factor of 100 (0.45, 0.78 rather than 45 or 78). Which would make the equation:

value_template: “{{ ( 236.4 - (states(‘sensor.your_sensor’) | float *303 )) | round(0) }}”

Don’t copy that, just adjust what you have as I’m on my mobile again and it has probably munted the quotes.

No idea what is causing the other intermittent issues you are seeing though.

Developer tools / logs in the front end for the log.

Unfortunately Im now at -20digits%

I changed the *303 to 0.3 and 0.03 and 0.003 All of which got me down to teh 236% figure however none of them altered from this (most likley as they are such small increments).

I have to go to work… so will play with this soon (when I get to work :slight_smile: