Open MatthiasDenkler opened 10 months ago
After latest Homeassistant Coreupdate, this works again as intended. But now the measured and sended States dont get displayed anymore. Can this be a Bug of ESPHome or is it more a Homeassistant Problem?
I'm on latest updates of everything but devices in deep sleep still are unavailable regularly.
With a run_duration of only 30 seconds, and update_interval of 40s for the sensors, its likely that they just dont update in time. The first update they do is at a random time between 0 and the update interval to spread out updates.
The best way to solve this is to use an on_boot
automation to wait until the api is connected, then force an update on each sensor, delay for a second or 2 to allow network traffic to be sent, then manually enter deep_sleep once that is done.
esphome:
on_boot:
- wait_until: api.connected
- component.update: bme280_id # give this id to the parent bme sensor
- component.update: outside_dew # give this id to the Outside_Dew template sensor
- component.update: outside_battery # give this id to the adc sensor
- delay: 1s
- deep_sleep.enter:
And delete the run_duration
from the deep sleep config.
This will likely let it run for even less than 30 seconds too as it only stays on for maybe 1 or 2 seconds after api is connected.
Will give it a try! Just a question from an eager-to-learn rookie: does the 'on boot' also run on wake after deep sleep then or only at actual boot after forced reset?
A wake up is the same as a reboot.
Thanks for clarifying... but I should have known 🤭. I already have an on_boot to check if a helper switch is on so that the device stays awake and give me opportunity to install new code wirelessly when needed.
No luck with this workaround here: already 2 disconnections in as many hours like before. My code for if someone would like to have a check:
esphome:
name: temp-004
on_boot:
- wait_until: api.connected
- component.update: bme280_temp004 # give this id to the parent bme sensor
- component.update: wifi_signal_db_temp004 # give this id to the Wi-Fi sensor
- component.update: batterij_temp004 # give this id to the adc sensor
- delay: 5s
- script.execute: consider_deep_sleep_temp004
esp8266:
board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "Ucno7qxcEczHMQFf0Uxxxxxxxx"
ota:
password: "7f471xxxxxxxxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
power_save_mode: none
manual_ip:
static_ip: 192.168.1.134
gateway: 192.168.1.1
subnet: 255.255.255.0
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Temp-004 Fallback Hotspot"
password: "OxxxxxUx1xxx"
captive_portal:
i2c:
# sda: 4
# scl: 5
scan: False
sensor:
- platform: bme280
id: bme280_temp004
temperature:
name: "Temperatuur"
filters:
- offset: 0.4
pressure:
name: "Luchtdruk"
filters:
- offset: 2.1
humidity:
name: "Luchtvocht"
address: 0x76
update_interval: 6min
- platform: wifi_signal # Reports the WiFi signal strength/RSSI in dB
name: "WiFi Signal dB"
id: wifi_signal_db_temp004
update_interval: 6min
entity_category: "diagnostic"
- platform: adc
id: batterij_temp004
pin: A0
name: "Batterij"
update_interval: 6min
unit_of_measurement: "%"
accuracy_decimals: 0
icon: mdi:battery-medium
filters:
- multiply: 4.5
- calibrate_polynomial:
degree: 3
datapoints:
- 0.00 -> 0.0
- 3.30 -> 0.0
- 3.35 -> 5.0
- 3.39 -> 10.0
- 3.44 -> 15.0
- 3.48 -> 20.0
- 3.53 -> 25.0
- 3.57 -> 30.0
- 3.62 -> 35.0
- 3.64 -> 40.0
- 3.69 -> 45.0
- 3.73 -> 50.0
- 3.78 -> 55.0
- 3.82 -> 60.0
- 3.87 -> 65.0
- 3.91 -> 70.0
- 3.96 -> 75.0
- 4.00 -> 80.0
- 4.05 -> 85.0
- 4.09 -> 90.0
- 4.14 -> 95.0
- 4.20 -> 100.0
- lambda: |-
if (x <= 100) {
return x;
} else {
return 100;
}
deep_sleep:
id: deep_sleep_control_temp004
# run_duration: 20s
sleep_duration: 15min
# Will only pick up a value if this device is configured in Home Assistant > Integrations
# If the device isn't configured, or Home Assistant is offline, it'll default to false
binary_sensor:
- platform: homeassistant
id: prevent_deep_sleep_temp004
entity_id: input_boolean.prevent_deep_sleep_temp004
script:
- id: consider_deep_sleep_temp004
mode: queued
then:
- delay: 10s
- if:
condition:
binary_sensor.is_on: prevent_deep_sleep_temp004
then:
- logger.log: 'Skipping sleep, per prevent_deep_sleep_temp004'
else:
- deep_sleep.enter: deep_sleep_control_temp004
- script.execute: consider_deep_sleep_temp004
I don't know what you mean by "disconnections", but if you want to find out what's going on, then you need to watch the serial logs.
Exactly what the thread opener described. Devices with deep sleep installed regularly get 'not available' a few moments after going back into deep sleep. It's a known issue and I've read and tried numerous workarounds... that fail to work. Cause and solution may be in HA.
Had hoped that today's version 2023.11.0 would have solved this issue... but alas. Only with my 2 D1's with deep sleep active.
Logger: aioesphomeapi.reconnect_logic
Source: runner.py:188
First occurred: 14 november 2023 om 22:26:55 (184 occurrences)
Last logged: 18:35:57
Can't connect to ESPHome API for temp-004 @ 192.168.1.134: Error connecting to ('192.168.1.134', 6053): [Errno 113] Connect call failed ('192.168.1.134', 6053) (SocketAPIError)
Can't connect to ESPHome API for temp-002 @ 192.168.1.132: Timeout while connecting to ('192.168.1.132', 6053) (SocketAPIError)
Can't connect to ESPHome API for temp-004 @ 192.168.1.134: Timeout while connecting to ('192.168.1.134', 6053) (SocketAPIError)
Can't connect to ESPHome API for temp-002 @ 192.168.1.132: Error connecting to ('192.168.1.132', 6053): [Errno 113] Connect call failed ('192.168.1.132', 6053) (SocketAPIError)
TWIMC: this is the only workaround that keeps the devices as 'available' during deep sleep for me. Increased the DisconnectRequest to 1000ms. Maybe less will work as well.
Device updated at 10h00 with this workaround:
Was this issue resolved by that change?
The problem
As the Title says as soon as the ESP goes into deep sleep, the Entitys in Homeassistant are going to "Currently not available" in the latest Version. When this happens in the Logs I get this Message:
Which version of ESPHome has the issue?
2023.10.1
What type of installation are you using?
Home Assistant Add-on
Which version of Home Assistant has the issue?
core-2023.10.3
What platform are you using?
ESP32
Board
Lolin32 ESP32 Lite 4MB
Component causing the issue
api?
Example YAML snippet
Anything in the logs that might be useful for us?
Additional information
No response