├── README.md └── moisture.yaml /README.md: -------------------------------------------------------------------------------- 1 | # Capacitive-Soil-Sensor 2 | This is a setup to use multiple capacitive soil sensors with one ESP8266 utilizing the great ESPHome library. Eventually this will will have 3D printed design files as well to enclose and waterproof the capacitive soil sensors and the ESP8266. 3 | 4 | Here are the sensors I am using: 5 | https://www.aliexpress.com/item/10pcs-Capacitive-soil-moisture-sensor-not-easy-to-corrode-wide-voltage-wire-for-arduino/32859931034.html?spm=a2g0s.9042311.0.0.36424c4dca4OGe 6 | 7 | I am using this Wemos D1 Mini Lite to read the sensor values: 8 | https://smile.amazon.com/gp/product/B07BK435ZW/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1 9 | 10 | Connect all of the sensors ground wires to ground, and connect all the analog outputs from each sensor to the same ADC pin. The positive wire on each sensor should go to its own GPIO on the ESP8266. 11 | 12 | Some notes for parts I will use in this project: 13 | 14 | I am going to use these connectors to make each sensor able to disconnect from a long cord, yet still stand up to outside weather 15 | https://smile.amazon.com/gp/product/B071NCK9WW/ref=ppx_yo_dt_b_asin_title_o04_s00?ie=UTF8&psc=1 16 | 17 | I am going to use this AC to DC converter to power the Wemos 18 | https://smile.amazon.com/gp/product/B076K8HT8Z/ref=ppx_yo_dt_b_asin_title_o09_s00?ie=UTF8&psc=1 19 | -------------------------------------------------------------------------------- /moisture.yaml: -------------------------------------------------------------------------------- 1 | esphome: 2 | name: wemos_moisture 3 | platform: ESP8266 4 | board: d1_mini_lite 5 | on_boot: 6 | then: # This ensures no sensors are getting power 7 | - output.turn_off: plant1Output 8 | - output.turn_off: plant2Output 9 | 10 | wifi: 11 | ssid: !secret ssid 12 | password: !secret wifi_password 13 | 14 | api: 15 | 16 | logger: 17 | 18 | ota: 19 | 20 | # These define the GPIO that are hooked up to the positive pin on the individual sensors 21 | output: 22 | - platform: gpio 23 | pin: D0 24 | id: plant1Output 25 | - platform: gpio 26 | pin: D1 27 | id: plant2Output 28 | 29 | 30 | # Dry 0.7 - taken from in the air, probably should do it directly in dry soil 31 | # Wet 0.264 - taken from in a glass of water, probably should do it directly in saturated soil 32 | sensor: 33 | # This is the actual reading of the various sensors 34 | - platform: adc 35 | pin: A0 36 | id: moisture 37 | update_interval: 0.1s 38 | internal: true # Don't expose this sensor to HA, the template sensors will do that 39 | accuracy_decimals: 1 40 | filters: 41 | - sliding_window_moving_average: # averages the last 10 results, probably overkill 42 | window_size: 10 43 | send_every: 10 44 | - lambda: |- 45 | if (x > 0.7) { // if over 0.7 volts, we are dry 46 | return 0; 47 | } else if (x < 0.264) { // if under 0.264 volts, we are fully saturated 48 | return 100; 49 | } else { 50 | return (0.7-x) / (0.7-0.264) * 100.0; // use a linear fit for any values in between 51 | } 52 | # actual sensors reported to Home Assistant, pull the value from the internal ADC sensor 53 | - platform: template 54 | name: "Plant 1 Soil Saturation" 55 | id: plant1 56 | unit_of_measurement: "% Saturation" 57 | icon: "mdi:water-percent" 58 | update_interval: never 59 | accuracy_decimals: 0 60 | lambda: |- 61 | return id(moisture).state; 62 | - platform: template 63 | name: "Plant 2 Soil Saturation" 64 | id: plant2 65 | unit_of_measurement: "% Saturation" 66 | icon: "mdi:water-percent" 67 | update_interval: never 68 | accuracy_decimals: 0 69 | lambda: |- 70 | return id(moisture).state; 71 | 72 | # This is the code that runs over and over again turning on the correct sensors then updating the template sensors 73 | interval: 74 | - interval: 15s # if you add more outputs, increase this time as appropriate 75 | then: 76 | - output.turn_on: plant1Output # turn on sensor 1 77 | - delay: 5s # let sensor 1's reading settle 78 | - component.update: plant1 # update sensor 1's reading in HA 79 | - output.turn_off: plant1Output # stop powering sensor 1 80 | - output.turn_on: plant2Output # turn on sensor 2 81 | - delay: 5s # let sensor 2's reading settle 82 | - component.update: plant2 # update sensor 2's reading in HA 83 | - output.turn_off: plant2Output # stop powering sensor 2 --------------------------------------------------------------------------------