Hello,
I am an ESPHome-User since about a month or so. I built 5 USB-powered devices with ESP32 successfully, also with BH1750. No problems so far.
A week ago I started with a battery powered version of ESP32 with a single Dallas temp sensor and a BH1750. I quickly noticed the high battery consumption when I do not switch both sensors OFF before deep sleep (I use 3xAAA NiMH with an LDO voltage regulator directly powering the ESP via 3.3V, without the transistor I get 2.25d of runtime. However, it does not matter if the ESP32 sleeps for 30min or 1h. Thus, I concluded that something else must be eating current. I was not able to measure the current, with my amperemeter connected the ESP32 would not turn on).
So, now I am using a P-channel IRF9Z34N mosfet in high side configuration (see Low side vs. High side transistor switch - Bald Engineer ) to switch both sensors on and off (logic therefore is inverted, GPIO low switching mosfet on and vice cersa). Yes, this mosfet is an overkill power-wise, but it works (a larger mosfet is also easier to solder ).
Here comes the strange part: when I do an OTA, the BH1750 and the Dallas work as intended. Then I switch off the Dallas and the BH1750. The ESP32 goes to deep sleep shortly after. When it wakes up again, the mosfet switches both sensors on, I get a ‘Communication with BH1750 failed’ message. The I2C scan also fails (every address is red, so no I2C device is recognized). The Dallas works as intended. I do not get any values from the BH1750. I tried connecting ADDR pin of BH1750, it does not matter. Without the mosfet, this does not occur. Thus, the switching off via mosfet is the reason for this problem.
So here is my current yaml:
esphome:
name: esphome--6
on_boot:
then:
#- delay: 2s
- switch.turn_off: mosfet_switch
#wake_up command BH1750, how to implement??
- delay: 53s # 180 - 10
- switch.turn_on: mosfet_switch
- delay: 2s
- deep_sleep.enter: deep_sleep_1
esp32:
board: esp32dev
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "XXXXXXXXXXXXXXXXX"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true
output_power: 12dB
manual_ip:
static_ip: 192.168.178.156
gateway: 192.168.178.10
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esphome--6 Fallback Hotspot"
password: "XXXXXXXXXX"
captive_portal:
deep_sleep:
run_duration: 60s
sleep_duration: 840s
id: deep_sleep_1
i2c:
sda: 21
scl: 22
scan: true #false does not solve BH1750 problem
id: bus_a
dallas:
- pin: 5
update_interval: 22s
sensor:
- platform: dallas
address: 0xe300000bfd37a328
name: "Mobil_1 ESP Dallas Onboard Temperature"
accuracy_decimals: 2
- platform: uptime
name: "Mobil_1 ESP Uptime"
update_interval: 40s
filters:
- lambda: return x / 3600;
unit_of_measurement: "h"
accuracy_decimals: 3
- platform: wifi_signal
name: "Mobil_1 ESP WiFi Signal"
update_interval: 45s
accuracy_decimals: 1
- platform: adc
pin: 34
name: "Mobil_1 ESP Battery Voltage"
attenuation: 11dB
update_interval: 24s
filters:
multiply: 1.4545 #voltage divider
- platform: bh1750
name: "Mobil_1 ESP BH Illuminance"
address: 0x23
id: light_sensor
update_interval: 45s
setup_priority: -100.0 #does not solve the BH1750 problem
button:
- platform: restart
name: "Mobil_1 Restart"
id: restart_button
disabled_by_default: true
on_press:
then:
- logger.log: Button Pressed
switch:
- platform: gpio
pin: 13
name: "Mosfet Switch" #logic inverted!
id: mosfet_switch
on_turn_off:
- delay: 50s
- switch.turn_on: mosfet_switch
status_led:
pin:
number: GPIO2
I found this topic SHTC3: Wake up the sensor during setup by Sizurka · Pull Request #993 · esphome/esphome · GitHub which sounds promising.
If anyone knows how to implement the wake up command in ESPHome, it would be very much appreciated (is it possible in the yaml? I do not know how to access the mentioned file in ESPHome). Maybe there is another workaround? I’m stuck at the moment, I already can see in the voltage curve that the mosfet really helps prolonging battery life, but without any signs of life of the BH1750.
Anyway, thanks in advance, maybe I have made a stupid mistake somewhere,
Mario