I am currently designing electricity for my game. If you've ever played or seen Factorio, this is pretty much the exact way I want it to be.
Okay, on to theory: What I came up with is some sort of power source produces a certain amount of Watts per frame. Most power sources cannot store any energy, so at the end of the frame, it is all lost.
Machines connected by wires to energy sources will perform a Dijkstra-style flood-fill from themselves through all connected wires, ignoring wires that have already been processed. The Watt cost will slightly increase for each wire it passes through (to simulate energy loss) and when it reaches a battery or power source, it will drain as much as it needs. If the source doesn't have enough, it continues to search for more power. If, by the end of the frame, it doesn't have enough Watts, it simply works slower or stops working entirely.
After all machines have done this, all batteries will perform a similar flood-fill, but ignoring other batteries, and will attempt to take ALL of the energy from sources (up to its storage capacity).
Then, all power sources discard all energy.
Is this how it actually works? I want to use numerical values, so just being connected to an energy source is not enough. Thanks.