Carbon-aware laptop charging
Andy Stanford-Clark - Aug'22
With recollections of "memory" in NiCad batteries of old, I thought maybe cycling the battery up and down from full to near empty might be a good idea. And then quickly thought that automating that process would be an even better idea.
So armed with my trusty tools of Node-RED and
MQTT, I created
a flow which would turn the charger off when the battery was full and on when the battery was empty.
-InternalBattery-0 (id=xxx) 100%; charged; 0:00 remaining present: truefrom which you are but a short regex away from extracting the battery percentage and charging state (note the <tab> character before the percentage digits!)
That worked fine, but people who know more about batteries than I do started telling me that cycling the batteries is the worst thing you can possibly do to a modern LiPo-family battery, and I should stop doing that immediately.
Then a conversation with @brackendawson led me down the more interesting rabbit hole of "could I make the charging more carbon-sensitive", in the sense that when the electricity grid is on minimal renewables and maximal high-carbon gas turbines (e.g. when it's early evening so the PV is dropping off, there's a high pressure system sitting over us so the wind isn't blowing, and grid demand is at its highest as we're all cooking dinner), could I "do my bit" to help and turn off the charger?
I had previously played with the UK National Grid Green Light Signal API which tells you the carbon-intensity of electricity generation in your part of the country.
"Where can I get a GlowOrb?", I hear you cry. paypal.me/andysc/25 will do the trick :)
As the feed for that data is on a handy MQTT topic (on my home broker), it was quite straightforward to modify my Node-RED flow so the charger turns off when the Green Light Signal says "very high", and back on when it either falls to a lower level, OR if the battery gets close to empty (I chose < 10%).
Note it could leave the battery in a low state of charge when you need it full to go out somewhere. A manual over-ride button (an inject node or a dashboard button) would be the obvious way to fix that — or just plug the charger directly into a power socket and don't use the SmartPlug!
Comments, advice or questions? Tweet @andysc.