Raspberry Pi CPU Fan Automation

Yup, using a simple switch:

# GPIO switch for the case fan
  - platform: rpi_gpio
    ports:
      14: CPU Fan

With the control wire of the fan connected to the GPIO #14

Then a couple of simple automations to turn it on and off:

alias: 'Fan Off 52C '
description: Turns the fan on if the CPU < 52C
trigger:
  - platform: numeric_state
    entity_id: sensor.cpu_temp
    for: '60'
    below: '52'
condition: []
action:
  - service: switch.turn_off
    entity_id: switch.cpu_fan
mode: single
alias: Fan On 70C
description: Turns the fan on if the CPU > 70C
trigger:
  - platform: numeric_state
    entity_id: sensor.cpu_temp
    above: '70'
    for: '60'
condition: []
action:
  - service: switch.turn_on
    entity_id: switch.cpu_fan
mode: single

CPU temp comes from this sensor:

# CPU temperature, for fan
  - platform: command_line
    name: CPU Temp
    command: "/bin/cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°C"
    value_template: '{{ (value | int / 1000) | int }}'

1 Like