I have Volumio running on a RPi 3B+ with a Hifiberry Amp+ DAC driving some Klipsh AW-400 outdoor speakers mounted on the side of my garage. I live on a corner lot so my garage is a separate building with one wall facing my patio. I also live in the Mojave desert so the garage can get pretty hot in the summer. My RPi started overheating last summer so I set up a fan to cool it.
First, I found a USB powered fan. Not a fan that is charged using USB but powered by it. It also needed to have a goose neck so I could point it at the RPi.
Now, at this point, I could have just left it. The fan would run while the RPi had power. But really. Where's the fun in that? I wanted to be able to turn the fan on and off as needed. I found that the CPU temp is stored at /sys/class/thermal/thermal_zone0/temp. So I figured that I can read it and if the CPU temp gets above 70° C I should turn on the fan because the overtemp warning happens at 80° C. But how can I control the USB ports?
I found the program uhubctl on Github that would do the trick. It is a Linux program that can control smart USB hubs. Fortunately, the RPi has that and it is one the program can handle.
Now all I needed to do was write a program to read the CPU temp and flip the USB port as needed. I created a Bash script that would do it and then added it to cron so that it runs every 5 minutes. Here's what the setup looks like:
IMG_3479.png (399.77 KiB) Viewed 122 times
Kind of ugly but it works well. The cover is off the RPi so the fan can blow into it. The white cables are the speaker wires.
If you're interested, here are my full set up instructions.