Not sure if you are running managed access points that work together or individual ones.
If you are using managed access points that all work together, you can usually pin a wireless client to one access point. Check your documentation.
If you are using multiple ones that do not talk to each other, you might check your documentation and see if you can block that MAC address on the access points you don’t want it to connect to.
Either way, you should not be doing this on the client end. It should be on the access point end. Without knowing what access point(s) you are using, that is about as far as I can go on this.
Thanks for a helpful comment, using a couple managed APs with the same SSID. Most devices connect the closest AP, except these esphome devices. The APs are setup to drop a connection when the connection is poor but esphome devices keep connecting to the wrong ones.
The APs have no way to lock devices to a specific AP, apparently that is a feature that supposed to come via firmware update.
You could perhaps do it the other way around, force the esp to connect to the specific AP through the network software. I know at least Unifi supports this.
Are your access points using different WiFi channels? (they should be)
The ESPHome docs on multiple networks suggest that you need multiple entries for the signal comparison to work. But docs also say that when using hidden AP you must use fast_connect which stops signal comparison. You may also try adding priority e.g. (I have not tested this.)
Anecdotally I use OpenWRT Access Points and they have option “Disassociate on low” which was causing more problems then solving. I saw devices attempting to connect multiple times to distant AP (-90Db) and failing. When I turned it off I could see that devices would connect to distant AP but once associated would switch to a better signal AP typically within 15-45 seconds.