RPI4 fan control

I installed the latest HAOS on my raspberry pi 4.

On my raspberry pi 4 I have the official fan, which is very loud so I want to be able to configure the speed so it only run fast when is above 80°C and the rest of the time is quiet. Installing Raspberry Pi Os is possible to configure it like this, so I imagine this souble be doable in HAOS as well

I tried looking for addons, settings, everywhere but I found nothing useful. I’m using the GPIO 14 for the fan if that helps

2 Likes

Look at using this.

3 Likes

Thanks Adam, I finally made it work!

After installing the addon you told me I had to add this config

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"
6 Likes

where are you adding that config? is it possible to do it from the GUI, or just from SSH?

/homeassistant/configuration.yaml via HA and File editor

I’ve added this and can trigger the fan by the switch. However, I cannot find a CPU temp in entities and don’t think my CPU temp is being read. Any way to check? Thanks.

You need to add it to your configuration.yaml

@at9 Hi, i have been following exact same config but in my case nothing is happening in the way that my fan keeps turning no matter if i switch it off with switch platform or not. It seems the pin 18 that i am using is not “sending” any info to cut the power form pin +5v…

Here is my code:

switch:
  - platform: rpi_gpio
    switches:
      - port: 18
        name: "Fan Office"
        unique_id: "fan_office_switch_port_18"

any help would be so much helpful :slight_smile:

I don’t actually use the GPIO pins I just have my fan running all the time.

If I was to troubleshoot it though are you using pin 18 or GPIO 18 as they are not the same?
And also try a different pin to see if that one works.

1 Like

Are you use Home Assistant OS?

If no hardware sensor data is available (e.g., because the integration runs in a virtualized environment), the sensor entity will not be created.

from here.

  • My official Raspberry PI 4 Case fan is not running.
  • The Case Fan is connected like this:

I Lead I Colour I GPIO pin I

I 5v I RED I 4 I

I Ground I BLACK I 6 I
I GPIO 14 I BLUE I 8 I

  • Raspberry Pi GPIO is installed.
  • The cards in the overview are running
  • configuration.yaml includes:
sensor:
  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /config
      - type: memory_free
      - type: memory_use_percent
      - type: swap_use_percent
      - type: processor_temperature
      
      # Raspberry Pi Cooling Fan


switch:
  - platform: rpi_gpio
    ports:
      14: RPI Cooling Fan

      
climate:
  - platform: generic_thermostat
    name: RPI Cooling Fan Controller
    heater: switch.rpi_cooling_fan
    target_sensor: sensor.system_monitor_prozessortemperatur
    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"

Can anyone help?

Thanks in advance

The radiator was broken. I replaced this. Now everything is going perfectly.

This thread is awesome, thank you so much @Saphyel for the config, works a treat, my CPU no longer overheats when building new firmwares for ESPHome. :slight_smile:

For others, rather than using “System monitor” to get the CPU temp, I use Glances add-on as I already had it installed for something else… the temp monitoring on it appears (for me at least) to be more precise than System monitor which appeared to have quite some variation in temperature compared.

Just in case

You need to use HACS as well to use this

Hi,

I installed Raspberry Pi GPIO and added this config to configuration.yaml
but the fan still running laud without any change.

any help ?!