Controlling cooling fan for Raspberry Pi 4

Hi, I am new to HA… Can I please ask you where exactly have you added the scripts? I can see that following that link ( [geekworm-repository](https://x735-v2.5/pwm_fan_control.py at 8f170d6bc964eb58f6cc97a01371ab60a4fa24c5 · geekworm-com/x735-v2.5 · GitHub)) there are 2 scripts: one for the on/off button and one for the fan. I would like to add them both, but I am struggling to understand where I should paste them. Can I have some help, please? cheers,

You don’t need scripts. Shutdown works natively. You control the fan according to the CPU temperature. Create a CPU temperature sensor, create a generic thermostat and enable in Rpi GPIO 13 and it works well on the X735-v2.5 board.

1 Like

Hi @pepe59, htank you for your reply!.. so you say that I can just put it on and it should shut down if I press the button? and that as soon as I make an automation on GPIO 13 for PWM control it is fine??

Yes, I use the same board mounted on the Rpi4 8Gb.
The shutdown button works without configuration and script
Everything has been working reliably for several months.
Add a CPU temperature sensor, GPIO switch and generic thermostat to the configuration.yaml. Adjust the values at your discretion

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


switch:
  - platform: rpi_gpio
    ports:
      13: RPI Ventilátor

climate:
  - platform: generic_thermostat
    name: RPI Chlazení
    heater: switch.rpi_ventilator
    target_sensor: sensor.teplota_cpu
    min_temp: 45
    max_temp: 75
    ac_mode: true
    target_temp: 60
    cold_tolerance: 0.1
    hot_tolerance: 0.1
    min_cycle_duration:
      seconds: 150
    keep_alive:
      minutes: 5
    initial_hvac_mode: "cool"

It does not control the fan speed only on / off

2 Likes

Thank you man! you have been super helpful! I just tried the switch and it works super fine! but I do have another question! it seems that it only has the hard reboot when I press it for long time an da 1 or 2 sec press is not doing anything. Am I doing something wrong??

I think it works the same way here. I have to hold down the button longer to turn off the system and only briefly to turn it on.
I don’t remember it anymore and I don’t want to try it on a running system where automation works now

1 Like

well, I think I will just stick to your wise suggestions man! thank you!!

This works a treat with the Geekworm NASPi case I’ve just installed.

Thank you!

Is anyone running this on a Raspberry Pi 4 with a Supervised HA install on Debian 11 (Bullseye)?

While the fan (official RPi case fan) runs fine, I had all kinds of trouble trying to access the GPIO. I only managed to do it after installing gpiod and using gpioset. The ‘switch’ code had to be updated to a command_line switch that runs gpioset (via ssh to the localhost) to turn the fan on/off.

Have I missed something that makes the GPIO work correctly in HA under Debian?

One remaining problem is that I can’t get the status of the fan pin (GPIO18), so can’t make a toggle switch for it: gpioget always sets the pin high (turning on the fan) before it reads it.

Hmm, I’ve been using this approach for a while now, and it works well.
However I have just seen the Raspberry Pi GPIO support will be deprecated and removed form HA 2022.6 - see here.

Looks like we have a few months to come up with an alternative solution.

I am assuming we can grab the code now, and prepare to run it as a custom integration.

Any other suggestions?

Hopefully this will work

Thanks, but it would not work for me, as it relies on using hass.io, whereas I’m using HA core in a Python venv.

Thanks so much for this. I’ve been using this to control my fan shim for years. I do worry about how we’re going to control the RPI 4 temperatures after the removal of RPI GPIO in V 2022.2.6.
Any thoughts on how we’ll be able to use the fan shim afterwards anyone?

There is now a custom integration in HACS that can be installed to replace the deprecated integration.

Raspberry Pi GPIO.

1 Like

Is this support seriously being removed for rpi gpio in home assistant?
A year ago I rebuild the entire heating system I my house using these io ports. It works perfect with
switch:

  • platform: rpi_gpio
    ports:…

and

climate LivingRoom:

  • platform: generic_thermostat
    name: LivingRoom
    heater: switch.a3_floorheat_livingroom
    target_sensor: sensor.velux_sensor_temperature…

I even sold the idea to one of my colleges so now Im kind of in troubles!
What can I do to keep this working going forward?

1 Like

If you are running HACS you can install this custom component by adding this repository to HACS

GPIO

or do it via the manual method also listed on that link.

1 Like

Is there a pin which can be controlled and delivers 5V

No, GPIO digital input/output pins are 3.3v. The 5v pins on the GPIO are directly connected to the USB 5v rail.

Thanks Neil! So I have to resolve this with a transistor.

Yes, nice big power transistor :wink: