Good morning, Alan and David,
Here's what I've got. I'm certain this script won't run for you "right out of the box." But it hopefully gives you a good outline and starting point for your use, given your own specific equipment configurations. Just FYI, I've included a wiring diagram showing how all my equipment is connected.
As I mentioned, when the power fails, and after the delay time passes, the UPS runs a "cmd" shell script, which in turn then calls the script to close up and shut down. This shell script is on the observatory computer, too, but in the folder domain of the UPS applications. My UPS specifies the literal location and name for that shell script. The shutdown script the shell script executes can be in any location on the observatory computer, so to make things simpler, I put the PowerfailGracefulShutdown.js script in the C: folder. Here's what that shell script statement looks like (also attached). It also generates a log file:
cscript C:\PowerfailGracefulShutdown.js >> PowerfailShutdown.log 2>&1
You will notice some statements in PowerfailGracefulShutdown are specific to my own observatory, such as the various ID's for the dome, IP-addressable power switch, weather object and software, etc. These you will need to configure for your own situation.
I always leave ACP running - the larger part of the script assumes ACP is running. If for some reason it's not, and there's a utility power outage, the smaller part of the script near the bottom will try to close the dome (the most critical thing you'd want to do but which is most unlikely to be open if ACP is not running...) and then shut down everything by brute force (again, not likely anything else is running if ACP is not).
The shutdown script provides logging via ACP's Console.PrintLine, saved in the default LocalUser folder, but only up to the point where ACP is shut down and Console.PrintLine is no longer available.
Good luck.