Can integration be detected and automized?

Hello, I’m a complete new noob into the world of HA since just a few weeks back but see the amazing potential of this software for controlling my home.
And have a question that I am unsure on how to do and wonder if someone skilled in HA can hint and guide me on.

I have an issue where my Homekit controller lose connection now and then…(yeah. that is an issue in itself that will be solved with a future update, but that’s not what I want to achieve now… :slight_smile: )

Question: When HA detect a specific Homekit, can this be scripted in HA to automatically be detected, setup and paired with the hard-coded pin code and a notification sent to me?
(yes, a temporary workaround to restore Homekit when it lose connection.)
I am pretty sure this can be done as I understand almost anything is possible with scripting but I am unsure on where to start looking.

Kind regards, Magnus