Bk7231t device being unavailable when refreshing DHCP

I decreased my DHCP lease time in the router to 1 minute and then I realized that my devices gets unavailable every minute. Increasing the lease time to 5 minutes they get unavailable every 5’th minute.

This only happens on my bk7231t (generic-bk7231t-qfn32-tuya) devices.

My guess is that this is where it happens (192.168.0.153 is my HA):

[08:03:00][VV][scheduler:225]: Running interval '' with interval=10000 last_execution=161317 (now=171320)
WARNING biltema12.local: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for biltema12.local
WARNING Disconnected from API
INFO Successfully connected to biltema12.local
[08:03:16][D][api:102]: Accepted 192.168.0.153
[08:03:16][VV][api.service:504]: on_hello_request: HelloRequest {
  client_info: 'Home Assistant 2023.11.0'
  api_version_major: 1
  api_version_minor: 9
}

Why would you decrease the lease time?
Are you having so.many device on your network that your DHCP is getting depleted and you at the same time have devices that are offline for longer times?

Try setting static ip leases in the DHCP. I don’t get why you would want 1 minute leases though?

Thanks for your replies @fleskefjes and @WallyR
I just decreased the lease time to do some investigations.

But… This indicates that there are some problems in the code for the wifi components for bk72 chips, and even though the lease time is configured to 120 minutes (as it is on my router by default) we don’t want the device to be unavailable 12 times a day for 15 seconds, that could really mess up an automation or get the family members annoyed.

And this kind of problems will be very hard to find the root cause for if we don’t go to the extremes like I did here

A DHCP client will request a renewal when remaining time gets below a certain point.
A device in deep sleep will not be ble to react to this point being reached.
At 1 minutes and also at 5 minutes lease time the device will probably have to issue a renewal right away and since the new lease time will be the same, then it will have to do it again.
It is just a unrealistic low lease time.

I understand how you are thinking but a one minute lease time (even though totally insane) works without issues for all my other devices on my network, Laptops, HA, Other ESPHome devices etc.
And even if the less time has expired, the device will work like as well on the network.

So I have created a ticket for this, let’s see if anyone will pick it up: Device unavailable for ~15 seconds when refreshing DHCP · Issue #5075 · esphome/issues · GitHub

It is worth a try. :wink:

1 Like