Original write
My pi is connected to an external drive. 4tb. With all this space i’m running a torrent client. Thing is, it keeps the HDD running pretty much all the time. And it makes a bit of noise. Also, because the torrent is running, my pi’s temperature is raising. So i installed a fan on it. The fan has no control on it. Only two wires, for power and ground. I would need a third to be able to control the rpm of it via gpio. i’ll get there soon.
Every night before sleep i pause all my torrents and turn off the fan by removing the power wire. And every morning starting it back up. It’s kinda tedious :))
So i’ve been looking up how i can automate it. I’m running qbittorent and so far i’ve not been able to find a way to pause the torrents on schedule. There is a request from 2018 still open. So no luck on that front. Searched if i can use an api call or some url i can call to pause all torrents. Nope, although i found a project that’s a web ui for various torrent client and in the code found something that i thought would work. The client is pretty neat, and looks nice. But nope, i can’t figure out a way to stop/start my torrents in qbittorrent.
And then i thought about starting the whole service with systemctl. And how to better automate it than with a cronjob.
So half of my issue is solved with these 2 lines
0 22 * * * /usr/bin/systemctl stop qbittorrent.service
0 09 * * * /usr/bin/systemctl start qbittorrent.service
And that gets rid of the noise from the HDD.
Now, for the fan, i ordered a 2N222 transistor which i’ll use on my fan and then setup a script to shut it down.
I’ll get back to you on that :)
▶ I rewrote the above section with chatGPT. Click if you’re curious
Rewrote with chatgpt
My Raspberry Pi is currently connected to an external hard drive with a capacity of 4 terabytes. Although it provides ample storage space, I’ve encountered a couple of issues. Firstly, the torrent client I’m running keeps the hard drive constantly active, resulting in noticeable noise. Additionally, the Pi’s temperature rises due to the torrent activity, prompting me to install a fan for cooling. Unfortunately, the fan lacks any control mechanism and is limited to only power and ground connections. To regulate its speed through GPIO, I need an additional wire, but I’ll address that soon.
Every night before going to bed, I manually pause all my torrents and turn off the fan by disconnecting the power wire. In the morning, I have to restart everything again. It has become a rather tedious routine :))
Consequently, I’ve been researching ways to automate these processes. Specifically, I’ve been using qbittorent as my torrent client, but I haven’t found any built-in scheduling options to pause the torrents. There’s a longstanding open request from 2018, so no luck on that front. I also explored the possibility of using an API call or a specific URL to pause all torrents, but my searches yielded no results. I did stumble upon a web UI project for various torrent clients that seemed promising, but unfortunately, I couldn’t find a way to stop or start my torrents using qbittorent.
That’s when I considered starting the entire service using systemctl, and what better way to automate it than with a cronjob?
I managed to resolve half of my issue with these two lines:
0 22 * * * /usr/bin/systemctl stop qbittorrent.service
0 09 * * * /usr/bin/systemctl start qbittorrent.service
These lines effectively eliminate the noise caused by the hard drive.
As for the fan, I’ve ordered a 2N222 transistor that I plan to use to control its operation. Once I set it up, I’ll provide an update on the progress.
I’ll keep you posted on that :)
Also this script
#!/usr/bin/env python3
import sys
import time
import subprocess
import signal
import atexit
from gpiozero import PWMLED
# Define the GPIO to control the transistor's B pin
fan = PWMLED(21)
# CPU temperature threshold (in Celsius)
TEMP_THRESHOLD = 55
def get_cpu_temperature():
# Use subprocess to run the 'vcgencmd measure_temp' command to get CPU temperature
result = subprocess.run(['vcgencmd', 'measure_temp'], capture_output=True, text=True)
temperature_str = result.stdout.strip()
temperature = float(temperature_str.replace("temp=", "").replace("'C", ""))
return temperature
def log_to_journal(message):
subprocess.run(f'echo "{message}" | systemd-cat', shell=True)
def cleanup():
fan.value = 0
def main():
atexit.register(cleanup)
def handle_signal(signum, frame):
sys.exit(0)
signal.signal(signal.SIGTERM, handle_signal)
signal.signal(signal.SIGINT, handle_signal)
while True:
current_hour = time.localtime().tm_hour
# print(current_hour)
cpu_temperature = get_cpu_temperature()
# log_to_journal(cpu_temperature)
# log_to_journal(fan.value)
if (8 <= current_hour < 23) or (23 <= current_hour and cpu_temperature > TEMP_THRESHOLD):
# print()
fan.value = 1
else:
fan.value = 0
time.sleep(60) # Sleep for 1 minute
if __name__ == '__main__':
main()
Insert image with the build here
- also i need to solder it. never did this before.