When you are using Home Assistant OS on a Raspberry Pi, you may want to control the cooling fan to keep the temperature in check. This guide will show you how to set up fan control for your Raspberry Pi using Home Assistant.


Configure Fan Control on an official raspbery pi fan case

First, you need to enable advanced mode in Home Assistant. You can do this by going to your user profile in the Home Assistant interface and toggling the "Advanced Mode" switch. Then you can edit the configuration files directly from the Home Assistant interface or use the File Editor add-on. For more information, you can refer to https://www.home-assistant.io/docs/configuration and https://siytek.com/how-to-install-the-home-assistant-file-editor.

Then check your configuration file path by going to Settings > System > Repairs > Click 3 dots on the top right corner > System information. Then find Configuration directory info, it should be something like /config which is the default path for Home Assistant OS.

After your File Editor is installed, you can start and navigate to the File editor page, then click folder icon on the top left corner to open the file browser. Please ensuire the directory is same as the Configuration directory info you found in the previous step. And then create a new file named configuration.yaml if it does not exist, or edit the existing one. Then paste the following configuration into the file:

# 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
switch:
  # Have been removed from Home Assistant core,
  # you need to install it as an add-on from HACS(Home Assistant Community Store)
  - platform: rpi_gpio
    switches:
      # You can change to another GPIO pin if you use a different one to control the fan
      - port: 14
        name: "RPI Cooling Fan"
climate:
  - platform: generic_thermostat
    name: RPI Cooling Fan Controller
    heater: switch.rpi_cooling_fan
    # The original post used `sensor.cpu_temperature` but it seems not available in 2025.6.3 core version.
    target_sensor: sensor.system_monitor_processor_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: 30
    keep_alive:
      minutes: 5
    initial_hvac_mode: "cool"

Refer from https://community.home-assistant.io/t/controlling-cooling-fan-for-raspberry-pi-4/137631

Then you need to install raspberry pi GPIO library as it have been removed from the Home Assistant core (mine is 2025.6.3) by using HACS (Home Assistant Community Store). If you don't have HACS installed, you can follow the guide from https://hacs.xyz/docs/use/.