I have built a sensor with the distance meter and the state of the battery.
The sensor should read the values of the battery and the distance, then it should go to sleep.
After the start, the values are read out, but it does not go into deep sleep mode. However, if I set sleep_mode to ON via mqtt, then it goes into deep_sleep, but not again after waking up.
ota_mode is set to OFF.
RST is set to D0 with R220.
A0 is connected to B+ via 100kOhm.
esphome:
name: regentonne
platform: ESP8266
board: d1_mini
# Enable logging
logger:
level: DEBUG
# Enable Home Assistant API
mqtt:
broker: !secret mqtt_url
username: !secret mqtt_user
password: !secret mqtt_pass
discovery: True
discovery_retain: True
birth_message:
will_message:
topic_prefix: 'regentonne'
on_message:
- topic: esp/ota_mode
payload: 'ON'
then:
- deep_sleep.prevent: deep_sleep_control
- topic: esp/sleep_mode
payload: 'ON'
then:
- deep_sleep.enter: deep_sleep_control
ota:
password: "123456"
wifi:
ssid: "xxxxxxxxxxx"
password: "xxxxxxxx"
fast_connect: True
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Regentonne Fallback Hotspot"
password: "xxxxxxxxxxx"
captive_portal:
i2c:
sda: D3
scl: D2
scan: True
sensor:
- platform: adc
pin: A0
id: "a0_pin"
name: "Regentonne VCC Voltage"
internal: true
accuracy_decimals: 3
filters:
- multiply: 4.2
- platform: template
name: "Regentonne_Battery_Voltage"
unit_of_measurement: 'V'
update_interval: 5s
accuracy_decimals: 2
lambda: |-
return (id(a0_pin).state);
- platform: template
name: "Regentonne_Battery_Percentage"
unit_of_measurement: '%'
update_interval: 5s
accuracy_decimals: 0
lambda: |-
return ((id(a0_pin).state-3) /1.2 * 100.00);
- platform: vl53l0x
name: Regentonne Distance
address: 0x29
id: regentonne_distance
timeout: 200us
enable_pin: D6
update_interval: 1s
unit_of_measurement: "m"
#on_value:
# then:
# deep_sleep.enter: deep_sleep_control
deep_sleep:
id: deep_sleep_control
run_duration: 5s
sleep_duration: 60s
Log:
[11:31:36][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.051 m
[11:31:36][D][sensor:113]: 'Regentonne Distance': Sending state 0.05100 m with 2 decimals of accuracy
[11:31:37][I][deep_sleep:072]: Beginning Deep Sleep
[11:32:37][I][mqtt:214]: MQTT Connected!
[11:32:38][C][deep_sleep:017]: Setting up Deep Sleep...
[11:32:38][I][app:060]: setup() finished successfully!
[11:32:38][I][app:099]: ESPHome version 2021.10.1 compiled on Oct 22 2021, 11:01:19
[11:32:38][C][wifi:490]: WiFi:
[11:32:38][C][wifi:352]: Local MAC: C4:5B:BE:54:B4:B1
[11:32:38][C][wifi:353]: SSID: [redacted]
[11:32:38][C][wifi:354]: IP Address: 192.168.1.217
[11:32:38][C][wifi:356]: BSSID: [redacted]
[11:32:38][C][wifi:357]: Hostname: 'regentonne'
[11:32:38][C][wifi:359]: Signal strength: -53 dB ▂▄▆█
[11:32:38][C][wifi:363]: Channel: 1
[11:32:38][C][wifi:364]: Subnet: 255.255.255.0
[11:32:38][C][wifi:365]: Gateway: 192.168.1.1
[11:32:38][C][wifi:366]: DNS1: 192.168.1.50
[11:32:38][C][wifi:367]: DNS2: 192.168.1.100
[11:32:38][C][i2c.arduino:032]: I2C Bus:
[11:32:38][C][i2c.arduino:033]: SDA Pin: GPIO0
[11:32:38][C][i2c.arduino:034]: SCL Pin: GPIO4
[11:32:38][C][i2c.arduino:035]: Frequency: 50000 Hz
[11:32:38][C][i2c.arduino:038]: Recovery: bus successfully recovered
[11:32:38][I][i2c.arduino:048]: Scanning i2c bus for active devices...
[11:32:38][I][i2c.arduino:053]: Found i2c device at address 0x29
[11:32:38][C][template.sensor:023]: Template Sensor 'Regentonne_Battery_Voltage'
[11:32:38][C][template.sensor:023]: State Class: ''
[11:32:38][C][template.sensor:023]: Unit of Measurement: 'V'
[11:32:38][C][template.sensor:023]: Accuracy Decimals: 2
[11:32:38][C][template.sensor:024]: Update Interval: 5.0s
[11:32:38][C][template.sensor:023]: Template Sensor 'Regentonne_Battery_Percentage'
[11:32:38][C][template.sensor:023]: State Class: ''
[11:32:38][C][template.sensor:023]: Unit of Measurement: '%'
[11:32:38][C][template.sensor:023]: Accuracy Decimals: 0
[11:32:38][C][template.sensor:024]: Update Interval: 5.0s
[11:32:38][C][logger:233]: Logger:
[11:32:38][C][logger:234]: Level: DEBUG
[11:32:38][C][logger:235]: Log Baud Rate: 115200
[11:32:38][C][logger:236]: Hardware UART: UART0
[11:32:38][C][adc:077]: ADC Sensor 'Regentonne VCC Voltage'
[11:32:38][C][adc:077]: Device Class: 'voltage'
[11:32:38][C][adc:077]: State Class: 'measurement'
[11:32:38][C][adc:077]: Unit of Measurement: 'V'
[11:32:38][C][adc:077]: Accuracy Decimals: 3
[11:32:38][C][adc:082]: Pin: GPIO17
[11:32:38][C][adc:104]: Update Interval: 60.0s
[11:32:38][C][vl53l0x:024]: VL53L0X 'Regentonne Distance'
[11:32:38][C][vl53l0x:024]: State Class: 'measurement'
[11:32:38][C][vl53l0x:024]: Unit of Measurement: 'm'
[11:32:38][C][vl53l0x:024]: Accuracy Decimals: 2
[11:32:38][C][vl53l0x:024]: Icon: 'mdi:arrow-expand-vertical'
[11:32:38][C][vl53l0x:025]: Update Interval: 1.0s
[11:32:38][C][vl53l0x:026]: Address: 0x29
[11:32:38][C][vl53l0x:028]: Enable Pin: GPIO12
[11:32:38][C][vl53l0x:030]: Timeout: 200us
[11:32:38][C][captive_portal:150]: Captive Portal:
[11:32:38][C][ota:082]: Over-The-Air Updates:
[11:32:38][C][ota:083]: Address: regentonne.local:8266
[11:32:38][C][ota:086]: Using Password.
[11:32:38][C][mqtt:063]: MQTT:
[11:32:38][C][mqtt:065]: Server Address: 192.168.1.50:1883 (192.168.1.50)
[11:32:38][C][mqtt:066]: Username: [redacted]
[11:32:38][C][mqtt:067]: Client ID: [redacted]
[11:32:38][C][mqtt:069]: Discovery prefix: 'homeassistant'
[11:32:38][C][mqtt:070]: Discovery retain: YES
[11:32:38][C][mqtt:072]: Topic Prefix: 'regentonne'
[11:32:38][C][mqtt:074]: Log Topic: 'regentonne/debug'
[11:32:38][C][mqtt:584]: MQTT Message Trigger:
[11:32:38][C][mqtt:585]: Topic: 'esp/ota_mode'
[11:32:38][C][mqtt:586]: QoS: 0
[11:32:38][C][mqtt.sensor:025]: MQTT Sensor 'Regentonne_Battery_Voltage':
[11:32:38][C][mqtt.sensor:029]: State Topic: 'regentonne/sensor/regentonne_battery_voltage/state'
[11:32:38][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.051 m
[11:32:38][D][sensor:113]: 'Regentonne Distance': Sending state 0.05100 m with 2 decimals of accuracy
[11:32:38][C][mqtt.sensor:025]: MQTT Sensor 'Regentonne_Battery_Percentage':
[11:32:38][C][mqtt.sensor:029]: State Topic: 'regentonne/sensor/regentonne_battery_percentage/state'
[11:32:38][C][mqtt.sensor:025]: MQTT Sensor 'Regentonne Distance':
[11:32:38][C][mqtt.sensor:029]: State Topic: 'regentonne/sensor/regentonne_distance/state'
[11:32:38][C][mqtt:584]: MQTT Message Trigger:
[11:32:38][C][mqtt:585]: Topic: 'esp/sleep_mode'
[11:32:38][C][mqtt:586]: QoS: 0
[11:32:38][C][deep_sleep:024]: Setting up Deep Sleep...
[11:32:38][C][deep_sleep:027]: Sleep Duration: 60000 ms
[11:32:38][C][deep_sleep:030]: Run Duration: 5000 ms
[11:32:39][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.050 m
[11:32:39][D][sensor:113]: 'Regentonne Distance': Sending state 0.05000 m with 2 decimals of accuracy
[11:32:40][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.051 m
[11:32:40][D][sensor:113]: 'Regentonne Distance': Sending state 0.05100 m with 2 decimals of accuracy
[11:32:41][D][sensor:113]: 'Regentonne_Battery_Voltage': Sending state 4.08926 V with 2 decimals of accuracy
[11:32:41][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.051 m
[11:32:41][D][sensor:113]: 'Regentonne Distance': Sending state 0.05100 m with 2 decimals of accuracy
[11:32:41][D][sensor:113]: 'Regentonne_Battery_Percentage': Sending state 90.77148 % with 0 decimals of accuracy
[11:32:42][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.050 m
[11:32:42][D][sensor:113]: 'Regentonne Distance': Sending state 0.05000 m with 2 decimals of accuracy
[11:32:43][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.049 m
[11:32:43][D][sensor:113]: 'Regentonne Distance': Sending state 0.04900 m with 2 decimals of accuracy
[11:32:44][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.049 m
[11:32:44][D][sensor:113]: 'Regentonne Distance': Sending state 0.04900 m with 2 decimals of accuracy
[11:32:45][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.049 m
[11:32:45][D][sensor:113]: 'Regentonne Distance': Sending state 0.04900 m with 2 decimals of accuracy
[11:32:46][D][sensor:113]: 'Regentonne_Battery_Voltage': Sending state 4.08926 V with 2 decimals of accuracy
[11:32:46][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.051 m
[11:32:46][D][sensor:113]: 'Regentonne Distance': Sending state 0.05100 m with 2 decimals of accuracy
[11:32:46][D][sensor:113]: 'Regentonne_Battery_Percentage': Sending state 90.77148 % with 0 decimals of accuracy
[11:32:47][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.048 m
[11:32:47][D][sensor:113]: 'Regentonne Distance': Sending state 0.04800 m with 2 decimals of accuracy
[11:32:48][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.051 m
[11:32:48][D][sensor:113]: 'Regentonne Distance': Sending state 0.05100 m with 2 decimals of accuracy
[11:32:49][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.050 m
[11:32:49][D][sensor:113]: 'Regentonne Distance': Sending state 0.05000 m with 2 decimals of accuracy
[11:32:50][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.050 m
[11:32:50][D][sensor:113]: 'Regentonne Distance': Sending state 0.05000 m with 2 decimals of accuracy
[11:32:51][D][sensor:113]: 'Regentonne_Battery_Voltage': Sending state 4.08926 V with 2 decimals of accuracy
[11:32:51][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.050 m
[11:32:51][D][sensor:113]: 'Regentonne Distance': Sending state 0.05000 m with 2 decimals of accuracy
[11:32:51][D][sensor:113]: 'Regentonne_Battery_Percentage': Sending state 90.77148 % with 0 decimals of accuracy
[11:32:52][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.049 m
[11:32:52][D][sensor:113]: 'Regentonne Distance': Sending state 0.04900 m with 2 decimals of accuracy
[11:32:53][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.050 m
[11:32:53][D][sensor:113]: 'Regentonne Distance': Sending state 0.05000 m with 2 decimals of accuracy
[11:32:54][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.048 m
[11:32:54][D][sensor:113]: 'Regentonne Distance': Sending state 0.04800 m with 2 decimals of accuracy
[11:32:55][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.050 m
[11:32:55][D][sensor:113]: 'Regentonne Distance': Sending state 0.05000 m with 2 decimals of accuracy
[11:32:56][D][sensor:113]: 'Regentonne_Battery_Voltage': Sending state 4.08926 V with 2 decimals of accuracy
[11:32:56][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.049 m
[11:32:56][D][sensor:113]: 'Regentonne Distance': Sending state 0.04900 m with 2 decimals of accuracy
[11:32:56][D][sensor:113]: 'Regentonne_Battery_Percentage': Sending state 90.77148 % with 0 decimals of accuracy
[11:32:57][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.049 m
[11:32:57][D][sensor:113]: 'Regentonne Distance': Sending state 0.04900 m with 2 decimals of accuracy
[11:32:58][D][vl53l0x:307]: 'Regentonne Distance' - Got distance 0.051 m