Plugin Fan Controller for Volumio

Installed a cooling fan. Description by link:
https://howchoo.com/g/ote2mjkzzta/control-raspberry-pi-fan-temperature-python
After installing the startup script, PeppyMater stopped working. Can this be fixed?.

I have a large radiator installed:
https://aliexpress.ru/item/1005001727955400.html?gatewayAdapt=glo2rus&sku_id=12000017375874672&spm=a2g0o.order_list.0.0.21efa396BvrOdo
It is not even necessary to install a fan with it. BUT!!!
A hat is installed on top:
https://aliexpress.ru/item/4000002802608.html?gatewayAdapt=glo2rus&sku_id=10000000003220261&spm=a2g0o.order_list.0.0.21efa396BvrOdo
It interferes with the free circulation of air. Gradually, everything around is getting very hot. It is necessary to make a forced movement of air. Therefore, a turbofan from a laptop was installed
https://aliexpress.ru/item/4000820278817.html?mp=1&sku_id=10000008604474092&spm=a2g2w.cart.0.0.ced24aa6XhIwNZ
But not from above. On the side. A 5 volt fan, connected to 3.3 volts. But I donā€™t like the night noise. Therefore, a script was installed, to which I gave a link. Everything became great. The range is 38-60Š” . The fan runs for 3 minutes, then 1 hour of silence.
The only problem is not running PeppyMeter. Software conflict. It is strange that there is no fan control plugin in Volumio

Did a quick check and the problem is that the script reads/act on GPIO status, which breaks peppy_meter. Donā€™t have a quick solution in place. (Placed some test code below in this topic)

Get a silent FAN, so the noise is very low and you donā€™t need to bother on the coding part.

Or get an extension cable, so the hat can be place sideways and you donā€™t need a FAN.

bash script: call_fancontrol.sh

#!/bin/bash
while [ : ]
do
	python3 /home/volumio/script/fancontrol.py
	sleep 15
done

Python script: fancontrol.py

#!/usr/bin/env python3

import subprocess
import time

from gpiozero import OutputDevice


ON_THRESHOLD = 65  # (degrees Celsius) Fan kicks on at this temperature.
OFF_THRESHOLD = 55  # (degress Celsius) Fan shuts off at this temperature.
GPIO_PIN = 22  # Which GPIO pin you're using to control the fan.


def get_temp():
    """Get the core temperature.
    Run a shell script to get the core temp and parse the output.
    Raises:
        RuntimeError: if response cannot be parsed.
    Returns:
        float: The core temperature in degrees Celsius.
    """
    output = subprocess.run(['vcgencmd', 'measure_temp'], capture_output=True)
    temp_str = output.stdout.decode()
    try:
        return float(temp_str.split('=')[1].split('\'')[0])
    except (IndexError, ValueError):
        raise RuntimeError('Could not parse temperature output.')



    # Validate the on and off thresholds
if OFF_THRESHOLD >= ON_THRESHOLD:
    raise RuntimeError('OFF_THRESHOLD must be less than ON_THRESHOLD')

fan = OutputDevice(GPIO_PIN)

    #while True:
temp = get_temp()

        # Start the fan if the temperature has reached the limit and the fan
        # isn't already running.
        # NOTE: `fan.value` returns 1 for "on" and 0 for "off"
if temp > ON_THRESHOLD and not fan.value:
    fan.on()

        # Stop the fan if the fan is running and the temperature has dropped
        # to 10 degrees below the limit.
elif fan.value and temp < OFF_THRESHOLD:
    fan.off()

Maybe this piece will do the trick.

1 Like

Respected Wheaten.Write the order of actions. I donā€™t understand anything about it.
In order:
1.
git clone GitHub - Howchoo/pi-fan-controller: Raspberry Pi fan controller.
2.
sudo apt-get install git
3.
sudo apt install python3-pip
4.
sudo pip3 install -r pi-fan-controller/requirements.txt
5.
./pi-fan-controller/script/install
6.
nano fancontrol.py
7.
#!/usr/bin/env python3

import subprocess
import time

from gpiozero import OutputDevice

ON_THRESHOLD = 60 # (degrees Celsius) Fan kicks on at this temperature.
OFF_THRESHOLD = 37 # (degress Celsius) Fan shuts off at this temperature.
GPIO_PIN = 16 # Which GPIO pin youā€™re using to control the fan.

def get_temp():
ā€œā€ā€œGet the core temperature.
Run a shell script to get the core temp and parse the output.
Raises:
RuntimeError: if response cannot be parsed.
Returns:
float: The core temperature in degrees Celsius.
ā€œā€ā€
output = subprocess.run([ā€˜vcgencmdā€™, ā€˜measure_tempā€™], capture_output=True)
temp_str = output.stdout.decode()
try:
return float(temp_str.split(ā€™=ā€™)[1].split(ā€™ā€™ā€™)[0])
except (IndexError, ValueError):
raise RuntimeError(ā€˜Could not parse temperature output.ā€™)

# Validate the on and off thresholds

if OFF_THRESHOLD >= ON_THRESHOLD:
raise RuntimeError(ā€˜OFF_THRESHOLD must be less than ON_THRESHOLDā€™)

fan = OutputDevice(GPIO_PIN)

#while True:

temp = get_temp()

    # Start the fan if the temperature has reached the limit and the fan
    # isn't already running.
    # NOTE: `fan.value` returns 1 for "on" and 0 for "off"

if temp > ON_THRESHOLD and not fan.value:
fan.on()

    # Stop the fan if the fan is running and the temperature has dropped
    # to 10 degrees below the limit.

elif fan.value and temp < OFF_THRESHOLD:call_fancontrol
fan.off()
8.
sudo mv fancontrol.py /usr/local/bin/
9.
sudo chmod +x /usr/local/bin/fancontrol.py
10.
??? nano fancontrol.shā€¦ or call_fancontrol.sh???
11.
sudo mv fancontrol.sh /etc/init.d/
sudo chmod +x /etc/init.d/fancontrol.sh ā€¦or call_fancontrol.sh???
12.
sudo update-rc.d fancontrol.sh defaults ā€¦or call_fancontrol.sh???

Thanks!

No one was found to do the job to the end.