I've been able to reproduce the lost state (accompanied of the Cannot send message because of TCP buffer space message in serial logs) quite reliably while streaming pictures. Pressing the button of my "doorbell camera" briefly would keep the state remain stuck in ON in Home Assistant when the OFF transiton was lost, or sending commands to turn on/off a light would be "rolled back" in HA's UI when it timed out waiting for a "light state change" coming back to confirm, but it being lost.
I've managed to greatly mitigate this by ensuring the camera data leaves at least 64 unused bytes in the TCP send window. Then when I press a button or send a light change there's always some space for a single state update back, even when streaming pictures back.
In addition to this, I think it'd be necessary to actually loop in APIConnection until there's enough free send buffer, rather than trying only twice.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Operating environment/Installation (Hass.io/Docker/pip/etc.):
pip, git clone dev branch
ESP (ESP32/ESP8266, Board/Sonoff):
esp32-cam
ESPHome version (latest production, beta, dev branch)
dev branch
Affected component:
https://esphome.io/components/api.html
Description of problem:
Sensor or light updates to Home Assistant get lost when there's a lot of traffic towards Home Assistant, especially when streaming pictures.
While https://github.com/esphome/issues/issues/877#issuecomment-558745873 says important messages are retried, that doesn't seem to be the case:
Demultiplexor
ensures only transitions are sent, so there's no option to "fill the gap later" if a transition is lost unless the sensor state changes:APIServer
doesn't check the return value ofsend_binary_sensor_state
if sending fails for any one client connection:APIConnection
only tries twice to send a message (with adelay(0)
in between):I've been able to reproduce the lost state (accompanied of the
Cannot send message because of TCP buffer space
message in serial logs) quite reliably while streaming pictures. Pressing the button of my "doorbell camera" briefly would keep the state remain stuck in ON in Home Assistant when the OFF transiton was lost, or sending commands to turn on/off a light would be "rolled back" in HA's UI when it timed out waiting for a "light state change" coming back to confirm, but it being lost.Problem-relevant YAML-configuration entries:
Logs (if applicable):
Additional information and things you've tried:
I've managed to greatly mitigate this by ensuring the camera data leaves at least 64 unused bytes in the TCP send window. Then when I press a button or send a light change there's always some space for a single state update back, even when streaming pictures back.
In addition to this, I think it'd be necessary to actually loop in
APIConnection
until there's enough free send buffer, rather than trying only twice.I'll link a PR with these changes.