This is where solid-state relays (SSRs ... packed into a module (you can even build one yourself). The first component is an optocoupler which isolates your control circuit from the mains ...
But what if all you have on hand is an ESP8266? [TechColab] needed to control a solenoid valve with a short pulse via a solid-state relay (SSR) but found that the trusty 555 timer was tricky to ...