After my first positive experiences with ESPhome, I had a closer look into the documentation and found out that deepsleep is also implemented.
I had some soil moisture sensors connected to an ESP8266 to detect if irrigation is necessary. The device is powered by an 18650 cell. It wakes up every 30 mins, switches on the power to the sensor, reads the sensor, sends the measured value via MQTT and goes back to deep sleep. It was not too difficult to implement it in ESPhome:
esphome:
name: eh-bodenfeuchte3
on_boot:
- switch.turn_on: Sensor_Vcc
- delay: 1s
# Terrassensensor
esp8266:
board: huzzah
# Enable logging
logger:
# Enable Home Assistant API
api:
password: ""
ota:
- platform: esphome
password: ""
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Eh-Bodenfeuchte3"
password: "EfGXNoIANTV5"
captive_portal:
deep_sleep:
run_duration: 12s
sleep_duration: 30min
id: ds
switch:
- platform: gpio
pin: GPIO14 #D5
id: Sensor_Vcc
binary_sensor:
- platform: homeassistant
id: no_deep_sleep
entity_id: input_boolean.no_deep_sleep
mqtt:
broker: 192.168.2.204
discovery: false
discover_ip: false
sensor:
- platform: wifi_signal
name: "WiFi Signal Sensor"
update_interval: 10s
- platform: adc
pin: A0
name: Terrassenfeuchte
samples: 10
update_interval: 8s
id: terrassenfeuchte
filters:
- multiply: 1000
on_value:
- mqtt.publish:
topic: "ESP/H2O/Sensor3"
payload: !lambda |-
return to_string(int(1*id(terrassenfeuchte).state));
retain: true
- if:
condition:
binary_sensor.is_on: no_deep_sleep
then:
- deep_sleep.prevent: ds
# - logger.log: "No sleep!"
else:
- deep_sleep.allow: ds
# - logger.log: "Let's snooze!"
Each time it wakes up, the **on_boot**-section is carried out. There I switch on the voltage for the sensor. As it does not draw much current, I power it directly from a GPIO.
The implementation in ESPhome allowed me even to add a switch to HA to prevent the device from going to deep sleep again after the next time it wakes up again. This allows easily flashing OTA without opening the waterproof housing. A feature which I did not have before.
I put the device into the soil in April and remove it at the end of October. I charge the cell at the beginning of August to be sure that it lasts. That's good enough for me.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.