Illustration of Active+Idle Power
Me being a perfectionist, it was an itch in my side until I came up with a solution to this problem. I've been testing it for some time (successfully imho) and now I'd like to share my idea with everyone. It's a bit tricky to set up, as you have to make sure different parts of factory power network are isolated behind Power Switches which is controlled by Decider Combinators which in turn has permanent access to power.
Illustration of Network Isolation
Power Switch Up Close
The key concepts leading to the solution are a buffering and a hysteresis. If you want to save power you have to turn off access to it for idle buildings. But you can't allow them being turned on and off rapidly, otherwise bad things happen. Here to the aid comes the hysteresis: it ensures the buildings work as long as there is enough resources to work with and there is space to transport products to (no shortage and no belt backup). The hysteresis also ensures power is turned off as long as conditions are not satisfied to the point production can run smoothly for some time. For these conditions to be satisfied reliably (and to detect the fact) the buffering is required.
Illustarion of Ealy- and Midgame Science Buffer
So, the Factory splits into blocks. Each such subfactory works on one single product (and maybe one or two prerequisite subproducts as is the case for Green and Red Circuits) and has buffers for every input and for output. The best way to organize a buffer is to use an array of chests with fast or bulk inserters to ensure throughput. This meshes really good with train network buffering. In case of very low in/out throughput or as a "quick and dirty" buffer a long (and/or curvy) patch of belt will do too (make sure all belt cells connected to the network read content as hold, not pulse).
All these buffers are connected into a single Circuit Network and their signals come into a Decider Combinator that controls the Power Switch for an entire subfactory. To organize the hysteresis the Decider Combinator must have a feedback on a different (color) network (see third the illustration above). The logic inside Decider Combinator is as follow: it starts to output ON signal if there is enough resources and space for product and continues to output ON as long as it still true (see next illustration). This logic is produced by one OR gate (that combines two cases) and a bunch of AND gates combining comparisons of Circuit Network signals from buffers with predetermined constants. Also, the second OR gate input depends of feedback signal to ensure the hysteresis. Specific numbers in comparisons depend on type and size of buffers (and on throughput in case of "dirty" belt buffers). Here is the example:
Illustration of Gate Logic Inside a Combinator
As you can see, ON conditions split into two parts. The starting conditions in the top half are hash and in the bottom half are much milder, but depends on ON signal already being present (feedback). This ensures the hysteresis. Output buffer is 6 Wooden Chests, that can contain up to 9.6k of Blue Circuits, so I decided to limit it at 9k and 1/3 of this value is enough of free space to begin a new production cycle. This means output buffer has to contain less than 6k of product.
This concept can be applied to power productions. When you are gradually switching from steam power to solar one with accumulators you may not want you Steam Engines to produce energy as long as there is enough charge in your accumulator stack. But they will output power into power network as long as there is power deficit and will keep you accumulators fully charged. It may be preferred behabiour (in case your defences are laser turrets) or may be not. In case not you can isolate your steam power network into separate part, connect it to main network through Power Switch and govern this switch with Decider Combinator with feedback, hysteresis logic and signal from nearby accumulator. Once accumulator charge deeps too low (preferably not zero) gate logic connects steem power network with main one and it starts produce additional power. Once accumulator charge is high enough (due to buildings being turned off, solar panels online or just steam power overpowering all the consumers) login breaks the connection. This works very well with nuclear power.
Here is the blueprint of two such subfactories (Green and Blue Circuits) close to each other, connected to train network and feeding one into another in case they work simultaneously (to save train fuel and thoughput). Into the design of them have come a lot of considerations of belts and inserters throughput balanced against consumption and productions rates of Assembling Machines with Beacons and Modules as well as rationality of using productivity modules on different stages of the game (as well balanced against energy and fuel consumption), but these are topics for another discussions.
Birds Eye View of the BP
By the way, I just love v.2+ Combinators! With how Devs implemented them in new version of the game it became so much easier and natural to make all the logic described above than it had been before.
.
