I am facing challenges with deep_sleep too. I did some testing on my network and my bme280 + esp32 was waking and sending readings and going back to sleep within 2 seconds, then sleeping for an hour. A run duration of zero was working. When I deploy this on another remote network I get different behavior. Otto has told me that run_duration starts being counted after MQTT is connected, this is important to know, so that should take care of variable time connecting to wifi and connecting to mqtt broker. It is important to know that if your sensor update_interval is longer that your run_time it has no effect, or at least that is what I was told by Otto, the update_interval time elapsed is not stored anywhere on non volatile storage, so gets reinitialized every time the device wakes from sleep. My update interval was set to 43mins, I have removed it for now, and am inclined to set it to something very small and rely on my automation to make the device sleep again. At the moment it seems that readings are scheduled on a variable basis. I also had blank birth and will messages to disable availability reporting and make the graphs look better, I don’t know if that exposes different behaviour. In the above config blank birth/will are now commented out.
Here is my config:
broker:********.co.uk
port: 23046
username: scott
password:********
# birth_message:
# will_message:
on_message:
- topic: bedford/ota_mode
payload: 'ON'
then:
- deep_sleep.prevent: deep_sleep_1
- topic: bedford/sleep_mode
payload: 'ON'
then:
- deep_sleep.enter: deep_sleep_1
logger:
# level: INFO
ota:
password: ********
i2c:
sda: 16
scl: 17
sensor:
- platform: bme280
temperature:
name: "bford temp"
oversampling: 2x
pressure:
name: "bford pres"
oversampling: 2x
humidity:
name: "bford humi"
oversampling: 2x
address: 0x76
deep_sleep:
id: deep_sleep_1
run_duration: 10s
sleep_duration: 60min
I have an automation that publishes a MQTT message which triggers deep_sleep.enter when the reading from the BME280 is received by HA. THis config worked fine for almost a whole day, then I see MQTT connections on my broker with no readings being sent. 10s should be enough time?
My device is in a inaccessible place at another address so difficult to debug/troubleshoot. I will go there later today and attempt to reflash it by setting ota_mode, I have set that just now to see if it now needs more than 10secs wake time, it would be a bit absurd to have to use on_boot to force sensor readings in a timely manner. I also seem to be having wifi and mobile data issues too, because the sensor does not connect every hour, so that can be influencing stuff, off to install a better router too.
update: I think deleting the retained messages for the readings messes it up. I cleared out all the retained messages to start afresh, including the homeassistant discovery ones and it started working again. You have to be careful what messages are posted when on mqtt, my automation got out of sync, and the message to sleep was being acted on before the readings
alias: bedford sleep after mqtt receipt
trigger:
- platform: mqtt
topic: bedford/sensor/bford_humi/state
action:
- delay: 00:00:02
- data:
payload: 'ON'
topic: bedford/sleep_mode
service: mqtt.publish
- delay: 00:00:10
- data:
topic: bedford/sleep_mode
service: mqtt.publish
Here I decide to disable the sleep mode 10s after it fires, if you edit the automation or restart ha it fires on its own due to the retained message.