I am configuring Wemos D1 mini with ESP Home. I want to power the device by battery and use deep sleep. I would prefer to use HA native API for node<->HA communication. But if I understood well the native API connection is initialized by HA. So, when the node wake up it must wait for HA to poll it. This is the reason why every successful project on this board uses MQTT. Am I right?
It all depends how often you need to connect to “somewhere”. Esphome is not optimized anyhow for fast connections after deep sleep.
LOL. All my successful projects are ESPHome native API.
Yes the device waits until HA connects to it.
Thank you for your answers. Currently my node is sleeping 15 minutes and then have 1 minute for communication. Approximately every second run the wake up time is not enough for sending the measured values.
Do you know about some source of information about the communication workflow? How often is HA polling the nodes? Is mdns involved in triggering HA about node being awake?
Would you mind to share your yaml?
It should, yes. Does mDNS work in your network or is it blocked?
Also other means do exist to deliver payloads to HA, for example webhooks/http-requests and even some official esp-now support on the horizon
Thank you for a good link. It generally answers my question.
Using mdns is probably* out of debate for me as I am using WireGuard component for connection to my VPS.
Could you please give me some hint how to use webhooks to trigger HA sensor polling?
Another question would be how to “enqueue” switching a node relay without MQTT retained message. When I try to switch the relay while the node is sleeping the HA just note that device is unreachable and forgets.
*) I am writing probably because even though WireGuard TUN VPS cannot transfer multicast packets I am able to sniff mdns queries at my VPS from my local computer connected through WireGuard VPN.
If I recall correctly, home assistant will attempt to reconnect to the device anywhere between every 5 and 10 seconds after disconnection. I recommend you make your sleep schedule depend on when the API event is connected has happened, rather than just making it a blind time window. That way, if the device needs to stay up for a minute, before home assistant decides to connect, then your device still works as advertised.
To my knowledge, MDNS is not involved in the decision to reconnect to the device on the side of Home Assistant — when and if the device has been added to Home Assistant by using the IP address of the device.
It does to my knowledge. It’s the same mechanism to auto discover a new esphome node. The moment a esphome joins a network it broadcasts it existence via mDNS. HA is listening and should act accordingly (ether offer to ad a new espHome node or connect to it if already known).
HA will reconnect without mDNS working, if the device was added thru its IP address.
Or hostname.
Still in case mdns is working HA can (should) quicker (re-)connect to a espHome node coming online that is sending out a mdns broadcast to announce it existence.
Also in case a new/different IP is assigned via DHCP to a node this workflow allows HA to updates it own records accordingly
Yes, so long as the hostname isn’t a .local
one, mDNS working won’t impact ESPHome Web or Home Assistant. They’ll retry every few seconds in my experience (at home I don’t rely on mDNS).