Help with Raspberry Pi 4 GPIO

I try to use raspberry pi GPIO to controller fan that cooling raspberrypi pi

I used

and

No one work

Home Assistant 2023.9.0
Supervisor 2023.08.3
Operating System 10.5
Frontend 20230906.1 - latest

Thanks

You don’t need MQTT IO to control the fan on/off
What kind of fan do you have?
Your yaml code in configuration?

You don’t need MQTT IO to control the fan on/off … .? So what i need ?

What kind of fan do you have? … 5v dc fan through transistor

Your yaml code in configuration?
For MQTT IO

mqtt: 
  host: localhost 
  port: 1883 
  user: add-on_mqtt-io
  password: XXXXXXXXXXX
  topic_prefix: mqtt-io
  status_payload_running: available 
  status_payload_stopped: unavailable 
  status_payload_dead: unavailable
  ha_discovery: 
    enabled: yes

# GPIO 
gpio_modules: 
  # Use the Raspberry Pi built-in GPIO 
  - name: rpi
    module: raspberrypi 

digital_outputs: 

  - name: intake_fan 
    module: rpi 
    pin: 23
    initial: low
    ha_discovery: 
      name: Intake Fan 
      device_class: fan
      component: fan

  - name: exhaust_fan 
    module: rpi 
    pin: 24
    ha_discovery: 
      name: Exhaust Fan 
      device_class: fan
      component: fan
      

    

I get this issues

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service base-addon-banner: starting
-----------------------------------------------------------
 Add-on: MQTT IO
 Expose GPIO modules and digital sensors via MQTT for remote control and monitoring.
-----------------------------------------------------------
 Add-on version: 0.2.1
 You are running the latest version of this add-on.
 System: Home Assistant OS 10.5  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2023.9.0
 Home Assistant Supervisor: 2023.08.3
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
s6-rc: info: service base-addon-banner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service base-addon-log-level: starting
s6-rc: info: service fix-attrs successfully started
Log level is set to INFO
s6-rc: info: service base-addon-log-level successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service mqtt-io: starting
s6-rc: info: service mqtt-io successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
[13:02:35] INFO: Starting MQTT IO...
2023-09-08 13:02:42 mqtt_io.__main__ [ERROR] MqttIo crashed!
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/mqtt_io/__main__.py", line 107, in main
    mqtt_gpio.run()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 1241, in run
    self._init_digital_outputs()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 453, in _init_digital_outputs
    gpio_module.setup_pin_internal(PinDirection.OUTPUT, out_conf)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/gpio/__init__.py", line 208, in setup_pin_internal
    return self.setup_pin(
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/gpio/raspberrypi.py", line 56, in setup_pin
    self.io.setup(pin, direction, pull_up_down=pullup, initial=initial_int)
RuntimeError: No access to /dev/mem.  Try running as root!
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.10/site-packages/mqtt_io/__main__.py", line 115, in <module>
    main()
  File "/usr/lib/python3.10/site-packages/mqtt_io/__main__.py", line 107, in main
    mqtt_gpio.run()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 1241, in run
    self._init_digital_outputs()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 453, in _init_digital_outputs
    gpio_module.setup_pin_internal(PinDirection.OUTPUT, out_conf)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/gpio/__init__.py", line 208, in setup_pin_internal
    return self.setup_pin(
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/gpio/raspberrypi.py", line 56, in setup_pin
    self.io.setup(pin, direction, pull_up_down=pullup, initial=initial_int)
RuntimeError: No access to /dev/mem.  Try running as root!
[13:02:42] INFO: Service MQTT IO exited with code 1 (by signal 0)
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service mqtt-io: stopping
s6-rc: info: service mqtt-io successfully stopped

also that report

For ha-rpi_gpio

- platform: rpi_gpio
  switches:
    - port: 27
      name: "Fan 1"
    - port: 28
      name: "Fan 2"
    - port: 29
      name: "Fan 3"
    #
    - port: 23
      name: "Ha LED Red"
    - port: 24
      name: "Ha LED Green"
    - port: 25
      name: "Ha LED Blue"

VCC, GNG and PWM power supply fan.
Custom HA-Rpi_gipo integration
Join Rpi4.
I have it wired according to the yaml code in the configuration

switch:
  - platform: rpi_gpio
    switches:
      - port: 13
        name: "RPI ventilátor"
        unique_id: "rpi_ventilator_switch_port_13"
climate:
  - platform: generic_thermostat
    name: RPI Chlazení
    unique_id: termostat_rpi_chlazeni
    heater: switch.rpi_ventilator
    target_sensor: sensor.teplota_cpu
    min_temp: 45
    max_temp: 75
    ac_mode: true
    target_temp: 60
    cold_tolerance: 0.1
    hot_tolerance: 0.1
    min_cycle_duration:
      seconds: 150
    keep_alive:
      minutes: 5
    initial_hvac_mode: "cool"
1 Like

@pepe59 thanks thats work for me

hello!
i did exaclty the same but mine is not working. question is : which kind of installation do you have? HAos or Core?
could you please explain this : VCC, GNG and PWM power supply fan.
i assume you have a 3 wires fan so you have connected red wire to rpi 5v, black wire to gnd and yellow wire to gpio13 ?

I have HAos. Note that the port is not a pin number, but the actual GPIO on the Rpi.

thx for your reply. i have also HAos and the exact same code + wiring does not work for me :frowning:

Do you have your own rpi gpio integration from HACS installed?

i am not sure what you mean by my own… but i have instal the one via HACS https://github.com/thecode/ha-rpi_gpio

Same problem here.

No additional information on the Github page listed earlier in this thread.

Is GPIO add-on working for anyone?

Yes it works fine all the time. I use it to control the HA cooling fan on the Rpi4.

Update on my system. At the time of my last posting, it started working, though not sure why.

At the time of this posting, I had an issue with my system and this problem started again.

In the meantime, others have discussed this on this thread.

The solution points to new forks in the HACS GPIO integration. This one worked for me.

Also discussed here.