Controlling cooling fan for Raspberry Pi 4

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

Just updated Home Assistant and the fan shim has stopped working, just on all the time.
My setup is the same as the original. Any idea’s of what should be changed?

EDIT: Just installed the HACS source and all wroking again. Thanks

1 Like

I have been trying to reconfigure the Yaml code but really struggling to get the fan working again, would you be able to share your updated Yaml code for this?

You don’t need any other yaml code. Install custom rpi gpio integration over HACS.

I did have it with a sensor though, and on a thermostat card, see attached. Now the fan is always on, day and night, this card no longer works. Yaml code is:

climate:
  - platform: generic_thermostat
    name: 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: 50
    cold_tolerance: 0.1
    hot_tolerance: 0.1
    min_cycle_duration:
      seconds: 30
    keep_alive:
      minutes: 5
    initial_hvac_mode: "cool"

Any ideas?
Screenshot 2022-07-14 at 18.27.35|550x500

Update rpi gpio to version 2022.7.0.
If there is a problem, restart the host

Check this post for updated code (older syntax commented)…

Thanks for the info, I really do struggle getting my head around things like this.

I have updated the code: See Below, but it doesn’t appear to have made any difference to the fan, it is still running constantly.

  - platform: rpi_gpio
    switches:
      - port: 18
        name: "RPi Cooling Fan"
        unique_id: "rpi_cooling_fan" 
climate:
  - platform: generic_thermostat
    name: 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: 50
    cold_tolerance: 0.1
    hot_tolerance: 0.1
    min_cycle_duration:
      seconds: 30
    keep_alive:
      minutes: 5
    initial_hvac_mode: "cool"

Am I doing something wrong here?

Make sure you’re also using gpio 18.
50C may be a lil’ too low.

Does the switch actually work? Try to manually turn off the fan by using the switch.

The coding seems right,but maybe there’s a problem with your fan/shim/circuitry.