Turn_on switch on startup rpi_gpio

Hi,

I connected a fan to my rpi on the GPIO17.
The command from the dashboard works perfectly.
I would like the fan to turn on when HA starts.

switch:
  - platform: rpi_gpio
    switches:
      - port: 17
        name: "Fan Office"
        unique_id: "rpi_fan_switch_port_17"

My fan is defined as a light; I have it start with one minute delay like this:

alias: CPU Fan aan na boot
description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
mode: single
  - service: light.turn_on
    data:
      brightness_pct: 100
    target:
      entity_id: light.rpi_cooling_fan

I guess you would need to use this for the action instead:

  - service: switch.turn_on
    data: {}
    target:
      entity_id: rpi_fan_switch_port_17

Ok,
As your feedback is running,
can you send me your light configuration.

In configuration.yaml:

light:
  - platform: rpi_gpio_pwm
    leds:
      - name: RPI Cooling Fan
        pin: 14

and:

climate:
  - platform: generic_thermostat
    name: RPI Cooling Fan Controller
    unique_id: rpi_cooling_fan_controller
    heater: light.rpi_cooling_fan
    target_sensor: sensor.cpu_temperature
    min_temp: 30
    max_temp: 70
    ac_mode: true
    target_temp: 30
    cold_tolerance: 0.1
    hot_tolerance: 0.1
    min_cycle_duration:
      seconds: 30
    keep_alive:
      minutes: 1
    initial_hvac_mode: "cool"

Didn’t invent that all myself; copied it from a topic here somewhere.

I decided to have your configuration.

But in the dashboard, the fan is in “idle” state !

FAN

Have you an idea ?

Sorry, no. But in your initial post you said it worked through te dashboard as a switch. I would keep that and adjust my automation to start the switch; seems way easier.

alias: CPU Fan aan na boot
description: ""
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
mode: single
  - service: switch.turn_on
    data: {}
    target:
      entity_id: rpi_fan_switch_port_17

should do the trick

Thank you for your reply:

my - platform: rpi_gpio_pwm send Error

2023-07-26 14:34:25.382 ERROR (MainThread) [homeassistant.components.light] Error while setting up rpi_gpio_pwm platform for light
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 353, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/ha-rpi_gpio_pwm/light.py", line 70, in setup_platform
    opt_args["pin_factory"] = PiGPIOFactory(host=led_conf[CONF_HOST], port= led_conf[CONF_PORT])
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/gpiozero/pins/pigpio.py", line 101, in __init__
    raise IOError('failed to connect to %s:%s' % (host, port))
OSError: failed to connect to localhost:8888

So I decided to use rpi_gpio and gpio17 to link climate module.

sensor:
  - platform: command_line
    name: "X CPU Temp"
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°C"
    value_template: "{{ value | multiply(0.001) | round(1)  }}"
    scan_interval: 10


switch:
  - platform: rpi_gpio
    switches:
      - port: 17
        name: "Fan Office"
        unique_id: "fan_office_switch_port_17"

climate:
  - platform: generic_thermostat
    name: rpi Cooling Fan Controller
    unique_id: rpi_cooling_fan_controller
    heater: switch.fan_office             
    target_sensor: sensor.X_CPU_Temp
    min_temp: 30
    max_temp: 70
    ac_mode: true
    target_temp: 30
    cold_tolerance: 0.1
    hot_tolerance: 0.1
    min_cycle_duration:
      seconds: 30
    keep_alive:
      minutes: 1
    initial_hvac_mode: "cool"

Now the climate controleur is running perfectly.

I want to know why rpi_gpio_pwm send an error.

Hi, I solved the error

OSError: failed to connect to localhost:8888

of the rpi_gpio_pwm add-on, simply by installing the Poeschl pigpio add-on (as written in the rpi_gpio_pwm readme) and then restarting HA.
Installing pigpio is done by adding https://github.com/Poeschl/Hassio-Addons into your HA add-ons custom repositories.
I hope it can be useful to someone.