I’ve been using ESPHome for a while and I started to use it with ESP32 devices and I’ve used my boilerplate yaml (including a uptime sensor and a wifi strength sensor) but I found that when hooking Home Assistant up to it, it would disconnect and reconnect.
[11:39:41][D][api.connection:604]: Client 'Home Assistant 0.116.4 (192.168.1.5)' connected successfully!
[11:39:41][D][api:067]: Disconnecting Home Assistant 0.116.4 (192.168.1.5)
[11:39:41][D][api.connection:604]: Client 'Home Assistant 0.116.4 (192.168.1.5)' connected successfully!
[11:39:42][D][api:067]: Disconnecting Home Assistant 0.116.4 (192.168.1.5)
[11:39:42][D][api.connection:604]: Client 'Home Assistant 0.116.4 (192.168.1.5)' connected successfully!
[11:39:42][D][api:067]: Disconnecting Home Assistant 0.116.4 (192.168.1.5)
[11:39:43][D][api.connection:604]: Client 'Home Assistant 0.116.4 (192.168.1.5)' connected successfully!
[11:39:43][D][api:067]: Disconnecting Home Assistant 0.116.4 (192.168.1.5)
[11:39:43][D][api.connection:604]: Client 'Home Assistant 0.116.4 (192.168.1.5)' connected successfully!
[11:39:44][D][api:067]: Disconnecting Home Assistant 0.116.4 (192.168.1.5)
[11:39:44][D][api.connection:604]: Client 'Home Assistant 0.116.4 (192.168.1.5)' connected successfully!
[11:39:44][D][api:067]: Disconnecting Home Assistant 0.116.4 (192.168.1.5)
[11:39:44][D][api.connection:604]: Client 'Home Assistant 0.116.4 (192.168.1.5)' connected successfully!
[11:39:45][D][api:067]: Disconnecting Home Assistant 0.116.4 (192.168.1.5)
[11:39:45][D][api.connection:604]: Client 'Home Assistant 0.116.4 (192.168.1.5)' connected successfully!
[11:39:45][D][api:067]: Disconnecting Home Assistant 0.116.4 (192.168.1.5)
By trial and error I found that the uptime text_sensor was to blame. If I commented it out, the behavior stopped and everything worked great. Maybe this is a bug in the ESP32/ESPHome implementation?
Here’s the uptime sensor details:
sensor:
- platform: uptime
name: ${friendly_name} Uptime Raw
id: ${node_name}_uptime_raw
internal: true
update_interval: 30s
text_sensor:
- platform: template
name: ${friendly_name} Uptime
lambda: |-
uint32_t dur = id(${node_name}_uptime_raw).state;
int dys = 0;
int hrs = 0;
int mnts = 0;
if (dur > 86399) {
dys = trunc(dur / 86400);
dur = dur - (dys * 86400);
}
if (dur > 3599) {
hrs = trunc(dur / 3600);
dur = dur - (hrs * 3600);
}
if (dur > 59) {
mnts = trunc(dur / 60);
dur = dur - (mnts * 60);
}
char buffer[17];
sprintf(buffer, "%ud %02uh %02um %02us", dys, hrs, mnts, dur);
return {buffer};
icon: mdi:clock-start
update_interval: 600s
Anyway, it was driving me nuts until I figured it out. I thought I’d post just in case someone else experiences the same thing…