Newbie - My first automation is not working

Hi All,

I’m very new to this and trying out my very first automation.
Unfortunately I cannot get it to work.

What I’m trying to achieve is, to switch on a GPIO pin on my RPi 3 B+, when the processor temperatur goes above 40c. GPIO pin will drive a npn transistor to power a small fan to cool the RPi heatsink.

This is what I have in my “automations.yaml” file for testing purposes to see at least if I get a message.
But nothing unless I manually run it.

- id: cpu_fan_on
  alias: Turn of CPU fan when temp at 40c
  trigger:
  - platform: numeric_state
    entity_id: sensor.processor_temperature
    above: '40'
  condition:
  action:
  - service: persistent_notification.create
    data:
      message: Your message goes here
      title: Custom subject
  mode: single

Btw, I do not know if this is correct or not, should above: '40' be above: 40 since platform: numeric_state ?
Those quotes are being automatedly added by the automation editor.

  • My RPi 3B+ processor temperature is always above 40c.
  • I have restarted the HS many times after automation changes.
  • Core Version : core-2021.6.4
  • Supervisor Version : supervisor-2021.06.0

Numeric state triggers only change when the threshold is crossed: in this case from below 40 to above 40. If you start it up already above 40, it will not trigger.

1 Like

Thanks @Troon now I understand.
It worked after adding as below and cooling down the temp. below 45 and let it rise again pass 45.

- id: cpu_fan_on
  alias: Turn of CPU fan when temp at 40c
  trigger:
  - platform: numeric_state
    entity_id: sensor.processor_temperature
    above: 45
    below: 55
  condition:
  action:
  - service: persistent_notification.create
    data:
      message: CPU fan is running
      title: CPU Fan
  mode: single

I now see that this way of implementing what I’m trying to achieve is not the correct way, because of the way it trigger → numeric-state works.
I need the fan to run if the temp. is above 45 at any given time. Like when I reboot the host, the cpu temp. is already around 48c (passed my range 45~55). So in this case, fan should run until it goes below 45.
Any thoughts how I could do this with HA OS?
I already tried with RPi OS and Debian buster with Supervisor installed, but those are very unstable and cpu temp. is always very high.
Any idea

Template binary sensor (docs):

template:
  - binary_sensor:
      - name: Hot Raspberry Pi
        state: "{{ states('sensor.processor_temperature')|float > 45 }}"

Automation:

trigger:
  - platform: state
    entity_id: binary_sensor.hot_raspberry_pi
action:
  - service: "switch.turn_{{ trigger.to_state.state }}"
    entity_id: switch.pi_fan_gpio

(assuming you’ve set up the GPIO as a switch)

Alternatively, you can use a generic thermostat:

1 Like

Thanks again @Troon
Generic Thermostat worked like charm for me.

climate:
  - platform: generic_thermostat
    name: CPU cooling fan
    heater: switch.cpu_fan
    target_sensor: sensor.processor_temperature
    ac_mode: true
    target_temp: 40
    cold_tolerance: 0.5
    hot_tolerance: 0
    min_cycle_duration:
      seconds: 5
    keep_alive:
      minutes: 3
    initial_hvac_mode: "cool"
    precision: 0.1
1 Like