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

Moderators: Site Moderators, FAHC Science Team

Tropical Snowman
Posts: 21
Joined: Sat Oct 18, 2025 2:08 pm

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

Post 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
calxalot
Site Moderator
Posts: 1719
Joined: Sat Dec 08, 2007 1:33 am
Location: San Francisco, CA
Contact:

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

Post 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.
Tropical Snowman
Posts: 21
Joined: Sat Oct 18, 2025 2:08 pm

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

Post 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?
Joe_H
Site Admin
Posts: 8270
Joined: Tue Apr 21, 2009 4:41 pm
Hardware configuration: Mac Studio M1 Max 32 GB smp6
Mac Hack i7-7700K 48 GB smp4
Location: W. MA

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

Post 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.
Image
Tropical Snowman
Posts: 21
Joined: Sat Oct 18, 2025 2:08 pm

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

Post 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.
muziqaz
Posts: 2231
Joined: Sun Dec 16, 2007 6:22 pm
Hardware configuration: 9950x, 9950x3d, 7950x3d, 5950x, 5800x3d
7900xtx, RX9070, Radeon 7, 5700xt, 6900xt, RX550, Intel B580
Location: London
Contact:

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

Post 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
FAH Omega tester
Image
calxalot
Site Moderator
Posts: 1719
Joined: Sat Dec 08, 2007 1:33 am
Location: San Francisco, CA
Contact:

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

Post by calxalot »

I can't see how a script will be successful at reading power state if the OS can't.
Tropical Snowman
Posts: 21
Joined: Sat Oct 18, 2025 2:08 pm

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

Post 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?
Tropical Snowman
Posts: 21
Joined: Sat Oct 18, 2025 2:08 pm

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

Post 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?
calxalot
Site Moderator
Posts: 1719
Joined: Sat Dec 08, 2007 1:33 am
Location: San Francisco, CA
Contact:

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

Post 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.
calxalot
Site Moderator
Posts: 1719
Joined: Sat Dec 08, 2007 1:33 am
Location: San Francisco, CA
Contact:

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

Post by calxalot »

Of course, if fah detects battery, you only need to deal with BOINC, if that.
Joe_H
Site Admin
Posts: 8270
Joined: Tue Apr 21, 2009 4:41 pm
Hardware configuration: Mac Studio M1 Max 32 GB smp6
Mac Hack i7-7700K 48 GB smp4
Location: W. MA

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

Post 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.
Image
Tropical Snowman
Posts: 21
Joined: Sat Oct 18, 2025 2:08 pm

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

Post 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
}
calxalot
Site Moderator
Posts: 1719
Joined: Sat Dec 08, 2007 1:33 am
Location: San Francisco, CA
Contact:

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

Post 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%"
calxalot
Site Moderator
Posts: 1719
Joined: Sat Dec 08, 2007 1:33 am
Location: San Francisco, CA
Contact:

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

Post by calxalot »

fold/pause commands do not use dashes.

Code: Select all

fahctl -h
Post Reply