ESP8266 in combination with a eight port multiplexer to support up to 8 capacitive soil moisture sensors.
The esp8266 reads the sensors every 10 minutes, transfers the readings via MQTT to a broker and goes back to deep sleep. The MQTT messages and can be picked up by i.e. Home Assistant.
- Mode 1: USB powered
- Mode 2: Battery powered (optional solar)
The code is written in MicroPython.
- Wemos D1 mini Pro V2.0.0 ESP8266 4,56€
- Capacitive soil moisture sensor 0,61€
- CD4051 Multiplexer 1,85€
- Project box 0,72€
- Circuit board 1,66€
- Wires 1,90€
- Pin headers 0,88€
- 3D printed sensor case (order print at treatstock) ~1,20€
A usb charger and micro usb cable is assumed to be available.
Use more batteries in parallel if you want (a) to decrease the time between sensor readings or (b) prolong the time until the next charging cycle or (c) compensate for smaller solar panels.
The solar panel is optional, of course you can also charge the batteries manually with a charger once they are drained. If you use a solar panel, you need to connect it via the micro usb port to the esp8266
Note: the Wemos D1 mini Pro v2.0.0 already has a built-in charging module.
- 18650 3,7V 3400mAh battery 2,21€
- JST connector 0,49€
- Optinal 5V 5W solar panel 4,13€
Use the config.json
to configure the esp8266 (no changes in boot.py
or main.py
required).
{
"hostname": "NAME_OF_ESP8266",
"wifi": {
"ssid": "YOUR_WIFI_NAME",
"password": "YOUR_WIFI_PASSWORD",
},
"mqtt": {
"user": "MQTT_USER",
"password": "MQTT_PASSWORD",
"broker": "MQTT_BROKER_IP",
"port": 1883,
"topics": "TOPIC_NAME"
}
}
I prefer PyCharm and the respective MicroPython plugin. Nevertheless, you can use any other suitable editor.
Create a configuration for each of the three files and flash them onto the esp8266. You can use the MicroPython REPL to watch the execution of the programs:
Connecting to WiFi...connected
Connecting to MQTT...connected
Sending: {"analog": "481", "percent": "7", "updated": "07.02.2020 23:12:25"}
Going back to sleep...
Add i.e. two mqtt sensors to your sensors.yaml
(your one esp8266 published to both topics as it operates multiple soil moisture sensors)
- platform: mqtt
name: "Ficus Benjamina"
state_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor0"
value_template: "{{ value_json.percent }}"
unit_of_measurement: "%"
json_attributes_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor0"
icon: mdi:leaf
- platform: mqtt
name: "Zitronenbaum"
state_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor1"
value_template: "{{ value_json.percent }}"
unit_of_measurement: "%"
json_attributes_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor1"
icon: mdi:fruit-citrus
- platform: mqtt
name: "Balsamapfel"
state_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor2"
value_template: "{{ value_json.percent }}"
unit_of_measurement: "%"
json_attributes_topic: "esp8266/pflanzen-wohnzimmer-fenster/sensor2"
icon: mdi:sprout
And the following to ui-lovelace.yaml
to display the two sensors in the lovelace frontend (Custom multiple entities card is used in this example)
- type: markdown
style: !include /config/ui-lovelace/style/title.yaml
content: Pflanzen
- type: entities
entities:
- type: custom:multiple-entity-row
entity: sensor.ficus_benjamina
hide_state: true
primary:
entity: sensor.ficus_benjamina
attribute: analog
unit: ''
name: 'Analog'
secondary:
entity: sensor.ficus_benjamina
attribute: percent
name: 'Wasser'
unit: '%'
- entity: sensor.zitronenbaum
hide_state: true
type: custom:multiple-entity-row
primary:
entity: sensor.zitronenbaum
attribute: analog
unit: ''
name: 'Analog'
secondary:
entity: sensor.zitronenbaum
attribute: percent
unit: '%'
name: 'Wasser'
- entity: sensor.balsamapfel
hide_state: true
type: custom:multiple-entity-row
primary:
entity: sensor.balsamapfel
attribute: analog
unit: ''
name: 'Analog'
secondary:
entity: sensor.balsamapfel
attribute: percent
unit: '%'
name: 'Wasser'
Result in lovelace frontend:
Detail view:
Two sensors placed in a plant each
Indoor case (source)
Outdoor case with top cover (source)
Three sensors connected to the esp (3 more available - multiplexer supports up to 8)
Front view of the connectors (the wholes could have been drilled better)
VCC and GND JST connectors glued in place
6 analog pins (multiplexer channels) for 6 soil moisture sensors glued in place
Mode 1 completed without case and ability to connect 4 moisture sensors (2 more have been added after taking the picture)
Sleep pin soldered to be able to wake up from deep sleep
Wiring below esp8266 (not all connections are visible from the top)
Back with soldered connections
Multiplexer wired to headers for esp8266 without connectors for sensors
Back of esp8266 and multiplexer wiring