My first ESPHome powered DIY sensor!

Hey all!

I’ve been spying on these forums for some time, slowly getting into the world of home automation and sensors. Today I officially finished by first project, a plant moisture sensor! I’ve been using a plant app for some time to notify when I should water my plans (as they apparently die otherwise!) but it just does this based on the plant type and a lot of the time the plant doesn’t need it. So, I decided to have a moisture sensor as my first DIY ESPHome sensor.

I’ve attached some pictures; the case is quite big but no 3D printer just yet and it’ll do for the time being. Also linked the parts I used and the ESPHome config if anyone is interested.

I’ve learnt a lot as this was also my first-time soldering, have needed to resolder this quite a bit as I made mistakes, such as hooking up the sensor to VCC thinking that is turned off during deep sleep!

Let me know your thoughts and what you’ve done with your plant sensor or if you have any improvements I could make.

Images

Parts Used

  • DFRobot FireBeetle 2 ESP32-E Board
    • I used this one as it has battery support built in, and seemed to have good reviews from what I could see, I did find the pin naming/layout a bit confusing, and it also doesn’t enter auto flash which isn’t explained in the documents - although that could be me not being experienced with schematics etc.
  • Capacitive Soil Moisture Sensor
    • Seems quite good, I know these can be hit and miss looking online, however, the reviews on Pi Hut seemed to indicate they’re a bit more of a reliable supplier. I did receive a 2.0 version, although I don’t know what the difference is
  • Protype Board
    • Probably not needed as to be honest I could of soldered directly to the ESP board, although I decided to use this for some reason
  • 3.7v Recharchable Lithium battery
    • For me the plug was in the wrong polarity, although is fairly ease to swap the cable around on the plug to suite the board
  • Box
    • Ideally would have liked to 3d print one but I do not have a 3d printer and these were pretty cheap so I just modified one to make the holes I needed

ESPHome Config
I went through a lot of iterations with this, and I’m sure there might be better ways to do it but this seems to work well for me

esphome:
  name: "kitchen-plant-monitor"

esp32:
  board: firebeetle32
  framework:
    type: arduino

# Enable logging
logger:

ota:

output:
  # Soil Sensor Live
  - platform: gpio
    pin: 14 # D6
    id: d2_soil_sensor
    inverted: true

sensor:
  - platform: adc
    pin: 34
    attenuation: 11db
    name: "Battery Voltage"
    id: "battery_voltage"
    update_interval: 1s
    filters:
      multiply: 2.0

  - platform: template
    name: "Battery Percentage"
    device_class: "battery"
    id: "battery_percentage"
    accuracy_decimals: 1
    update_interval: 1s
    unit_of_measurement: '%'
    lambda: |-
      return ((id(battery_voltage).state - 3.5) / 0.7 * 100.00);
    filters:
      - lambda: |-
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);
    
  - platform: adc
    pin: A0
    id: moisture_sensor
    name: "Soil Moisture %"
    unit_of_measurement: "%"
    update_interval: 1s
    accuracy_decimals: 0
    attenuation: auto
    filters:
      - calibrate_linear:
        - 1.80 -> 0.0
        - 1.35 -> 25.0
        - 1.00 -> 50.0
        - 0.85 -> 100.0
      - lambda: |-
          if (x < 0) return 0; 
          else if (x > 100) return 100;
          else return (x);

deep_sleep:
  id: deep_sleep_1
  run_duration: 1s
  sleep_duration: 1440min # One day
  
mqtt:
  broker: 192.168.1.115
  topic_prefix: "home/kitchen/plant-monitor"
  will_message:
  birth_message:
  on_message:
    - topic: home/kitchen/plant-monitor/ota_mode
      payload: 'ON'
      then:
        - deep_sleep.prevent: deep_sleep_1
    - topic: home/kitchen/plant-monitor/ota_mode
      payload: 'OFF'
      then:
        - deep_sleep.allow: deep_sleep_1

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: 192.168.1.239
  fast_connect: true

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "SSID"
    password: "PASS"

captive_portal:
    

Let me know if you have any questions or suggestions for future projects, I do have another plant that I’m going to hook up with another one of these but will use what I’ve learnt this time to hopefully make it a smoother process!

Happy DIYing!

5 Likes

How did you reflect the readings of the sensors in the main page of HA lovelace ?

Hey @VizuaaLOG, this is a nice project but I am really struggling with one thing. Since I got this FireBeetle 2 ESP32-E device I am having a hard time getting proper battery readings from it.

Did you have any issues with that? Here is what I see, I have even tried PIO directly.

[12:08:48][D][sensor:094]: 'Battery Voltage': Sending state 0.28400 V with 2 decimals of accuracy
[12:08:48][D][sensor:094]: 'Battery Percentage': Sending state 0.00000 % with 1 decimals of accuracy

I have tried three new batteries I purchased for this purpose.

Any help would be appreciated. Thanks!

Apologies I must have missed the notification for your message.

I used MQTT to transfer the data to HA. Then just used normal entity/tile cards to display the data, some automation to notify me etc nothing too fancy.

I don’t remember having any issues the config I used above provided a reading that I would expect.

Only things that come to mind is if the pin is correct depending on if you’re using the inboard battery connector or using another pin on the board?