Soil moisture sensor icw Sonoff TH10 for garden irrigation

Hi out there!

I like to share how I am trying to automate my garden irrigation based on a Sonoff TH10 and capacitive soil moisture sensors:

First of all I am still rather news to this. So it can be very well so that I didn’t take the shortest route to the outcome. I needed a lot of reading and trial and error to get where I am today and I am still not where I want to be!

First of all I am running HA on a raspberry PI4 with a 64GB SD card. It’s the set-up I choose when I started my home automation just less the a year ago. Very much a noob still.

I am working a lot with Sonoff devices and they have proven to be quite reliable. I just integrated them (various types of switches, sensors and even cameras) on the original software. I have automation for the heating, pool, alarm, electricity monitoring etc. and my latest project is irrigation automation.

I noticed via my electricity consumption monitoring that the irrigation (especially the over-irrigation) was one of the most expensive consumers of energy and water. Hence I decided to control it.
Let me explain how the physical part is set up: I have a borehole at about 70m deep with a 380v pump automatically switching on a high and low level floaters in a storage tank. The storage tank is connected with a booster pump keeping pressure on the irrigation system and the irrigation is controlled by some old fashion battery operated Rainbird controllers which control 10 sections in the garden.

The Rainbirds are underground, have no WiFi or cloud capabilities and out of reach of the WiFi or RF433mhz as well.

So what I decided to do is set fixed timings for irrigation with the Rainbird and supply pressure with the booster pump whenever irrigation was required :

That are the basics and it is working fine. I keep an eye on the forecast and switch the pump accordingly. But since I am out of the house sometimes for months I wanted a more scientific control of the irrigation. I want to know if the soil is dry yes or no and whether I need to irrigate. Hence the project was started (to be cont’d)

So the next step was to control the booster pump with a soil moisture sensor (or sensors). Since I have some good experiences with the Sonoff stuff I bought a TH10 with a sensor connection and a capacitive soil moisture sensor (CSMS) and linked it all to see what happened:

It proves that I am a noob and there must be people on their knees now laughing…

