MQTT-IO fails access to RPI GPIO

In the following configuration, the activation of the Mqtt-Io add-on fails due to a hardware exception when accessing GPIO. What can I do?

Add-on: MQTT IO
Expose GPIO modules and digital sensors via MQTT for remote control and monitoring.
Add-on version: 0.3.0
You are running the latest version of this add-on.
System: Home Assistant OS 11.2 (aarch64 / raspberrypi4-64)
Home Assistant Core: 2023.12.3
Home Assistant Supervisor: 2023.11.6

The Mqtt-Io configuration file is as follows:

mqtt:
host: localhost
topic_prefix: home

gpio_modules:

  • name: rpi
    module: raspberrypi
    digital_inputs:
  • name: gpio0
    module: rpi
    pin: 11
    digital_outputs:
  • name: gpio0
    module: rpi
    pin: 12

Here are the relevant info of the log file:

File “/usr/lib/python3.11/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!
File “/usr/lib/python3.11/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!
[12:17:52] INFO: Service MQTT IO exited with code 1 (by signal 0)

This is likely by design. HAOS is a locked-down version of Linux to improve security, and Add-ons run in docker containers. The underlying HAOS is unlikely to allow access to the ‘real’ hardware (hence the root permission errors).

The alternative I used was to move fron RPi GPIO to an ESP8266 (Wemos D1 mini) running ESPhome or Tasmota. You could also try moving from HAOS to your own install of Linux plus HASS container, but that’s a lot more work, and defeats the object of a packaged secure image.

From the original HASS code in 2022.6:

I carefully read the answer, in the meantime I continued with tests.
On some occasion, Hassos’s GUI can deceive. It is possible to give access privileges to the HW. In Settings-> Add-ons-> MQTT IO, when authorized the following writing appears

Moreover I installed Log viewer Add-on and modified configuration.yaml appending the following lines:

Immagine 2023-12-27 163524

Then the MQTT IO log report is the following:

[16:00:12] INFO: Starting MQTT IO…
2023-12-27 16:00:19 mqtt_io.server [INFO] Digital output ‘output1’ current value is False (raw: False)
2023-12-27 16:00:19 mqtt_io.server [INFO] Digital output ‘output2’ current value is False (raw: False)
2023-12-27 16:00:19 mqtt_io.server [INFO] Digital input ‘input1’ value changed to True
2023-12-27 16:00:19 mqtt_io.server [INFO] Digital input ‘input2’ value changed to True
2023-12-27 16:00:20 mqtt_io.server [INFO] Connecting to MQTT…
2023-12-27 16:00:20 mqtt_io.server [INFO] Connected to MQTT
2023-12-27 16:00:20 mqtt_io.server [INFO] Subscribed to topic: ‘home/output/output1/set’
2023-12-27 16:00:20 mqtt_io.server [INFO] Subscribed to topic: ‘home/output/output1/set_on_ms’
2023-12-27 16:00:20 mqtt_io.server [INFO] Subscribed to topic: ‘home/output/output1/set_off_ms’
2023-12-27 16:00:20 mqtt_io.server [INFO] Subscribed to topic: ‘home/output/output2/set’
2023-12-27 16:00:20 mqtt_io.server [INFO] Subscribed to topic: ‘home/output/output2/set_on_ms’
2023-12-27 16:00:20 mqtt_io.server [INFO] Subscribed to topic: ‘home/output/output2/set_off_ms’

And the Log Viewer reports the MQTT events as below:

2023-12-27 16:00:20.192 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on home/input/input2 (qos=0): b’ON’
2023-12-27 16:00:20.198 DEBUG (MainThread) [homeassistant.components.mqtt.client] Received message on home/input/input1 (qos=0): b’ON’
2023-12-27 16:10:56.009 DEBUG (MainThread) [homeassistant.components.mqtt.client] Transmitting message on home/output/output1/set: ‘ON’, mid: 3, qos: 0
2023-12-27 16:10:57.700 DEBUG (MainThread) [homeassistant.components.mqtt.client] Transmitting message on home/output/output2/set: ‘ON’, mid: 4, qos: 0