Controlling cooling fan for Raspberry Pi 4

Thanks aszxc, I’ll give it a go…

Regards,

Bob…

Sorry, I’m new to all this how do I get the integration GPIO , can’t find it on Add Integrations.

Regards,

Bob…

I’ve been seeing posts like this forever and for the life of me I can’t figure out why people are obsessed with controlling that fan and it’s speed from HA… sometimes the best way to create smart home devices and services is to keep things simple and adding layers of automations and third part add-ons from HACS is the opposite of keeping it simple. Atleast for me, I want my pi to run as cool as I can and remove any heat that’s generated. I’m not interested in spinning up the fan to 30% because because the temperature rose X degrees and then turning it off at Y degrees. A full size hestsink with a fan for the pi4, they’re like 9$. There’s no reason to overcomplicate this and add additional failure points. Let the dang fan run and do its job, period. That 9$ fan of mine had been chugging along and doing its thing over a year now. Live your life people. Don’t waste it by stressing over spinning up and down a little 5v fan…

1 Like

Hi aszxc,

I managed to load HACS and install the RPI GPOI integration and that has fixed the HA error.

Thanks again for pointing me in the right direction.

Not sure why HA has to be so hard to work with…

Regards,

Bob…

I am also new to using HA. I’m sure everything will get easier when we use it more :slight_smile:

1 Like

Hey!

I am trying to get PWM working using you’r PWM .py script, but can’t really get it working.
I have added Pyscript in HASS, created a folder under config and added you’r files there, and changed port 17 to my port 14, but the fan only goes at 100%…

Any suggestions?

Justin: Go all the way to the top of this thread and read- The thread got off the rails a bit. The issue that started the conversation is those of us with a SupTronics x735 Power supply/cooling fan add on board - the fan would never run. Why? This is due to the SupTronics board needing a script to operate. That script can not be installed depending on your HA implementation. If owners of the x735 board want cooling, then this thread deals with the method to achieve that function.
Bottom line - read the thread

Does this code PWM the fan speed depending on temperature or is it just turning the fan on to max or off depending on the set temperature?

i have built the circuit in the below link and i would prefer if the fan could be adjusted depending on temperature. so it only turn on slow if the temp is just above the set. temp and then rev up if needed.

Thank you!

I am using a Raspberry Pi 4B with the 52Pi’s Ice Tower 4010 cooling fan (ZP-0139).This worked great after a few modifications.
First of all, rpi_gpio is no longer supported in the core version. So, I installed ha-rpi_gpio via HACS.
Afterwards, I changed the configuration for the switch to this:

switch:
  - platform: rpi_gpio
    switches:
      - port: 14
        name: rpi_cooling_fan

Note the new format and note that I used port 14 as per the instruction manual for the cooling fan.

After rebooting the system, I added a lovelace card for another Climate controller. It worked like a champ. My pi runs cool already, so to test it out, I pointed a hair dryer at it until it passed 55°C. Sure enough, the fan kicked on. It went off once the temp dropped below 55°C.

I need help… It will not work!

HACS installed
GPIO by HACS installed
Fan is running on permanent 3V and 5V but not on GPIO 14
I tried GPIO 14 and 18
It seems, that the switch is automaticly working in HA at temperature 50

What am I doing wrong?

switch:
  - platform: rpi_gpio
    switches:
      - port: 14
        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: 50
    cold_tolerance: 0.5
    hot_tolerance: 0.5
    min_cycle_duration:
      seconds: 120
    keep_alive:
      minutes: 5
    initial_hvac_mode: "cool"
2 Likes

Hi there,

sorry for the stupid question, but I would be very happy if you could tell me how did you build the “RPI Cooling Fan Controller” lovelace card.

Thank you!

KR
Rok

I made the card about 2 years ago and it still working. I will copy the yaml of the cards for you and then we take it from there.

1 Like

type: vertical-stack
title: RPI Cooling Fan
cards:
  - show_name: false
    show_icon: true
    type: button
    tap_action:
      action: toggle
    entity: switch.rpi_cooling_fan
    icon_height: 36px
    show_state: true
    icon: mdi:fan
  - type: custom:mini-graph-card
    entities:
      - entity: sensor.processor_temperature
    show:
      extrema: true
      average: true
      labels: true
    name: Processor Temperature
    font_size_header: 20
    color_thresholds:
      - value: 50
        color: '#008000'
      - value: 60
        color: '#FF0000'
    hours_to_show: 24
    points_per_hour: 60
    update_interval: 10
    lower_bound: 40
    upper_bound: 65
    line_width: 3
    height: 150
    smoothing: false
    hour24: true
  - type: history-graph
    entities:
      - entity: switch.rpi_cooling_fan
        name: ' '
    hours_to_show: 24
    refresh_interval: 0
  - type: thermostat
    entity: climate.rpi_cooling_fan_controller

Hi,

thx for the quick reply, it was my typo that didn’t start the configuration.yaml, everything is ok now with the card :slight_smile: , but I do have one Issue…

I’m using a basic “pi fan” with 3 cables, it works without a problem when I’m using rapbian - I have following “pins” connected:

Red: pin 4 (5V)
Black: pin 6 (GND)
Blue: pin 8 (GPIO 14)

But the Fan doesn’t start, even if I move the blue wire to pin 12 (GPIO 18) it doesn’t start. As soon as I remove the blue wire the fan is pinning.

Thanks for your help!

KR
Rok

Well from the top of my head the gpio14 is the switch pin ‘switching’ the transistor on and off. It logical the fan runs when ground and 5v are connected. To switch the fan on and off you have to make gpio14 the switch pin.

1 Like

Hi,

thx for your help! I’ve changes it to 18 and not it works :slight_smile: ! I’m still a big noob in HA configs, so that’s why my questions my sound weird or simple :rofl: :man_facepalming:

KR
Rok

Seems this doesn’t work for 2 wire fan, not enough power in GPIO.

I am not getting an CPU sensor in entities though, so I can only trigger by toggling the switch and not by temperature. Any idea what I can do?

Hi Alex. It should work for 2 wires fan because mine are 2 wires fans.

The set-up is to connect the positive to either the 3.3V or if that is not enough to a 5V pin.
The other wire should be split by a transistor with the center connection to a switching GPIO.

There is in the thread a good description how to set it up exactly. https://www.instructables.com/PWM-Regulated-Fan-Based-on-CPU-Temperature-for-Ras/ Follow that. That should do it.

WRT temperature. What are you using as setup? A Rasberry?

Thanks, I found a cheap controller online so have bought that.

On CPU temp, Raspberry Pi 4, I was looking at the wrong code, I finally found a post with the correct code and it worked.

Not working:

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

Working:

command_line:

  • sensor:
    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
1 Like