+1 for Shelly as I have or any other drop in relay, all the wiring you’ll need to do is behind the switchplate, you can decouple the input switch from the relay output and have HA trigger either output based on some input conditions. My fav config is having two flips of the switch perform a different action
The best code its given me I’d been able to search for and find where it was taken. Hey it helped me discover some real human blogs with vastly more helpful information.
(If you’re curious, it was circa when there was that weird infight at
openclosedAI with altman, I prompted to give code to find the rotational inertia per axis and to my surprise and suspicion the answer made too much sense. Backsearching I found where I believe it got this answer from)