Wi-fi Soil Moisture Sensor with ESPHome

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 มิ.ย. 2024
  • A quick and easy solution to monitoring plant soil moisture. Integrates into Home Assistant with ESPHome.
    Board: Seeed Xiao ESP32-C3, I use a capacitive moisture sensor and 1200mAh battery available on Amazon.
    YAML (pay attention to the greater than/less than notes below):
    esphome:
    name: wifi-moisture-sensor
    friendly_name: WiFi Moisture Sensor
    on_boot:
    then:
    - switch.turn_on: sensor_power
    on_shutdown:
    then:
    - switch.turn_off: sensor_power
    esp32:
    board: esp32-c3-devkitm-1
    framework:
    type: arduino
    Enable logging
    logger:
    Enable Home Assistant API
    api:
    encryption:
    key: "your_key"
    ota:
    password: "your_pwd"
    wifi:
    ssid: !secret wifi_ssid
    password: !secret wifi_password
    fast_connect: on
    power_save_mode: LIGHT
    manual_ip:
    static_ip: your.ip
    gateway: your.gateway
    subnet: your.subnet
    dns1: your.dns
    Enable fallback hotspot (captive portal) in case wifi connection fails
    ap:
    ssid: "your_fallback"
    password: "fallback_pwd"
    captive_portal:
    sensor:
    - platform: adc
    pin: 3
    name: "Soil Moisture"
    unit_of_measurement: "%"
    device_class: MOISTURE
    update_interval: 2s
    attenuation: 11db #required
    filters:
    - calibrate_linear: #set your own values here
    - 1.45 -&gt 100.00 #replace "&gt" with greater than symbol (YT doesn't allow angled brackets)
    - 2.821 -&gt 0.00
    - lambda: |
    if (x &lt 0) return 0; #replace "&lt" with less than symbol (YT doesn't allow angled brackets)
    else if (x &gt 100) return 100;
    else return (x);
    accuracy_decimals: 0
    - platform: adc
    pin: 4
    allow_other_uses: True
    name: "Battery Life"
    unit_of_measurement: "%"
    device_class: BATTERY
    update_interval: 2s
    attenuation: 11db #required
    filters:
    - multiply: 2.0
    - calibrate_polynomial: #set your own values here
    degree: 4
    datapoints:
    Map 0.0 (from sensor) to 0.0 (true value)
    - 3.4 -&gt 0.0
    - 3.6 -&gt 8.43
    - 3.81 -&gt 50.06
    - 3.86 -&gt 57.63
    - 3.92 -&gt 72.56
    - 3.96 -&gt 90.96
    - 4.05 -&gt 100
    - lambda: |
    if (x &lt 0) return 0;
    else if (x &gt 100) return 100;
    else return (x);
    - platform: adc
    pin: 4
    allow_other_uses: True
    name: "Battery Voltage"
    update_interval: 2s
    attenuation: 11db #required
    filters:
    - multiply: 2.0
    - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 2s
    switch:
    - platform: gpio
    pin: GPIO10
    id: sensor_power
    internal: true
    deep_sleep:
    run_duration: 10s
    sleep_duration: '5:59:50'
    === Timestamps ===
    0:00 Introduction
    0:44 Commercial Products... Fail
    1:10 DIY Solution
    3:54 YAML Configuration Overview
    7:25 Conclusion
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 73

  • @MattOmondPrintbotOMO
    @MattOmondPrintbotOMO 4 หลายเดือนก่อน +1

    Thank you so much for explaining that. I had everything working except that. Great project. Looking forward to making a few.

  • @UltraEd14
    @UltraEd14 11 หลายเดือนก่อน +3

    Amazing work! I'm making my own and this saved me a lot of hassle

    • @TechDregs
      @TechDregs  11 หลายเดือนก่อน +1

      Glad it helped.

  • @havemannolaf
    @havemannolaf 6 หลายเดือนก่อน

    Thank you. i wil do it to. 😀

  • @l0gic23
    @l0gic23 11 หลายเดือนก่อน +1

    Pretty cool. +1 sub

  • @tbandras
    @tbandras หลายเดือนก่อน

    Thanks a lot for sharing your project! A quick question: the Xiao C3 is rated up until 3.6V whilst the battery is 3.7V (and I assume the voltage goes even higher, maybe lower 4.x when fully charged). Have you experienced any issues with it, should I be considered if I were to copy your setup with a 3.7V LiPo battery?

    • @TechDregs
      @TechDregs  หลายเดือนก่อน

      Not sure where you're getting the 3.6V from, so IDK what to reference there. The Xiao is made for 3.7V LiPo batteries. The higher charged state voltages (~4.2V) are no problem; that's just how LiPo batteries are.

  • @niallbt
    @niallbt 11 วันที่ผ่านมา

    Do you have a github page or a written guide with wiring diagrams? I'm just getting started with ESP32 using batteries. Also, did you consider fitting a solar panel to this battery to keep it topped up?

  • @IF-VR123
    @IF-VR123 11 หลายเดือนก่อน +1

    Thanks, this is great and exactly what I want to create. Would you be willing to share the design for the case and a link to the battery you used (for sizing)?

    • @TechDregs
      @TechDregs  11 หลายเดือนก่อน

      I generally no longer share STLs for designs, but one thing that's helpful is that you can usually get STEP files for the SEEED Xiaos either directly from them or from grabcad. I wouldn't get this battery again, so I won't link it. I wasn't paying attention and ordered a 3-wire battery, and the third wire isn't useful (I think it's a thermistor in the battery for temp monitoring).

  • @lflondonol
    @lflondonol 4 หลายเดือนก่อน

    This is my very first ESP32 project and I am trying to understand how to connect a 18650 battery to the board. How did you make the connection? Are you connecting it to the 5v pin?

    • @TechDregs
      @TechDregs  4 หลายเดือนก่อน

      If you're using a Xiao, the battery connections are on the underside of the board. There are two pads there than you solder the battery connections to.

  • @tobias561
    @tobias561 วันที่ผ่านมา

    Thanks for the tutorial! But by Pasting your code i get the following error code:
    INFO ESPHome 2024.5.5
    INFO Reading configuration /config/esphome/boden-feuchtigkeit-1.yaml...
    ERROR Error while reading config: Invalid YAML syntax:
    while scanning a simple key
    in "/config/esphome/boden-feuchtigkeit-1.yaml", line 16, column 1
    could not find expected ':'
    in "/config/esphome/boden-feuchtigkeit-1.yaml", line 17, column 1
    can someone help me out? Many thanks!

  • @LorenzKort
    @LorenzKort 9 หลายเดือนก่อน +1

    Can you share the 3d printed design? I'd like to make my own :)

  • @timderks5960
    @timderks5960 หลายเดือนก่อน +1

    Is there any update on this project? How is the battery life? How accurate are your readings? I'd be very interested in a follow up

    • @TechDregs
      @TechDregs  หลายเดือนก่อน +1

      I can't speak to accuracy, as I have no other soil moisture measurement devices that use a different type of sensor. But since I reconfigured the sensor to draw power via GPIO that turns it off when in deep sleep, battery life is over four months on a charge. I did something like a followup in these videos:
      th-cam.com/video/4EZYYPmQnJY/w-d-xo.html
      th-cam.com/video/Yttauf94A04/w-d-xo.html

    • @timderks5960
      @timderks5960 29 วันที่ผ่านมา

      @@TechDregs Interesting videos, thanks!

  • @jebradleymd
    @jebradleymd 2 หลายเดือนก่อน

    I pasted your yaml code into the code for an ESP-D1 on Home Assistant and did a search and replace of the > and < markers as directed. When I run the "validate" on the code, I get the following error message:
    INFO ESPHome 2024.3.1
    INFO Reading configuration /config/esphome/d1-1.yaml...
    ERROR Error while reading config: Invalid YAML syntax:
    while scanning a simple key
    in "/config/esphome/d1-1.yaml", line 61, column 9
    could not find expected ':'
    in "/config/esphome/d1-1.yaml", line 62, column 9
    I do not see anything where I would think a ":" would be needed.

    • @TechDregs
      @TechDregs  2 หลายเดือนก่อน

      I'm not sure. It could be a spacing issue in your YAML or it could be a change to ESPHome that has occurred since I did this project. Lines 61/62 are in the WIFI setup for me, and I don't see any issues there, so I'm guessing it's in the lines above that somewhere. Just check all the indentation.
      I haven't updated mine in a while, but next time I do I'll update the code in the details.

  • @MattOmondPrintbotOMO
    @MattOmondPrintbotOMO 4 หลายเดือนก่อน +1

    Can you charge the battery via the Xiao or do you need to de solder and charge via a charger. Thanks/

    • @TechDregs
      @TechDregs  4 หลายเดือนก่อน +2

      If you plug the Xiao into any USB port/charger, it will charge the battery. No need to desolder.

  • @DivinaFarms_James
    @DivinaFarms_James 3 หลายเดือนก่อน +2

    How well did the capacitive sensor hold up?

    • @TechDregs
      @TechDregs  3 หลายเดือนก่อน +1

      It's still going. I haven't looked at it closely in a while... it's just out there doing its job.

  • @Marco1010101
    @Marco1010101 3 หลายเดือนก่อน

    Ok, my sensor is working, it reads 30 second and after 3h in deep sleep. But I have 2 questions.
    1. It seems that the Voltage reading is not very accurate. I have calibrate the value Many times but after some reboot it reads 0.2 0.3 V more or less than the real battery value. I have used two resistor 220k in parallel.
    2. How can I do to allowr home assistant to show in the dashboard the last value read when the esp32 is in deep sleep.
    Thanks in advance for any help.

    • @TechDregs
      @TechDregs  3 หลายเดือนก่อน

      For #2, that should just show up automatically over time. For #1, battery voltage in my experience can fluctuate a bit, especially when it's above 4.0V. It seems to settle down and get smoother below that.

    • @kalabahaa
      @kalabahaa 5 ชั่วโมงที่ผ่านมา

      read esphome deepsleep page.
      While in deep sleep mode, the node will not do any work and not respond to any network traffic, even Over The Air updates. If the device’s entities are appearing as Unavailable while your device is actively sleeping, this component was likely added after the device was added to Home Assistant. To prevent this behavior, you can remove and re-add the device in Home Assistant.
      i think this should solve your problem.

  • @SuperMrZerox
    @SuperMrZerox 10 หลายเดือนก่อน

    can you send the link of soil sensor and where did you get it connected. with my sensor only stupid values

    • @TechDregs
      @TechDregs  10 หลายเดือนก่อน

      Did you calibrate your sensor values? You need to test what voltage it sends in open air and fully submerged in water. I used these: www.amazon.com/Capacitive-Moisture-Corrosion-Resistant-Detection/dp/B07SYBSHGX

  • @kherhitesh
    @kherhitesh 5 หลายเดือนก่อน

    nice video sir, i do as well as your code , but after update ESPHome platform - adc duplicate error show , so what to do any other way?

    • @TechDregs
      @TechDregs  5 หลายเดือนก่อน +1

      Looks like mine died this week (I think water got into it), so I can't test this, but try replacing:
      pin: 4
      with:
      pin:
      number: 4
      inverted: false
      allow_other_uses: true
      In both places that it appears. See if that works. They implemented a change recently to break using a pin multiple times unless you specifically allow it.

    • @kherhitesh
      @kherhitesh 3 หลายเดือนก่อน +1

      @@TechDregs Thank you , New ESPhome update as well as working fine pin multiple

  • @SuperMrZerox
    @SuperMrZerox 10 หลายเดือนก่อน +1

    Can Share all ? the project is amazing. I've been looking for something like this for a long time and now I'm grateful to you for showing it. can you show the wiring properly? Thx

    • @TechDregs
      @TechDregs  10 หลายเดือนก่อน

      There's actually very little wiring. The battery is connected to the battery pads on the bottom of the board. I've got a voltage divider on the positive lead, with one side to ground and the other to an analog pin. The sensor board only has three wires: power in, ground, and sensor out. The sensor out just needs to go to an analog pin. The YAML is in the description; so you can see which pins I used there for the sensor and battery voltage readings. One trick that I have done since this video is powering the sensor from a digital GPIO pin, which I enable when the device wakes up and disable when it goes to sleep. That has a huge impact on battery life, as this sensor draws about 5mA when it's on.

    • @enriqueazvz
      @enriqueazvz 6 หลายเดือนก่อน

      @@TechDregs great stuff. Would you have the YAML that includes the GPIO pin as the 'smart' power source for the sensor?

    • @TechDregs
      @TechDregs  6 หลายเดือนก่อน +1

      I updated the details with the code. Basically, you just add onboot and onshutdown commands, and add the pin below as a switch. Make sure to change the GPIO to the pin you're using for power to the sensor. I also added a wifi signal sensor, since that can be useful to see.

    • @enriqueazvz
      @enriqueazvz 4 หลายเดือนก่อน

      thanks@@TechDregs , I was implementing it on my side and apparently HA after 2023 requires the use of 'allow_other_users' if the same pin is used for several uses (battery life and battery voltage)
      I replaced pin: 4 for 'pin:
      number: 4
      allow_other_uses: True'

    • @enriqueazvz
      @enriqueazvz 4 หลายเดือนก่อน

      What code did you use to calibrate the moisture sensor? (so I can get my min and max values)

  • @Marco1010101
    @Marco1010101 3 หลายเดือนก่อน

    can you show me what kind of resin did you have use (black/gray)?

    • @TechDregs
      @TechDregs  3 หลายเดือนก่อน

      It's just cheap basic epoxy from a local hardware store.

  • @Marco1010101
    @Marco1010101 4 หลายเดือนก่อน

    Hi, great job, what is the battery duration with that configuration?

    • @TechDregs
      @TechDregs  4 หลายเดือนก่อน +1

      With the GPIO power setup, at least 4 months on a charge.

  • @pemlody
    @pemlody 7 หลายเดือนก่อน +1

    How long it runs at battery?

    • @TechDregs
      @TechDregs  7 หลายเดือนก่อน +3

      Currently, it's been almost 4 months since I last charged it. It might last another month or two, looking at the voltage plots.

  • @Marco1010101
    @Marco1010101 3 หลายเดือนก่อน +1

    Hello, I'm trying to make my yaml configuration, but I got this error: Pin 0 is used in multiple places. Could you help me? thanks in advance
    Failed config
    sensor.adc: [source :55]

    Pin 0 is used in multiple places.
    platform: adc
    pin:
    number: 0
    mode:
    input: True
    output: False
    open_drain: False
    pullup: False
    pulldown: False
    inverted: False
    ignore_strapping_warning: False
    drive_strength: 20.0
    name: Battery Life
    unit_of_measurement: %
    device_class: battery
    update_interval: 2s
    attenuation: 11db
    filters:
    - multiply: 2.0
    - calibrate_polynomial:
    degree: 4
    datapoints:
    - from: 3.4
    to: 0.0
    - from: 3.6
    to: 8.43
    - from: 3.81
    to: 50.06
    - from: 3.86
    to: 57.63
    - from: 3.92
    to: 72.56
    - from: 3.96
    to: 90.96
    - from: 4.05
    to: 100.0
    - lambda: !lambda |-
    if (x > 0) return 0;
    else if (x > 100) return 100;
    else return (x);
    disabled_by_default: False
    force_update: False
    accuracy_decimals: 2
    state_class: measurement
    raw: False
    sensor.adc: [source :80]

    Pin 0 is used in multiple places.
    platform: adc
    pin:
    number: 0
    mode:
    input: True
    output: False
    open_drain: False
    pullup: False
    pulldown: False
    inverted: False
    ignore_strapping_warning: False
    drive_strength: 20.0
    name: Battery Voltage
    update_interval: 2s
    attenuation: 11db
    filters:
    - multiply: 2.0
    disabled_by_default: False
    force_update: False
    unit_of_measurement: V
    accuracy_decimals: 2
    device_class: voltage
    state_class: measurement
    raw: False

    • @TechDregs
      @TechDregs  3 หลายเดือนก่อน +1

      You need to allow other uses. It's an update ESPHome has since I made this. Use it every time you setup a pin which is used more than once.
      pin:
      number: 0
      allow_other_uses: True

    • @Marco1010101
      @Marco1010101 3 หลายเดือนก่อน +1

      @@TechDregs grazie

  • @kherhitesh
    @kherhitesh 3 หลายเดือนก่อน

    how much battery life as well as your deep sleep time?

    • @TechDregs
      @TechDregs  3 หลายเดือนก่อน +2

      I wake mine up for 10s every 6hours (so, 4x a day). The battery I used lasts ~3.5months on a charge.

    • @kherhitesh
      @kherhitesh 3 หลายเดือนก่อน +1

      ​@@TechDregs good battery backup 👍

  • @lflondonol
    @lflondonol 5 หลายเดือนก่อน

    How did you get the voltages for the battery?

    • @TechDregs
      @TechDregs  5 หลายเดือนก่อน +1

      See ~2m in the video. Just taking a reading via a voltage divider to an analog pin on the Xiao.

  • @MattOmondPrintbotOMO
    @MattOmondPrintbotOMO 4 หลายเดือนก่อน

    Would you be able to explain the switch code here. switch:
    - platform: gpio
    pin: GPIO10
    id: sensor_power
    internal: true
    Sorry a noob. Have you got a switch wired into pin 10 thanks for a great project

    • @TechDregs
      @TechDregs  4 หลายเดือนก่อน

      I'm using pin 10 to provide the power to the soil moisture sensor rather than wiring it directly to the output voltage pins on the ESP32 board. That allows me to turn power to the sensor on and off. This is the routine that sets up pin 10 as a power outlet that can be turned on and off (which ESPHome calls a switch). So, switch: - platform: GPIO tells ESPHome that this will be a binary on/off switch using a GPIO pin. ID: sensor_power is the internal name of that switch so I can refer to it elsewhere (like the boot and shutdown sequences). Internal: true means that it isn't exposed externally, so the switch won't show up in Home Assistant.

    • @MattOmondPrintbotOMO
      @MattOmondPrintbotOMO 4 หลายเดือนก่อน

      Sorry just reading this again and doing a little Google I was un aware you could supply 3.5 volts from a gpio pin. Other than vin etc. am I misunderstanding. Probably 😢

    • @TechDregs
      @TechDregs  4 หลายเดือนก่อน +1

      Depends on the pin. Some pins are input only. But GPIO pins can output about 40mA of current at 3.3v. There is also a total power budget that you have to stay under, but if you're only doing one or two pins of output, that's not a concern.

    • @MattOmondPrintbotOMO
      @MattOmondPrintbotOMO 4 หลายเดือนก่อน +1

      Awesome thank you. Love to learn.

    • @MattOmondPrintbotOMO
      @MattOmondPrintbotOMO 4 หลายเดือนก่อน

      @@TechDregs Pleas ignore this if you wish. I know you are not a help board. But I am curious. I have it all working. But when it goes into deep sleep it becomes unavailable on the dashboard. I have read on a few forums that it is best to change over to mqtt and then you can use birth and will_message. But I did a quick try and havn't been able to do the switch to mqtt. I am wondering if you have the same issue.

  • @roldgold5972
    @roldgold5972 หลายเดือนก่อน

    How do you think a solar charger would do?

    • @TechDregs
      @TechDregs  หลายเดือนก่อน +1

      Already done. :) th-cam.com/video/Yttauf94A04/w-d-xo.html

    • @roldgold5972
      @roldgold5972 27 วันที่ผ่านมา

      @@TechDregs 🐐🐐

  • @njain2686
    @njain2686 11 หลายเดือนก่อน

    How will you charge it?

    • @TechDregs
      @TechDregs  11 หลายเดือนก่อน

      I'll just pull it and charge it inside on a cell phone charger.

  • @dr.m.sanaullahsahar9859
    @dr.m.sanaullahsahar9859 5 หลายเดือนก่อน

    I can't see a link to your 3D printed parts. May i ask?

    • @TechDregs
      @TechDregs  5 หลายเดือนก่อน

      Sorry, I generally no longer upload 3D prints. Too many of my past designs ended up being sold on ebay and etsy.

    • @MARY-si9gl
      @MARY-si9gl 14 วันที่ผ่านมา

      @@TechDregs Is it possible that you send me the 3D print file in an E-Mail? I will not sell the file. I just ordered a printer and i´m verry new in this material.

    • @rudopodkrivacky
      @rudopodkrivacky 4 วันที่ผ่านมา

      @@TechDregs Thanks for the project also is it possible to connect the battery directly to the esp32 c3 supermini?, and is it possible to send the 3D print file by email? Of course, I will not move the file to the web. Well thank you

    • @TechDregs
      @TechDregs  4 วันที่ผ่านมา

      @@rudopodkrivacky I don't the supermini has onboard battery management.