Sailing Exodus
Projects · automation

Smart plugs
for dumb devices.

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 idea

The Pi decides. The plug just switches.

Diagram: a battery bank sends its voltage to a Raspberry Pi, which switches a smart plug on or off; the plug feeds mains from the inverter to a charger, which charges the tool batteries, vacuum or kettle

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.

It can't overcharge anything

We only control on and off

The plug never controls charging. Every charger on a plug is a real charger with its own overcharge protection: it decides how much current to push and when to stop. The Pi only decides whether the charger has mains power at all. Leave a plug on forever and the charger still stops when the battery is full, exactly as it would plugged straight into a wall.

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.

What we run this way

Each one has a different rule

DeviceWhat the Pi watchesThe 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.

Chargers whose settings we couldn't get at

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.

It keeps working with the internet down

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.

Other ideas

Not built, but the same trick would do it

What to watch out for

Cheap plugs have limits

Build your own

The shape of it

  1. Buy a smart plug that speaks a local protocol. We use TP-Link Kasa HS103s, which a free Python library can control directly on your own network.
  2. Put the plugs on the Pi's own Wi-Fi, so control doesn't depend on the router or the internet.
  3. Write a small script that reads the battery from Signal K and switches the plug. Start with a single threshold.
  4. Run it from a timer, every few minutes. Log every decision, with the reading that caused it.
  5. Make it fail safe. Missing data means do nothing, and add a maximum run time.
The scripts are available on request on Discord. They're short Python, nothing exotic.

Our custom screens → The lithium banks Charging off a dumb alternator All projects