This weekend I finally got around to changing all my ESP sensors from mqtt to the api and discovered a case where esphome mqtt is superior to the esphome api.
It takes at least three times as long using the api as it does using mqtt to wake and report the state of a binary sensor. Using the api this regularly results in missed sensor states, even allowing for filters like this:
filters:
- delayed_on: 100ms
- delayed_off: 10s
With mqtt and the above filter I never miss a sensor state that wakes the device.
I tried upping the off time to 45s and while this did allow the api to report the state that woke the device it caused other problems.
Problem with current native API is that the ESP is the server. That was an intentional decision that makes setup much easier (and so the default will stay that way).
However, for things like deep sleep the api needs to be turned around: A central server (kind of like MQTT broker) that all ESPs connect to. Current plan is to incorporate this new server directly into HA.
If only I had read it before changing everything over. Would have saved a bit of mucking about and restarting to remove …_2 and …_3 copies of the sensors.