A cheap smart plug, a Raspberry Pi and a few lines of Python turn a plain 120 volt device into an automatic one. Chargers that watch the battery. A kettle on a timer. A heater that gives up when the battery gets low.
The Pi decides. The plug just switches.
The Pi reads the battery, compares it with a threshold, and tells the plug on or off. The plug is the only thing it touches.
Plenty of things aboard that charge batteries off our batteries are about as clever as a brick: a power-tool charger, a vacuum, a kettle. Plug them in and they take power, whether or not the battery behind them can spare it. That matters when the power comes through an inverter, because the inverter wastes some of it just turning DC into AC.
So we put each one behind a TP-Link Kasa smart plug, and the Pi decides when the plug is on. The Pi already knows the state of every battery bank, because it reads the battery management systems. The rule is a voltage or a percentage: above this, pass power; below this, don't. A small script checks every few minutes and flips the plug.
We only control on and off
On top of that, our scripts are built to fail safe. If a reading is missing or stale, they change nothing. Anything that turns a charger off has to see the condition several checks in a row, so one flicker doesn't flip a plug. A charger that was switched on has a maximum run time, so a fault can't leave it on for days. And thresholds have a gap between “on” and “off” so a plug never chatters around a single number.
Each one has a different rule
| Device | What the Pi watches | The rule |
|---|---|---|
| DeWalt battery chargers and the vacuum | House battery charge | Above 70%, power passes through. Below it, the plug stays off. We never spend a draining battery topping up drill batteries. |
| 12 V nav bank AC charger Victron Blue Smart |
Nav bank charge and voltage | On at 50% or below, or a week after the last full charge. Off when the charge has tapered (voltage high and current almost nothing, three checks in a row), or after twelve hours at the most. |
| Engine-start battery charger | Is there shore or generator power? | On while there's AC on the dock or from the generator. Off when we're running on the inverter, so it doesn't draw from the house bank. |
| Engine block heater | Shore power, and house charge | We turn it on by hand and the Pi only ever turns it off: no shore power, or the house bank down to 50%. It will never switch itself on. |
| Hot water heater (planned, not on a plug yet) |
House battery charge, and whether anything is charging the bank | It runs on AC and it is a big draw, so it only runs when the bank is being charged, by solar, the generator or the engine. Even then it only comes on when the bank is over 70% and charge is coming in. Otherwise it stays off unless we switch it on by hand. |
| Electric kettle | The clock | On a timer. |
The block heater is the one worth copying. A heater is a huge load and comfortable to forget about. Letting a script cut it but never start it keeps us in charge of when it runs and still protects the batteries.
The plug works even when the charger won't talk to you
Some AC chargers have a Bluetooth app and a password, and one of ours is a case in point: we lost the password, so we can't open its settings. A smart plug doesn't care. It never talks to the charger, only to the mains going into it. So a charger we can't configure can still be automated: it comes on when we want it and goes off when we don't, and the charger itself keeps behaving like the charger it is.
The plugs live on the Pi's own Wi-Fi, not on the boat's internet connection, and they answer a command straight from the Pi with no cloud account in the loop. Starlink can be off, the router can be dead, and the whole loop (read the battery, decide, switch the plug) still runs.
Not built, but the same trick would do it
Cheap plugs have limits
The shape of it
Our custom screens → The lithium banks Charging off a dumb alternator All projects