Controlling cooling fan for Raspberry Pi 4

What would be a nice temperature range for the processor of the RPI?

Its done. I followed a link earlier in this thread how to wire it. GPIO 18 (pin12) as switch on a transistor switching the fan on and off. Added a blue led which lights when it is running.


Looking good Ed :grinning:

I have my Pi4 in a Flirc case so passive cooling but I did drill a hole in the top for an Led so show if the water temperature in our tank is hot enough for a shower.

Very neat that Flirc case!

I’m trying Pyscripter from the HACS repositories as an alternative. It’s actually a complete Python environment that lets you import modules like RPi.GPIO. It is quite simple to setup and use.

I can now manipulate the GPIO pins reading and writing. Unfortunately I can’t get the PWM module to work. It seems to work and generates no errors, but there is no output.

I will try to use pigpio in this environment next.

Thanks, but I think I’ll use https://github.com/thecode/ha-rpi_gpio.
It’s the code currently in HA refactored to use HACS.

I managed to get pigpio working with PWM.
My findings and test scripts are documented here : https://github.com/paulvee/Home-Assistant

2 Likes

The ha-rpi_gpio implementation is very limited to only reading and writing to GPIO ports and with only one event to be used as a trigger. The developers mention that they will add PWM soon though…

Thanks for this, itsvery useful

Hi!

I have HACS successfully installed already. Can anyone explain how I disable the built in integration and install the HACS one (I know how to install the HACS one but I don’t understand how I “remove” the original integration?

Thanks!
James

If you mean rpi gpio, you don’t have to delete anything. It will be removed in version HA 2022.6

Ok, so can I just install this one now and temporarily have both?

Yes you can have both. I use it that way.

Have a pimoroni fan shim set up using native gpio support.
When adding the HACS gpio support and trying to set it up I discovered that the fan had actually crashed (no spinning at all).

Have extra plain cheap fans around (got all the spare parts /parts list available), was wondering if building this circuitry would actually work in the present config out of the box.

Also kindly check if my ‘translation’ from built-in gpio to HACS gpio is correct:

# Raspberry Pi Cooling Fan
sensor:
  - platform: command_line
    name: CPU Temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(1) }}'
    scan_interval: 10

# HA way to be deprecated 2022.6
#switch:
#  - platform: rpi_gpio
#    ports:
#      18: RPI Cooling Fan

# HACS RPi-gpio integration
  - platform: rpi_gpio
    switches:
      - port: 18
        name: "RPi Cooling Fan"
        unique_id: "rpi_cooling_fan" 

climate:
  - platform: generic_thermostat
    name: RPI Cooling Fan Controller
    unique_id: rpi_cooling_fan_controller
    heater: switch.rpi_cooling_fan
    target_sensor: sensor.cpu_temperature
    min_temp: 40
    max_temp: 80
    ac_mode: true
    target_temp: 55
    cold_tolerance: 0.1
    hot_tolerance: 0.1
    min_cycle_duration:
      seconds: 120
    keep_alive:
      minutes: 3
    initial_hvac_mode: "cool"
 

Kindly note the commented yaml (native gpio) was working fine when last tested (I’m guessing the shim problem is actually a mechanical fan issue).

Many thanks for your time and expertise.

Edit: solved!
Circuitry in the link (npn+resistor) does the same as the fan shim.
My yaml is correct and works as intended via HACS gpio integration.

1 Like

I have a problem since they deprecated and removed the pigpio Daemon PWM LED component I was using for the PWM fan using the following code with python scripts and the pigpio add-on could handle it perfectly.

light:

platform: rpi_gpio_pwm
led:
name: RPI cooling fan
pilot: gpio
pins: [18]
type: simple
Enable Python scripts
python_script:

Do you have any advice for me to be able to still use the pwm fan of my Geekworm NASPi 2.5 "SATA HDD / SSD NAS Storage Kit for Raspberry Pi 4 B
Thanks a lot to everyone

I have the same case for my setup and the code is still working. There is no pwm control but the fan is starting above set temperature and stoping below it.

Which Parameter defines how long the fan spins, before it stops again?

Hi, could someone help me add these codes to the YAML configuration?

I’m new to HA and I don’t really know how to do it.

I downloaded the add-on file editor. When you open a new folder you can select configuration.yaml. But then it automatically selects a entitiy. How to do this?

PS: I’m using the normal Pi case fan (with the heatsink) which applies to the original case.

Edit: I think I managed to get it work. I selected port 14 instead of 18 and now the fan is off. Could someone verify this? Am I doing something wrong?

Raspberry Pi GPIO has been now removed from 2022.6
Does anyone have an idea how to control the fan without rpi_gpio?

Use this repository (installed via HACS), does the same. Minor changes to yaml syntax but works fine.

1 Like