Hi there,
i hope there is someone who can point me into the right direction.
Following situation:
I have programmed an ESP32 to do some basic measures for a tank level.
To run it on battery, i need to put it on deep sleep between the measurements.
I also created a prevent from sleep with MQTT.
This works good so far, i upload the code, measurements are done, i put it to deep sleep, device comes back, but doesn’t update any measurements and goes to deep sleep again.
Here is my code:
sensor:
- platform: uptime
name: "Uptime"
- platform: adc
pin: GPIO34
name: "Spannung"
id: voltage_sensor
update_interval: 1s
# accuracy_decimals: 3
attenuation: 12db
internal: false
samples: 10
filters:
- multiply : 1000
- platform : template
name : "Tanklevel"
id: id_tanklevel
unit_of_measurement : "%"
accuracy_decimals : 0
update_interval : 5s
lambda: |-
if (id(voltage_sensor).state >= 3110){
return 100;
} else if (id(voltage_sensor).state <= 150) {
return 0;
} else {
return (((id(voltage_sensor).state) - 150)*100) / (3110-150);
}
# Tank leer = xx,yy V 0,150 -> 150
# Tank voll = xx,yy V. 3,113 -> 3113
mqtt:
broker: 192.168.1.200
username: !secret mqtt_user
password: !secret mqtt_password
on_message:
- topic: tank/prevent.sleep
payload: 'on'
then:
- deep_sleep.prevent: deep_sleep_1
- topic: tank/prevent.sleep
payload: 'off'
then:
- deep_sleep.allow: deep_sleep_1
- deep_sleep.enter: deep_sleep_1
deep_sleep:
id: deep_sleep_1
run_duration: 30s
sleep_duration: 1min
this is what i get in the log:
[08:55:02][D][api:133]: Accepted 192.168.1.200
[08:55:02][D][api.connection:1570]: Home Assistant 2025.6.1 (192.168.1.200) connected
[08:55:02][D][sensor:098]: ‘Tanklevel’: Sending state 100.00000 % with 0 decimals of accuracy
[08:55:02][D][sensor:098]: ‘Spannung’: Sending state 3113.00000 V with 2 decimals of accuracy
[08:55:03][D][sensor:098]: ‘Spannung’: Sending state 3113.00000 V with 2 decimals of accuracy
[08:55:04][D][sensor:098]: ‘Spannung’: Sending state 3113.00000 V with 2 decimals of accuracy
[08:55:05][D][sensor:098]: ‘Spannung’: Sending state 3113.00000 V with 2 decimals of accuracy
[08:55:06][D][sensor:098]: ‘Spannung’: Sending state 3113.00000 V with 2 decimals of accuracy
[08:55:07][D][sensor:098]: ‘Tanklevel’: Sending state 100.00000 % with 0 decimals of accuracy
[08:55:07][D][sensor:098]: ‘Spannung’: Sending state 3113.00000 V with 2 decimals of accuracy
[08:55:08][I][deep_sleep:062]: Beginning sleep
[08:55:08][I][deep_sleep:064]: Sleeping for 60000000us
[08:55:08][D][esp32.preferences:142]: Writing 1 items: 0 cached, 1 written, 0 failed
[08:55:08][D][esp-idf:000]: I (12107) mqtt_client: Client asked to disconnect
INFO Processing expected disconnect from ESPHome API for wassertank-bug @ 192.168.1.51
WARNING Disconnected from API
INFO Successfully resolved wassertank-bug @ 192.168.1.51 in 0.000s
WARNING Can’t connect to ESPHome API for wassertank-bug @ 192.168.1.51: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address=‘192.168.1.51’, port=6053))]: [Errno 113] Connect call failed (‘192.168.1.51’, 6053) (SocketAPIError)
INFO Trying to connect to wassertank-bug @ 192.168.1.51 in the background
INFO Successfully resolved wassertank-bug @ 192.168.1.51 in 0.000s
INFO Successfully resolved wassertank-bug @ 192.168.1.51 in 0.000s
INFO Successfully resolved wassertank-bug @ 192.168.1.51 in 0.000s
INFO Successfully resolved wassertank-bug @ 192.168.1.51 in 0.000s