Backup Generator Guard
Automatically fire up a fuel-burning backup generator whenever your main battery drops below 20% charge, keep it running until the battery reaches 90%, and hold it on for 5 extra seconds (off_delay) so brief power spikes never make it flicker on and off.

World setup
Section titled “World setup”- Place a Tier 1 Interface with an Energy Expansion against your main energy storage block (for example, a Mekanism Energy Cube or battery) and name it
battery. - Place a Tier 1 Interface with a Redstone Expansion against your backup generator (or redstone wire leading to it) and name it
generator. - Open
generator’s Redstone tab:- Set Direction to Output.
- Set Fault value to
0(or15if your generator uses “high signal = disabled”) so the generator shuts off safely if the PLC stops or faults.
- Check your battery’s total capacity in FE and adjust
LOW_FEandHIGH_FEin the script below (the example assumes a1,000,000 FEbattery).
Script
Section titled “Script”load("mplc:timers", "off_delay")
BATTERY = point("battery/energy")GEN = point("generator/redstone")
LOW_FE = 200_000 # Turn on below 20%HIGH_FE = 900_000 # Turn off at 90%HOLD_TICKS = 100 # Keep running 5 seconds (100 ticks) after reaching HIGH_FE
RUNNING = register("running", False)HOLD = register("hold", [-1, False])
def scan(): stored = BATTERY.count()
if stored < LOW_FE: RUNNING.set(True) elif stored >= HIGH_FE: RUNNING.set(False)
# Hold the output on briefly after RUNNING flips False to prevent flicker active = off_delay(HOLD, RUNNING.get(), HOLD_TICKS) GEN.set(15 if active else 0)Why this works
Section titled “Why this works”- Energy is keyless, so
BATTERY.count()takes no arguments and returns total FE directly. - The
RUNNINGregister creates a latch (hysteresis): between200,000and900,000FE, the script keeps whatever state it was already in instead of rapidly toggling at a single threshold. off_delayfrommplc:timersuses its ownHOLDregister ([-1, False]) and counts real game ticks withnow().
Ways to tweak it
Section titled “Ways to tweak it”- Inverted redstone generator (“high = off”): Swap the final line to
GEN.set(0 if active else 15)and set the Redstone Expansion’s Fault value to15. - Auto-calculate percentages: If your battery’s
space()returns remaining room reliably, you can readtotal = BATTERY.count() + BATTERY.space()—note thatspace()is capped by the Interface’s put limit (20k/40k/80k FE), so fixed FE constants likeLOW_FEandHIGH_FEare more accurate for large batteries. - Fuel-saving alarm: Add a second Redstone Output
alarmthat lights up ifstored < 50_000for more than 10 seconds usingon_delay(ALARM_REG, stored < 50_000, 200).
Not an official Minecraft website. Not approved by or associated with Mojang or Microsoft.