Anyway I quickly understood that a analog signal cannot be mixed with a digital input. So I read and read and came across a article of Tinkerman.cat (https://tinkerman.cat/post/sonoff-th10-th16-sensors-displays-actuators/) and started to learn about digital inputs and I2C protocol… I also understood that I needed to covert the analog signal to digital. Hence I started to search for a ADC and I finally settled with an ADS1115 to convert the analog output to digital output. So the basic components were now: an ADS1115, the TH10 and the CSMS. How to link those fellows to each other…

Interesting take on it! I’m working on something similar but using Arduino’s with that same sensor to create a network of battery operated devices throughout my property to broadcast the moisture levels. Working on getting the power usage down so that a standard battery allows it to last 4-5 months on one charge (at least).

To understand how this is actually working I bought an arduino and started experimenting with it:

Quite quickly had readings and the calibration in itself was fairly easy. So with this:


And the pin out of the ADS1115:

I needed to hook it up with the TH10. But how to figure out the TH10 in combination with I2C. Here based on the article of Tinkerman I figured that I need to flash the TH10 to set the pins for SCL and SDA. So I went into flashing the TH10 with Tasmota Tasmotizer!

1 Like

So I started my first flash. I went to GitHub Tasmota and followed the instruction to install the Tasmotizer on my MAC. That in itself was straightforward and I got it up and running quickly.

I soldered 4 pins in position on the board of the TH10 to establish the flash.


Bought a CP2102 USB module and started my first ever flash.

That was not as easy as all YouTube instructions you make to believe. My TH10 here ‘died’ in the process. The issues I came along were the following:

Tick the back-up box to back up your original firmware. I did but then it doesn’t continue with erase and write. I found on GitHub that it was an issue and that it was resolved. Well for me it wasn’t. I couldn’t get a connection with Tasmotizer and the TH10. Somewhere during that trying the first TH10 died. No reset, no leds no nothing. Dead as anything. After numerous try-outs I decided to convert another TH10 and not to back-up the firmware. To my surprise it connected, erased and wrote the new firm ware. I selected the Tasmota.sensors.bin as I read somewhere if you were to work with sensors.

After that you can send your WiFi details by using the send config button. That does work however the Get IP button doesn’t and that took me some time to figure out. I thought that the flash had failed but it didn’t. Just the Get IP button didn’t work. I did a network scan and I found eventually the Tasmota and with using the IP address I got the UI of Tasmota! Victory once again. I was quite happy. Next step was how to link the ADS to the TH10 now for real…

I am planning to connect a sensor which will be completely underground (cable and sensor included) to the TH10 which I hook up in HA. The TH10 will be just powered with 220V. No batteries. Gives a stable power supply to the sensor and I found the Sonoffs cheap and reliable. I have already done a trial with 20m cable between the sensor and the Sonoff and it holds fine. There should be no signs of sensors at all.

So again I followed the article of Thinkerman.cat and the good things is that the TH10 has 2 pins which can be used for SCL and SDA. This is how I finally wired the setup:

Then I configured Tasmota. Linked GPIO14 SCL which is actually the tip of the 2.5mm plug and the SDA to GPIO4 which is R1 of the plug. I actually soldered these wires on the back of the 2.5 jack plug on the board to the ADS1115.

Once that was done I got a reading on my screen. Again I was happy here! There is life in numbers!!

I tried the sensor in dry air and it gave a reading of about 15000 and in a glass of water it gave about 7000. That is the range which I will use to calibrate it to % humidity (from 0 % dry air to 100% just water).

The formula which I will later use in HA is:
Humidity = 187.5 - 0.0125*(reading ADS1115 Analog0).

Then I went a bit further to understand what this humidity means and I bought a simple soil moisture sensor and used it in combination with the capacitive sensor and a bio-sensor (a plant :grin: :grin:):

With this set-up I have tried to give meaning to the numbers. I established a Low Level at 7500 and a Upper Level at 8300, which I will use later the switch on/off the booster pump.

After that I had to decided where to put the ADS1115. Close to the sensor (eventually underground) or close or inside the TH10. So it did a trial with the ADS on top of the TH10 and 20m cable to the sensor. No noticeable difference and I decided to integrate the ADS into the TH10:

So finally the end result is a neat and clean TH10 with an ADS inside which can handle the analog signal from the sensor!

The next steps I have to figure out is the integration with HA. I already integrated Tasmota and MQTT but its the first time I will be actually using it. So lets see how that comes along,

Then I have to make another 2 or 3 steps. I want to have 4 sensors at various locations which I will use to control the irrigation for the different areas. The plan is that they go fully underground and so I have to make the sensors waterproof.

Then get the automations working and finally I want add a rain sensor in case it starts raining while the pump is running!

Keep you posted.

BTW some help on the integration with HA is welcome! I am still confused on the use of MQTT. If some can show me how the config.yaml is configured for Tasmota and MQTT that would be a big help.

Hi, are you willing to sell this modified product? I also have this sonoff, but I don’t know if I can change it.

ive been working with various moisture sensors via esp32/8266 or even the lilygo both versions. the data coming from the esp was crap with that sensor imo, i dont have any sonoff products atm but i am going order me up a few parts to try and duplicate as this is waaaaay cleaner. Can you post your entire tasmota config??

Also if i understand the ads1115 you can add multiple sensors to one one th10 now right? it has multiple Analog inputs

I will try. The issue is that I fried my SD card and lost everything I did. I am currently still not up and running and I could take some while. Sorry…

sad face, but ill use the screenshots as a jump off point. anything related to this project cause you to go down?

Yes. It has the option for 4 sensors. However the wiring is very sensitive and it seems that I have some spill-over. Another thing which I found out what makes a difference is that the same type of sensor but from different suppliers gives different readings. So my reco is to buy your sensors if you want to use more all in once from one supplier (brand/make). In that way you have only one calibration to make.

1 Like

I am afraid not. Sorry!

Ive noticed the difference in brands and producers for sure, all of mine run off of USB which is plugged into the wall and i can see voltage spikes sometimes when other devices power on and off in the home. i do have 2 version from the same brand i used esphome to filter out weird spikes and dips giving me a very smoothed curved on my graphs. A lot of the same filters can be used by HA just have to define a template sensor etc. Atm my sensors are real ugly, i have a 3d printer otw to help me clean up some of them but idk how much cleaner i could get then your final product. We will see tho lol, still this is a prety good write up and i may run with

No. I used a rpi 4 with a SD card. Because of some power failures I fried my SD card. The backups are on the card too, so I lost them too. I am now trying to recup but not sure about the outcome.

Só I have been sick and tired of HA for a few months but have restarted. The first thing I did is to build a fail safe system.

My rpi boots now from USB and SSD and it has a powerbank power back up. The snapshots I make daily are downloaded to my hard drive on my computer. There I keep a HA instance which can run on a VM. So even if my rpi goes up in flames I will be back in minutes from my laptop. I recommend to do something like that. There basically no warnings in the community but I have read a lot about crashed SD cards. Additional advantage of USB and SSD that it is (measured) 10-20 faster.

Good luck and let me know how you get along. I have still not figured out Tasmota icw HA.

Most of it relates to the fact that SD cards are not meant to read and write that much data that quickly, so if you have a lot of data streaming it in can overload the sd. Ive read a lot of the blogs and help groups of people waking up in the mornings to a smart home all fuh up. Good news is i already have the SSD bridge recommended just waiting to get the SSD itself now. I will make sure i do that sooner rather then later. The rest for power surge protection ill have the router and pi behind a battery back up to smooth out its power and keep it all powered when necessary

I appreciate the benefiting of your experience sir thank you!

Good measures to protect your setup. Avoid a major headache :+1::+1::+1:

Can’t find sensor with digital signal?