Page 1 of 2

Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Tue Nov 25, 2025 11:48 pm
by Tropical Snowman
Hello everyone,
I experience power losses from time to time and I'm worried it could damage my PC, so I'll buy a UPS (backup battery).

Since my measured power draw is 340 watts with Folding and BOINC, but less than 90 watts without them, I'd be much better off pausing them automatically when there's a power loss. My idea is linking it to the internet connection: when the router shuts off, PC pauses BOINC and Folding. If it's just for a couple minutes, when router comes back on PC will unpause; if not, the UPS will send the shutdown to the PC. All must be automatic, so I need a reliable script to pause and resume the crunching.
Can it work?

I've got a draft, written with the help of Chat-gpt (forgive me, I'm a total noob...), but the forum for some reason blocks me if I write it. I'll try to put it in the comments.

Thanks for your time

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Tue Nov 25, 2025 11:56 pm
by calxalot
If you have a usb connection to the ups, then you can use the pause on battery feature of the client. The client needs to show has battery true in the machine info panel of web control.

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Wed Nov 26, 2025 2:01 pm
by Tropical Snowman
All the UPS models I've seen do have a usb connection, but I haven't bought it yet and can't really know if it'll show on the Folding client... I don't want to send it back, that's why I wanted to test such a script before buying it. So if it shows, fine; otherwise I'll use the automatic script.

Do you think any UPS with a usb connection will be recognized?

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Wed Nov 26, 2025 6:51 pm
by Joe_H
Whether or not the UPS will show in the client depends entirely on the OS and its settings. There is a standard that most USB connected UPSs follow and that will provide basic controls to the OS. So purchase one from a good brand and it should be recognized.

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Wed Nov 26, 2025 10:31 pm
by Tropical Snowman
Thanks for that advice, but I'm not sure if I have a way to know whether the UPS will be recognized by Folding and BOINC; so I'd like (or better: I need) to plan carefully.
Should I ask the sellers of each UPS I'm considering if they are recognized by Windows 11 as batteries? What do you suggest? They won't know if it's compatible with Folding, so what can I ask specifically?

Also, I'd still like to discuss the original question. Can you help me write such a script? So that I'll have a plan B if Folding doesn't recognize the battery.

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Wed Nov 26, 2025 10:35 pm
by muziqaz
Tropical Snowman wrote: Wed Nov 26, 2025 10:31 pm Thanks for that advice, but I'm not sure if I have a way to know whether the UPS will be recognized by Folding and BOINC; so I'd like (or better: I need) to plan carefully.
Should I ask the sellers of each UPS I'm considering if they are recognized by Windows 11 as batteries? What do you suggest? They won't know if it's compatible with Folding, so what can I ask specifically?

Also, I'd still like to discuss the original question. Can you help me write such a script? So that I'll have a plan B if Folding doesn't recognize the battery.
If you are buying modern, better known brand UPS, it will definitely going to be compatible with popular OSs (windows, Linux and probably Mac). You can always google the potential products you want to buy, and see their spec sheets and product details. I am certain they will mention the compatibility

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Wed Nov 26, 2025 10:36 pm
by calxalot
I can't see how a script will be successful at reading power state if the OS can't.

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Thu Nov 27, 2025 12:10 am
by Tropical Snowman
muziqaz wrote: Wed Nov 26, 2025 10:35 pm If you are buying modern, better known brand UPS, it will definitely going to be compatible with popular OSs (windows, Linux and probably Mac). You can always google the potential products you want to buy, and see their spec sheets and product details. I am certain they will mention the compatibility
They all mention having a software for Windows, but will this mean Folding will recognize them?

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Thu Nov 27, 2025 12:12 am
by Tropical Snowman
calxalot wrote: Wed Nov 26, 2025 10:36 pm I can't see how a script will be successful at reading power state if the OS can't.
Did I miss something?
The script doesn't read power state, but internet connection. In the first post I wrote:
My idea is linking it to the internet connection: when the router shuts off, PC pauses BOINC and Folding.
Can it work?

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Thu Nov 27, 2025 4:11 am
by calxalot
Ah. Missed that from skimming.
I take it the router will not be on UPS?

Your script should use fahctl or lufah to pause folding, rather than sending signals to cores.
I have no idea what BOINC supports.

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Thu Nov 27, 2025 4:14 am
by calxalot
Of course, if fah detects battery, you only need to deal with BOINC, if that.

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Thu Nov 27, 2025 4:16 am
by Joe_H
Forget the script. As long as you use an USB connected UPS that follows the USB standards for HID devices connected to the system you will know whether or not the power is "out". Your router can also be connected to an UPS, and that is actually standard for FIOS connections and cable routers providing phone service.

You may not want to use the provided software for Windows. That has sometimes been reported to interfere with the battery vs. wall power status being available to the F@h client to handle pausing or shutdown. Windows already has the basic settings to start a shutdown if a UPS status is that it is operating off battery instead AC.

Otherwise you possibly could script it, but it would take knowing how to read the power status off the USB connection to the UPS.

P.S. Don't undersize the UPS. Runtime and battery life is very short if you are operating one at over 50% of its VA capacity. That is not the same as watts, typically they are allowing for a power factor in the 0.7 range. Personally I only buy in the 1200-1500 VA range for my systems, smaller units are used for things like my cable modem and router.

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Thu Nov 27, 2025 9:01 am
by Tropical Snowman
calxalot wrote: Thu Nov 27, 2025 4:11 am Ah. Missed that from skimming.
I take it the router will not be on UPS?

Your script should use fahctl or lufah to pause folding, rather than sending signals to cores.
I have no idea what BOINC supports.
Would it look like this?

Code: Select all

function Pause-Folding {
    Write-Log "Pausing Folding..."
    Start-Process "C:\Program Files\FAHClient\fahctl.exe" -ArgumentList "--pause" -NoNewWindow
}

function Resume-Folding {
    Write-Log "Resuming Folding..."
    Start-Process "C:\Program Files\FAHClient\fahctl.exe" -ArgumentList "--fold" -NoNewWindow
}

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Thu Nov 27, 2025 9:13 am
by calxalot
No, fahctl is a python script with no extension.
You need to install python 3.6 or later, and install websocket-client
You should be able to use

Code: Select all

  python --version
to see what you have or be offered python from the MS app store.
Then

Code: Select all

  pip install websocket-client
You will need to create a fahctl.bat file and place it next to fahctl
I believe this ai slop will work:

Code: Select all

@echo off
set "bat_dir=%~dp0"
set "filename=%~n0"
rem Run the Python script with the same name from the same directory
python "%bat_dir%%filename%"

Re: Help writing a script to pause Folding (and Boinc) if power loss and PC runs on UPS battery

Posted: Thu Nov 27, 2025 9:16 am
by calxalot
fold/pause commands do not use dashes.

Code: Select all

fahctl -h