This would work (even?) better if it wasn’t a switch, but a push button with the unblocking automatically timing out after some interval. Otherwise you’re prone to just letting it stay on unblock.
The Amazon Dash buttons could be hacked to do something like that.
Little programmable buttons, they're great. I've used them for similar habit formation stuff, in my case not ignoring my alarm, by making the button the only way to shut it off, and putting the button very far away from bed.
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.
The Amazon Dash buttons could be hacked to do something like that.