I have a ESP32 with a switch connected to pin 13. Since the device is battery powered, I want it to stay in deep sleep, unless the switch is toggled. When that happens, I want it to send the switch status and the status (state of charge) of the battery.
When I don’t add deep sleep, everything works well with this config:
esphome:
name: test
includes:
- BQ27441.h
libraries:
- Wire
- "SparkFun BQ27441 LiPo Fuel Gauge Arduino Library"
sensor:
- platform: custom
lambda: |-
auto BQ27441 = new Dyli_BQ27441();
App.register_component(BQ27441);
return {BQ27441};
sensors:
name: "battery level"
binary_sensor:
- platform: gpio
pin: 13
name: "switch status"
device_class: window
esp32:
board: esp32dev
framework:
type: arduino
When I add deep sleep configuration like this:
esphome:
name: test
includes:
- BQ27441.h
libraries:
- Wire
- "SparkFun BQ27441 LiPo Fuel Gauge Arduino Library"
on_boot:
then:
- deep_sleep.enter
sensor:
- platform: custom
lambda: |-
auto BQ27441 = new my_BQ27441();
App.register_component(BQ27441);
return {BQ27441};
sensors:
name: "battery status"
deep_sleep:
wakeup_pin: 13
wakeup_pin_mode: INVERT_WAKEUP
binary_sensor:
- platform: gpio
pin: 13
name: "switch status"
device_class: window
esp32:
board: esp32dev
framework:
type: arduino
I see in the log that the device goes into deep sleep:
[I][app:029]: Running through setup()...
[I][i2c.arduino:161]: Performing I2C bus recovery
Connected to BQ27441!
[D][binary_sensor:034]: 'Switch status': Sending initial state OFF
[I][deep_sleep:116]: Beginning Deep Sleep
When I toggle the switch, I also see it waking up and logging that it is sending the switch state:
[I][logger:243]: Log initialized
[C][ota:465]: There have been 0 suspected unsuccessful boot attempts.
[D][esp32.preferences:113]: Saving 1 preferences to flash...
[D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[I][app:029]: Running through setup()...
[I][i2c.arduino:161]: Performing I2C bus recovery
Connected to BQ27441!
[D][binary_sensor:034]: 'Switchstatus': Sending initial state ON
[I][deep_sleep:116]: Beginning Deep Sleep
The status change is however not visible in HA. Any idea what I should change to fix that?
I also couldn’t really figure out how to send the battery status before it’s going into deep sleep again, any ideas?