You could use a home assistant-like api to turn off the switch as well as manage the /etc/hosts changes. I don’t have any experience with home assistant, per-se, but I have programmatically controlled similar the switches with an older api, so I assume HA would work too.