If you're interested in DIY water cut-off devices for electric water heaters, you might want to check out this article.
For safe water use, you can follow along to DIY a water-powered cut-off device. The principle of this device is to install a water flow sensor at the water inlet of the heater. When water is flowing, a normally-closed relay opens and cuts off the live wire to the heater.
The picture below shows the water flow sensor being used.
This water flow sensor is the HengTeng HT-60 model, though you can also choose other types if you like.
This sensor was originally designed to control water pumps. When water flows, the internal SCR conducts and controls the pump operation. It's quite sensitive. When water flows, there's a resistance of tens of K ohms across the sensor, which can be used to control a relay.
You can use a relay mounted on a prototyping board to control the circuit, like in the picture below.
You can use a router power supply to provide 12V, use the normally-closed contacts of the relay, and have the relay control the live wire. The picture below shows how the sensor is installed.
You can install the control part inside the water heater. In actual use, it works really well.
And just like that, the whole setup is complete.