Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Powerwall and apcupsd

This site may earn commission on affiliate links.
I can't be the first person who has thought of having a powerwall communicate using apcupsd, to get it to tell computers to shut down safely when grid power is unavailable. I'm no expert with apcupsd, I just found out about it last night, but it's a standard that allows UPS devices to communicate with computers, so that they can know if they need to shutdown safely before power loss. Of course a powerwall could power computers for a bit, but during the winter with low amounts of solar, if there was a power outage, I would prioritize power for my electric well pump (which enables flushing toilets) vs powering a server, and doing this automatically would be best.

I haven't found anything with google searches, does anything like this exist? Seems like a docker container could access the gateway and translate it to apcupsd maybe?
 
I can't be the first person who has thought of having a powerwall communicate using apcupsd, to get it to tell computers to shut down safely when grid power is unavailable. I'm no expert with apcupsd, I just found out about it last night, but it's a standard that allows UPS devices to communicate with computers, so that they can know if they need to shutdown safely before power loss. Of course a powerwall could power computers for a bit, but during the winter with low amounts of solar, if there was a power outage, I would prioritize power for my electric well pump (which enables flushing toilets) vs powering a server, and doing this automatically would be best.

I haven't found anything with google searches, does anything like this exist? Seems like a docker container could access the gateway and translate it to apcupsd maybe?

You probably don't want the UPS making the shutdown decision or having something automated physically turn the UPS off unless there are high demand loads on the UPS that can't be controlled themselves.

Likely a better solution is to have a script running on your server that checks the local Powerwall API (vloschiavo/powerwall2)

Code:
GET /api/system_status/grid_status Determine if the Grid is up or down.

request: curl --cacert cacert.pem https://powerwall/api/system_status/grid_status
response: {"grid_status":"SystemGridConnected","grid_services_active":false}
{"grid_status":"SystemGridConnected"} = grid is up
{"grid_status":"SystemIslandedActive"} = grid is down
{"grid_status":"SystemTransitionToGrid"} = grid is restored but not yet in sync.

If the script detects a grid outage then you can kick off whatever graceful shutdown process you'd like.
 
  • Helpful
  • Informative
Reactions: diyguy and ra88it
Thanks, I'll have to digest this later, but yeah, I wasn't thinking about a ups being involved much, except the ride out the brief time before powerwalls are able to provide power in an outage. Then if there's a signal the grid is down one or many computers can shut down immediately or wait X minutes and then shut down. I'm not a developer but kind of a Windows batch script hobbiest, which isn't useful for this. This could be a good excuse to learn a different language.
 
Thanks, I'll have to digest this later, but yeah, I wasn't thinking about a ups being involved much, except the ride out the brief time before powerwalls are able to provide power in an outage. Then if there's a signal the grid is down one or many computers can shut down immediately or wait X minutes and then shut down. I'm not a developer but kind of a Windows batch script hobbiest, which isn't useful for this. This could be a good excuse to learn a different language.

Actually batch scripting would work great! :)

If you're familiar with PowerShell a simple PS script task would do the trick as it natively has web call capabilities with Invoke-WebRequest. Old school batch script would work too combined with Curl to make the calls to the Powerwall. Set either as a Windows scheduled task to run every minute or five and there you go.

Happy to help if you have questions.
 
Ultimately what I want to use this for would be to shut down two unraid boxes, maybe a pfsense box, but I'm sure if I could figure that out, powershell or batch for my windows 10 pc would be relatively easy so why not. The reason I was thinking apcpsd is because, I think, you set it up in one place, normally where the UPS is plugged in to a computer, and then other computers are capable of listening to the first for a signal, so the new custom code is in one place. I do think the chance of me figuring out scripts on the client boxes would be much more likely then some sort of unified apcupsd server.

Unraid is linux which I hear has some built in scripting ;). I'm going to tackle this later, today is my birthday and there is some beer on a shelf somewhere looking for a home. Thank you for your offer of help, I'll probably need it.
 
Well happy birthday!

Certainly having it in one place would make pushing out signals more straightforward but also risks a central point of failure.

Bash scripting is very viable, just use wget or curl for the http requests and take action from there. I'm guessing the same or very similar script should run on your unraid Linux (bash) as pfsense FreeBSD (tcsh) with how simple it is. https://web.fe.up.pt/~jmcruz/etc/unix/sh-vs-csh.html