Outstanding configuration. Thanks for sharing.
I’ve made a few changes to it so that the moisture sensor can be manually calibrated.
(By placing the sensor in a glass of clean water, writing down the voltage and replacing the “calibration_hundread_perc_voltage” value. Repeat the same step, drying up the sensor unit and noting down the relevant value on “calibration_zero_perc_voltage” in the calibration section).
I’ve added a raw voltage HA sensor to help with the process.
To anyone interested in this config, keep in mind that my unit only has a BME280 so I’ve modified the config accordingly.
EDIT: forgot to mention that I’ve got rid of MQTT support in favor of direct HA api. Got better results
Cheers,
Simon
substitutions:
devicename: "plant_sensor_1"
upper_devicename: Plant Sensor 1
run_duration: 12s # set how long to stay awake - NOT less then 10sec
sleep_duration: 60min # set how long to sleep in minutes
update_interval: 5s
# IPs
fixed_ip: 10.10.10.118
gateway_ip: 10.10.10.1
subnet_mask: 255.255.255.0
# Calibration
calibration_zero_perc_voltage: "2.87"
calibration_hundread_perc_voltage: "1.37"
###############################################################################################
esphome:
name: "${devicename}"
platform: ESP32
board: esp32dev
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: enable
manual_ip:
static_ip: ${fixed_ip}
gateway: ${gateway_ip}
subnet: ${subnet_mask}
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${devicename}"
password: !secret wifi_fallback_password
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: !secret ota_password
# Deep Sleep
deep_sleep:
id: deep_sleep_control
run_duration: ${run_duration}
sleep_duration: ${sleep_duration}
##time:
## - platform: homeassistant
## id: esptime
i2c:
- id: bus_a
sda: GPIO25
scl: GPIO26
scan: true
setup_priority: -200
- id: bus_b
sda: GPIO21
scl: GPIO22
scan: true
setup_priority: -200
switch:
# Update Mode
- platform: template
name: "update mode ${upper_devicename}"
id: "${devicename}_update_mode"
icon: "mdi:alarm-light"
optimistic: true
# internal: true
turn_on_action:
- deep_sleep.prevent: deep_sleep_control
turn_off_action:
if:
condition:
and:
- switch.is_off: ${devicename}_pumpe
then:
- delay: ${run_duration}
- deep_sleep.enter: deep_sleep_control
# Watering pump
- platform: template
name: "Pumpe ${upper_devicename}"
id: "${devicename}_pumpe"
icon: "mdi:water-pump"
optimistic: true
turn_on_action:
- deep_sleep.prevent: deep_sleep_control
turn_off_action:
if:
condition:
and:
- switch.is_off: ${devicename}_update_mode
then:
- delay: ${run_duration}
- deep_sleep.enter: deep_sleep_control
# Power Switch
- platform: gpio
name: "${upper_devicename} Sensor Power"
pin: 4
id: spower
restore_mode: ALWAYS_ON
internal: true
setup_priority: 1000
# Wake Button
binary_sensor:
- platform: gpio
name: "${upper_devicename} Wake Button"
pin: 35
internal: true
setup_priority: 1000
# Wifi Signal
sensor:
- platform: wifi_signal
name: "WiFi Signal Sensor"
update_interval: ${update_interval}
# Temperature and humidity
# BME280 Sensor
- platform: bme280
i2c_id: bus_a
temperature:
name: "${upper_devicename} Temperature"
oversampling: 16x
unit_of_measurement: "°C"
icon: "mdi:thermometer"
device_class: "temperature"
state_class: "measurement"
accuracy_decimals: 1
pressure:
name: "${upper_devicename} Pressure"
unit_of_measurement: "mbar"
icon: "mdi:gauge"
device_class: "pressure"
state_class: "measurement"
humidity:
name: "${upper_devicename} Humidity"
unit_of_measurement: "%"
icon: "mdi:cloud-percent"
device_class: "humidity"
state_class: "measurement"
address: 0x77
setup_priority: -300
update_interval: ${update_interval}
# Soil humidity %
- platform: adc
pin: 32
name: "${upper_devicename} Soil Moisture"
id: "${devicename}_moisture"
icon: "mdi:watering-can"
attenuation: 11db
# unit_of_measurement: 'V' # uncomment for raw data
unit_of_measurement: '%' # comment for raw data
filters: # comment for raw data
- calibrate_linear: # comment for raw data
# Map 0.0 (from sensor) to 0.0 (true value)
- ${calibration_zero_perc_voltage} -> 0.0 # comment for raw data
- ${calibration_hundread_perc_voltage} -> 100.0 # comment for raw data
update_interval: ${update_interval}
# Soil humidity V %
- platform: adc
pin: 32
name: "${upper_devicename} Soil Moisture Voltage"
id: "${devicename}_moisture_voltage"
icon: "mdi:watering-can"
attenuation: 11db
unit_of_measurement: 'V' # uncomment for raw data
update_interval: ${update_interval}
# Fertilizer sensor
- platform: adc
pin: 34
name: "${upper_devicename} Salt"
id: "${devicename}_salt"
icon: "mdi:flower"
unit_of_measurement: '%'
accuracy_decimals: 4
filters:
- calibrate_linear:
# Map 0.0 (from sensor) to 0.0 (true value)
- 0.0 -> 0.0
- 1.1 -> 100.0
# - sliding_window_moving_average:
# window_size: 15
# send_every: 15
update_interval: ${update_interval}
# Lux sensor
- platform: bh1750
i2c_id: bus_a
name: "${upper_devicename} Illuminance"
id: "${devicename}_lux"
address: 0x23
unit_of_measurement: "lx"
icon: "mdi:white-balance-sunny"
device_class: "illuminance"
state_class: "measurement"
setup_priority: -300
update_interval: ${update_interval}
# Battery
- platform: adc
pin: 33
name: "${upper_devicename} Battery"
id: "${devicename}_voltage"
attenuation: 11db
unit_of_measurement: "V"
icon: "mdi:battery-high"
device_class: "voltage"
state_class: "measurement"
accuracy_decimals: 3
filters:
- multiply: 2
- calibrate_linear:
# Map 0.0 (from sensor) to 0.0 (true value)
- 0.0 -> 0.0
- 4.0 -> 4.0
# - sliding_window_moving_average:
# window_size: 10
# send_every: 10
update_interval: ${update_interval}
# Battery %
- platform: adc
pin: 33
name: "${upper_devicename} Battery %"
id: "${devicename}_percent"
attenuation: 11db
unit_of_measurement: '%'
filters:
- multiply: 2
- calibrate_linear:
# Map 0.0 (from sensor) to 0.0 (true value)
- 3.18 -> 0.0
- 4.20 -> 100.0
# - lambda: |-
# return ((id(${devicename}_voltage).state - 2.76) / 0.379 * 100.00);
# (current - minimum) / difference between max & min * 100
update_interval: ${update_interval}
# Soil Moisture Pump Control (a climate bang bang to control the pump)
climate:
- platform: bang_bang
visual:
min_temperature: 0
max_temperature: 100
temperature_step: 1
name: ${upper_devicename} Regler
sensor: ${devicename}_moisture
default_target_temperature_low: 20
default_target_temperature_high: 70
heat_action:
- switch.turn_on: ${devicename}_pumpe
idle_action:
- switch.turn_off: ${devicename}_pumpe