Giter Club home page Giter Club logo

addon-mqtt-io's Introduction

Home Assistant Community Add-on: MQTT IO

GitHub Release Project Stage License

Supports aarch64 Architecture Supports amd64 Architecture Supports armhf Architecture Supports armv7 Architecture Supports i386 Architecture

Github Actions Project Maintenance GitHub Activity

Discord Community Forum

Expose GPIO modules and digital sensors via MQTT for remote control and monitoring.

About

Exposes general purpose inputs and outputs (GPIO), hardware sensors and serial devices to an MQTT server. Ideal for single-board computers such as the Raspberry Pi.

📚 Read the full add-on documentation

Support

Got questions?

You have several options to get them answered:

You could also open an issue here GitHub.

Contributing

This is an active open-source project. We are always open to people who want to use the code or contribute to it.

We have set up a separate document containing our contribution guidelines.

Thank you for being involved! 😍

Authors & contributors

The original setup of this repository is by Franck Nijhof.

For a full list of all authors and contributors, check the contributor's page.

We have got some Home Assistant add-ons for you

Want some more functionality to your Home Assistant instance?

We have created multiple add-ons for Home Assistant. For a full list, check out our GitHub Repository.

License

MIT License

Copyright (c) 2023-2024 Franck Nijhof

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

addon-mqtt-io's People

Contributors

dependabot[bot] avatar frenck avatar lyokovic avatar mrk-its avatar renovate[bot] avatar thecode avatar wrt54g avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

addon-mqtt-io's Issues

Last version of paho-mqtt dependency causes crash on startup

Problem/Motivation

mqtt-io uses very old version of asyncio-mqtt (8.1), depending on paho-mqtt>=1.5.0. In Feb 2024 paho-mqtt released version 2.0 introducing some breaking changes, resulting in following error during startup of the addon:

2024-06-04 00:16:17 mqtt_io.__main__ [ERROR] MqttIo crashed!
Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/mqtt_io/__main__.py", line 107, in main
    mqtt_gpio.run()
  File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 1280, in run
    self.loop.run_until_complete(self._main_task)
  File "/usr/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 1199, in _main_loop
    await self._connect_mqtt()
  File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 596, in _connect_mqtt
    await self.mqtt.connect()
  File "/usr/lib/python3.11/site-packages/mqtt_io/mqtt/asyncio_mqtt.py", line 32, in inner
    await func(*args, **kwargs)
  File "/usr/lib/python3.11/site-packages/mqtt_io/mqtt/asyncio_mqtt.py", line 79, in connect
    await self._client.connect(timeout=timeout)
  File "/usr/lib/python3.11/site-packages/asyncio_mqtt/client.py", line 82, in connect
    if not isinstance(client_socket, mqtt.WebsocketWrapper):

Steps to reproduce

Reinstall (rebuild) addon on latest version of HA OS / HA CORE

Proposed changes

The issue should be fixed upstream. But it looks that following line added to addon's requirements.txt solves the problem for now:

paho-mqtt<2

Error when retrieving values from DHT22 Sensor

Problem/Motivation

Hello once again! My other issue #15 got solved with the solution you provided. But now I'm facing another problem with pulling the data from the sensor. The addon successfully connects to my MQTT Broker but throws errors when it pulls sensor data.

Expected behavior

The sensor data would be pulled from the sensors and then posted on the MQTT Broker

Actual behavior

The addon connects to the MQTT server succesfully but throws this error while trying to retrieve values from the DHT22 sensor

2022-07-25 14:22:38 mqtt_io.server [ERROR] Exception when retrieving value from sensor 'humidity':
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 561, in poll_sensor
    value = await get_sensor_value()
  File "/usr/lib/python3.10/site-packages/backoff/_async.py", line 133, in retry
    ret = await target(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/backoff/_async.py", line 66, in retry
    ret = await target(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 556, in get_sensor_value
    return await sensor_module.async_get_value(sens_conf)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/sensor/__init__.py", line 57, in async_get_value
    return await loop.run_in_executor(ThreadPoolExecutor(), self.get_value, sens_conf)
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/sensor/dht22.py", line 62, in get_value
    humidity, temperature = self.sensor.read_retry(self.sensor_type, self.pin)
  File "/usr/lib/python3.10/site-packages/Adafruit_DHT/common.py", line 94, in read_retry
    humidity, temperature = read(sensor, pin, platform)
  File "/usr/lib/python3.10/site-packages/Adafruit_DHT/common.py", line 80, in read
    platform = get_platform()
  File "/usr/lib/python3.10/site-packages/Adafruit_DHT/common.py", line 55, in get_platform
    from . import Raspberry_Pi_2
  File "/usr/lib/python3.10/site-packages/Adafruit_DHT/Raspberry_Pi_2.py", line 22, in <module>
    from . import Raspberry_Pi_2_Driver as driver
ImportError: cannot import name 'Raspberry_Pi_2_Driver' from 'Adafruit_DHT' (/usr/lib/python3.10/site-packages/Adafruit_DHT/__init__.py)
2022-07-25 14:22:38 mqtt_io.server [ERROR] Exception when retrieving value from sensor 'temperature':
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 561, in poll_sensor
    value = await get_sensor_value()
  File "/usr/lib/python3.10/site-packages/backoff/_async.py", line 133, in retry
    ret = await target(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/backoff/_async.py", line 66, in retry
    ret = await target(*args, **kwargs)
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 556, in get_sensor_value
    return await sensor_module.async_get_value(sens_conf)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/sensor/__init__.py", line 57, in async_get_value
    return await loop.run_in_executor(ThreadPoolExecutor(), self.get_value, sens_conf)
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/sensor/dht22.py", line 62, in get_value
    humidity, temperature = self.sensor.read_retry(self.sensor_type, self.pin)
  File "/usr/lib/python3.10/site-packages/Adafruit_DHT/common.py", line 94, in read_retry
    humidity, temperature = read(sensor, pin, platform)
  File "/usr/lib/python3.10/site-packages/Adafruit_DHT/common.py", line 80, in read
    platform = get_platform()
  File "/usr/lib/python3.10/site-packages/Adafruit_DHT/common.py", line 55, in get_platform
    from . import Raspberry_Pi_2
  File "/usr/lib/python3.10/site-packages/Adafruit_DHT/Raspberry_Pi_2.py", line 22, in <module>
    from . import Raspberry_Pi_2_Driver as driver
ImportError: cannot import name 'Raspberry_Pi_2_Driver' from 'Adafruit_DHT' (/usr/lib/python3.10/site-packages/Adafruit_DHT/__init__.py)

Steps to reproduce

Here is the config.yml file used:

mqtt:
  host: 192.168.1.2
  port: 2883
  user: "mqtt-username"
  password: "mqtt-password"
  topic_prefix: home/livingroom/climate

sensor_modules:
  - name: dht22_sensor
    module: dht22
    type: AM2302
    pin: 4

sensor_inputs:
  - name: temperatur
    module: dht22_sensor
    interval: 10
    digits: 4
    type: temperature

  - name: luftfuktighet
    module: dht22_sensor
    interval: 10
    digits: 4
    type: humidity

I am very greatful for your help, and your continued support of Home Assistant and the addons, you guys are the best <3

Addon folder structure changed - config folder not present in new HAOS-installation

As documented here just 3 months ago, it seems like the addon-config-mounting-map has recently changed. Unfortunately, I couldn't find the correct commit changing the actual logic.

As a consequence, there seems to be no more "config" folder in newer installations of HAOS:

# pwd
/mnt/data/supervisor
# ls
addon_configs       config.json         mounts
addons              dns                 multicast.json
addons.json         dns.json            observer.json
apparmor            emergency           services.json
audio               homeassistant       share
audio.json          homeassistant.json  ssl
backup              ingress.json        tmp
cli.json            media               updater.json

Instead, it is recommended to mount "addon_configs". For now I was able to work around this using the share folder and adjusting the addon configuration to search in /share/mqtt-io/config.yml. This could either be reflected as a preferred solution in the corresponding Documentation or probably better yet changed in the add-on config. I'm sorry there's no direct PR here, if I get around to it after solving the problem at hand I'd be happy to contribute.

Thanks for your work. I'll be happy to provide more info if necessary.

addon didn't start - config file missing

Until now, all within HA is done from GUI
While starting iqtt-io i got the message like "Config file is missing ... create the config /config/mqtt-io/config.yml"
Is there an option to build these file from GUI?

Thx Dirk

RuntimeError: No access to /dev/mem. Try running as root!

Hi, I updated mqtt-io and got this error.

Problem/Motivation

[17:51:40] INFO: Starting MQTT IO...
2023-01-20 17:51:54 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 1240, in run
    self._init_digital_inputs()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 387, in _init_digital_inputs
    gpio_module.setup_pin_internal(PinDirection.INPUT, in_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 1240, in run
    self._init_digital_inputs()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 387, in _init_digital_inputs
    gpio_module.setup_pin_internal(PinDirection.INPUT, in_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!

Steps to reproduce

Home Assistant OS Release 2023.1.6 (raspberry3). Update MQTT-IO to 0.2.0

Somehow /dev is less than /dev/mem? c6d4059

Add support for environment variables

Problem/Motivation

I have the plug-in working. But I have to hard-code a user-name and password into the config file.

I would like to be able to hook into the Services API to retrieve connection details, so I can remove these sensitive details

For example:

mqtt:
  host: core-mosquitto
  user: mosquitto
  password: XeEb8
  topic_prefix: /home/alarm
  ha_discovery:
    enabled: true

Expected behaviour

I would like to be able to use placeholders for the MQTT server, username and password. Such as:

mqtt:
  host: { { my_env('MQTT_HOST') } }
  user: { { my_env('MQTT_USER') } }
  password: { { my_env('MQTT_PASSWORD') } }
  topic_prefix: /home/alarm
  ha_discovery:
    enabled: true

Proposed changes

I have mqtt-io working with environment variables in my own environment. To make this work I needed to...

Create a static render.yaml file with the contents:

backends:
  my_env:
    type: env

This tells mqtt-io that you want to define a config source called my_env and it should use the env backend add-in.

I then add a parameter when the python is started...

python3 -m mqtt_io --render render.yaml config.yaml

so in this context, I think the mqtt-io/rootfs/etc/services.d/mqtt-io/run file needs updating to include:

MQTT_HOST=$(bashio::services mqtt "host")
MQTT_USER=$(bashio::services mqtt "username")
MQTT_PASSWORD=$(bashio::services mqtt "password")

exec python3 -m mqtt_io --render render.yaml "$(bashio::config 'configuration_file')"

and the mqtt-io/config.yaml file would need updating to include the mqtt service

services:
  - mqtt:need

I can try and get this working myself - but I wanted to raise as an issue to ensure this is a good approach given your much greater experience with the HAOS platform

Xiaomi Gateway 3 (ZNDMWG03LM) Mesh update interval

Hi, this post is similar to the post I made on HACS forum.

I have a dozen of Xiaomi Mesh power socket (ZNCZ01ZM) which is capable of getting outlet, power, led, power_protect, power_value.

As I understood (maybe I’m wrong) that the Mesh message can be sent out randomly by the device itself thus we don’t have much control over how often we wanted to. As such automation might not be able to trigger at the precise moment if needed.

As for my device (ZNCZ01ZM) it gets updated roughly at about 9 to 10 mins timeframe and even if it gets updated, I believe it's just a message to respond to the gateway it is still there, it doesn’t contain the full message.

I've noticed once I fire up my Mi Home app and enter into the device, the app will update the complete messages back to the gateway, and thus the power_value update instantaneously.

So, I think besides having the device send the message randomly we can somehow focus it to send it back to the gateway.

Personally, I have not tested on other Xiaomi BLE Mesh devices if by visiting the device using the App, the sensor reports the value back to HA but I believe they do.

Is there a way we can send the command similar to entering the device on Mi Home app and attach it to an automation? Doing so is as good as having the possibility to set the refresh interval.

Addon will not start?

Problem/Motivation

The addon will not start.

Expected behavior

Addon to run.

Actual behavior

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.4.0
 You are running the latest version of this add-on.
 System: Debian GNU/Linux 12 (bookworm)  (armv7 / raspberrypi4)
 Home Assistant Core: 2024.4.3
 Home Assistant Supervisor: 2024.04.0
-----------------------------------------------------------
 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
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:19:07] INFO: Starting MQTT IO...
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/lib/python3.11/site-packages/mqtt_io/__main__.py", line 115, in <module>
    main()
  File "/usr/lib/python3.11/site-packages/mqtt_io/__main__.py", line 79, in main
    config = validate_and_normalise_main_config(raw_config)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mqtt_io/config/__init__.py", line 184, in validate_and_normalise_main_config
    config = validate_and_normalise_config(raw_config, get_main_schema())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/mqtt_io/config/__init__.py", line 104, in validate_and_normalise_config
    if not validator.validate(config):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/cerberus/validator.py", line 1031, in validate
    self.__init_processing(document, schema)
  File "/usr/lib/python3.11/site-packages/cerberus/validator.py", line 644, in __init_processing
    raise DocumentError(errors.DOCUMENT_MISSING)
cerberus.validator.DocumentError: document is missing
[13:19:11] 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
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service base-addon-log-level: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service base-addon-log-level successfully stopped
s6-rc: info: service base-addon-banner: stopping
s6-rc: info: service base-addon-banner successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Steps to reproduce

Fresh install of this addon on a RaspberryPI with Supervised Install.

Proposed changes

Addon crashes on initial startup

Problem/Motivation

I was trying to setup this addon and I had made a config.yml file and everything, but when I started the addon after a while it crashed and if I tried to start the addon once more, it would crash on the same spot again.

Expected behavior

The addon would start as expected

Actual behavior

The addon crashes with the following error code:

× Running setup.py install for Adafruit_DHT did not run successfully.
  │ exit code: 1
  ╰─> [24 lines of output]
      running install
      /usr/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build/lib.linux-armv7l-3.10
      creating build/lib.linux-armv7l-3.10/Adafruit_DHT
      copying Adafruit_DHT/common.py -> build/lib.linux-armv7l-3.10/Adafruit_DHT
      copying Adafruit_DHT/platform_detect.py -> build/lib.linux-armv7l-3.10/Adafruit_DHT
      copying Adafruit_DHT/Beaglebone_Black.py -> build/lib.linux-armv7l-3.10/Adafruit_DHT
      copying Adafruit_DHT/__init__.py -> build/lib.linux-armv7l-3.10/Adafruit_DHT
      copying Adafruit_DHT/Test.py -> build/lib.linux-armv7l-3.10/Adafruit_DHT
      copying Adafruit_DHT/Raspberry_Pi_2.py -> build/lib.linux-armv7l-3.10/Adafruit_DHT
      copying Adafruit_DHT/Raspberry_Pi.py -> build/lib.linux-armv7l-3.10/Adafruit_DHT
      warning: build_py: byte-compiling is disabled, skipping.
      
      running build_ext
      building 'Adafruit_DHT.Raspberry_Pi_2_Driver' extension
      creating build/temp.linux-armv7l-3.10
      creating build/temp.linux-armv7l-3.10/source
      creating build/temp.linux-armv7l-3.10/source/Raspberry_Pi_2
      gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fomit-frame-pointer -g -fomit-frame-pointer -g -fomit-frame-pointer -g -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/include/python3.10 -c source/Raspberry_Pi_2/pi_2_dht_read.c -o build/temp.linux-armv7l-3.10/source/Raspberry_Pi_2/pi_2_dht_read.o -std=gnu99
      error: command 'gcc' failed: No such file or directory
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> Adafruit_DHT
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
2022-07-25 12:21:53 mqtt_io.__main__ [ERROR] MqttIo crashed!
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/__init__.py", line 51, in install_missing_module_requirements
    install_missing_requirements(pkgs_required)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/__init__.py", line 22, in install_missing_requirements
    check_call([sys.executable, "-m", "pip", "install"] + pkgs_required)
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'pip', 'install', 'Adafruit_DHT']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
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 1230, in run
    self._init_sensor_modules()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 255, in _init_sensor_modules
    self.sensor_modules[sens_config["name"]] = _init_module(
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 124, in _init_module
    install_missing_module_requirements(module)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/__init__.py", line 53, in install_missing_module_requirements
    raise CannotInstallModuleRequirements(
mqtt_io.exceptions.CannotInstallModuleRequirements: Unable to install packages for module <module 'mqtt_io.modules.sensor.dht22' from '/usr/lib/python3.10/site-packages/mqtt_io/modules/sensor/dht22.py'> (['Adafruit_DHT']): Command '['/usr/bin/python3', '-m', 'pip', 'install', 'Adafruit_DHT']' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/__init__.py", line 51, in install_missing_module_requirements
    install_missing_requirements(pkgs_required)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/__init__.py", line 22, in install_missing_requirements
    check_call([sys.executable, "-m", "pip", "install"] + pkgs_required)
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'pip', 'install', 'Adafruit_DHT']' returned non-zero exit status 1.
The above exception was the direct cause of the following exception:
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 1230, in run
    self._init_sensor_modules()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 255, in _init_sensor_modules
    self.sensor_modules[sens_config["name"]] = _init_module(
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 124, in _init_module
    install_missing_module_requirements(module)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/__init__.py", line 53, in install_missing_module_requirements
    raise CannotInstallModuleRequirements(
mqtt_io.exceptions.CannotInstallModuleRequirements: Unable to install packages for module <module 'mqtt_io.modules.sensor.dht22' from '/usr/lib/python3.10/site-packages/mqtt_io/modules/sensor/dht22.py'> (['Adafruit_DHT']): Command '['/usr/bin/python3', '-m', 'pip', 'install', 'Adafruit_DHT']' returned non-zero exit status 1.
[12:21:54] WARNING: MQTT IO crashed, halting add-on
s6-rc: info: service legacy-services: stopping
[12:21:54] INFO: MQTT IO stopped

Steps to reproduce

Start the addon with a fresh install.

MQTT IO not starting - no access to /dev/mem

Problem/Motivation

Hi, I have installed it as a plugin but I'm not able to start the MQTT IO on managed HA (Home Assistant OS 9.5) on RPI:

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 9.5  (aarch64 / raspberrypi4-64)
 Home Assistant Core: 2023.4.5
 Home Assistant Supervisor: 2023.04.1
-----------------------------------------------------------
 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
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
[11:19:58] INFO: Starting MQTT IO...
2023-04-26 11:20:07 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 1240, in run
    self._init_digital_inputs()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 387, in _init_digital_inputs
    gpio_module.setup_pin_internal(PinDirection.INPUT, in_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 1240, in run
    self._init_digital_inputs()
  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 387, in _init_digital_inputs
    gpio_module.setup_pin_internal(PinDirection.INPUT, in_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!
[11:20:07] 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
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service base-addon-log-level: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service base-addon-log-level successfully stopped
s6-rc: info: service base-addon-banner: stopping
s6-rc: info: service base-addon-banner successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Expected behavior

MQTT starts

Actual behavior

mqtt_io.main [ERROR] MqttIo crashed! -> RuntimeError: No access to /dev/mem. Try running as root!

RuntimeError: No access to /dev/mem. Try running as root!

Not Working.....

Home Assistant 2023.1.6

Supervisor 2022.12.1

Operating System 9.4

Interface: 20230110.0 - latest

MQTT IO - Current version: 0.2.1

My config...
/config/mqtt-io/config.yml

mqtt:
host: 192.168.15.200
port: 1883
user: "samuel"
password: "46173106"
topic_prefix: mqtt_io
ha_discovery:
enabled: yes

gpio_modules:

name: rpi_gpio
module: raspberrypi
digital_outputs:

name: Fonte
module: rpi_gpio
pin: 7
on_payload: "on"
off_payload: "off"
initial: high
publish_initial: yes
retain: yes
Log:

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 9.4 (aarch64 / raspberrypi3-64)
Home Assistant Core: 2023.1.6
Home Assistant Supervisor: 2022.12.1
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
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
[20:14:40] INFO: Starting MQTT IO...
2023-01-20 20:14:53 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
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!
[20:14:53] 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
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service base-addon-log-level: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service base-addon-log-level successfully stopped
s6-rc: info: service base-addon-banner: stopping
s6-rc: info: service base-addon-banner successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

RuntimeError: unkown platform

Problem/Motivation

Start of the addon fails with stacktraces.

`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.4.0
You are running the latest version of this add-on.
System: Home Assistant OS 12.1 (aarch64 / raspberrypi4-64)
Home Assistant Core: 2024.3.1
Home Assistant Supervisor: 2024.03.0

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
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
[19:42:23] INFO: Starting MQTT IO...
2024-03-17 19:42:28 mqtt_io.server [INFO] Connecting to MQTT...
2024-03-17 19:42:28 mqtt_io.server [INFO] Connected to MQTT
2024-03-17 19:42:38 mqtt_io.server [ERROR] Exception when retrieving value from sensor 'temperature':
Traceback (most recent call last):
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 572, in poll_sensor
value = await get_sensor_value()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/backoff/_async.py", line 133, in retry
ret = await target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/backoff/_async.py", line 66, in retry
ret = await target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 567, in get_sensor_value
return await sensor_module.async_get_value(sens_conf)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/sensor/init.py", line 58, in async_get_value
return await loop.run_in_executor(self.executor, self.get_value, sens_conf)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/sensor/dht22.py", line 62, in get_value
humidity, temperature = self.sensor.read_retry(self.sensor_type, self.pin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/Adafruit_DHT/common.py", line 63, in get_platform
raise RuntimeError('Unknown platform.')
RuntimeError: Unknown platform.
2024-03-17 19:42:38 mqtt_io.server [ERROR] Exception when retrieving value from sensor 'humidity':
Traceback (most recent call last):
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 572, in poll_sensor
value = await get_sensor_value()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/backoff/_async.py", line 133, in retry
ret = await target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/backoff/_async.py", line 66, in retry
ret = await target(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 567, in get_sensor_value
return await sensor_module.async_get_value(sens_conf)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/sensor/init.py", line 58, in async_get_value
return await loop.run_in_executor(self.executor, self.get_value, sens_conf)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/sensor/dht22.py", line 62, in get_value
humidity, temperature = self.sensor.read_retry(self.sensor_type, self.pin)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/Adafruit_DHT/common.py", line 63, in get_platform
raise RuntimeError('Unknown platform.')
RuntimeError: Unknown platform.`

Proposed changes

Smells a bit like #100

last version dosen't work

Problem

I updated with the last vesrion version and the addon stop working

Actual behavior

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.2 (aarch64 / raspberrypi3-64)
Home Assistant Core: 2023.6.0
Home Assistant Supervisor: 2023.06.2

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 DEBUG
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
[23:22:07] INFO: Starting MQTT IO...
2023-06-26 23:22:38 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
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!
[23:22:40] 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
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service base-addon-log-level: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service base-addon-log-level successfully stopped
s6-rc: info: service base-addon-banner: stopping
s6-rc: info: service base-addon-banner successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Steps to reproduce

reinstall old version and upgrade again

Is there anyone had this issue?
Thanks guys
Steve

RuntimeError: This module can only be run on a Raspberry Pi!

Freshly installed HA on RPI4 crashes:

[19:47:39] INFO: Starting MQTT IO...
2024-01-07 19:47:44 mqtt_io.main [ERROR] MqttIo crashed!
Traceback (most recent call last):
File "/usr/lib/python3.11/site-packages/mqtt_io/main.py", line 107, in main
mqtt_gpio.run()
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 1269, in run
self._init_gpio_modules()
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 244, in _init_gpio_modules
self.gpio_modules[gpio_config["name"]] = _init_module(
^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 128, in _init_module
return module_class(module_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/gpio/init.py", line 106, in init
self.setup_module()
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/gpio/raspberrypi.py", line 25, in setup_module
import RPi.GPIO as gpio # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/RPi/GPIO/init.py", line 23, in
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/usr/lib/python3.11/site-packages/mqtt_io/main.py", line 115, in
main()
File "/usr/lib/python3.11/site-packages/mqtt_io/main.py", line 107, in main
mqtt_gpio.run()
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 1269, in run
self._init_gpio_modules()
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 244, in _init_gpio_modules
self.gpio_modules[gpio_config["name"]] = _init_module(
^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 128, in _init_module
return module_class(module_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/gpio/init.py", line 106, in init
self.setup_module()
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/gpio/raspberrypi.py", line 25, in setup_module
import RPi.GPIO as gpio # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/RPi/GPIO/init.py", line 23, in
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
[19:47:44] INFO: Service MQTT IO exited with code 1 (by signal 0

My config file:

mqtt:
host: core-mosquitto
port: 1883
user: ""
password: "
"
topic_prefix: ha
ha_discovery:
enabled: yes

gpio_modules:

  • name: rpi
    module: raspberrypi

#digital_outputs:

- name: dioda_1

module: rpi

pin: 1

digital_inputs:

  • name: ogrod
    module: rpi
    pin: 0
    pullup: no
  • name: wejscie
    module: rpi
    pin: 1
    pullup: no
  • name: garaz
    module: rpi
    pin: 2
    pullup: no
  • name: alarm
    module: rpi
    pin: 3
    pullup: no

Any help?

Error when addon trying to access/dev/i2c-1

Problem/Motivation

I have RPi-OS and hassio supervised installed on my RPi4. When I try to run addon-mqtt-io with a BME280 sensor connected locally via GPIO I2C, I get below error:

PermissionError: [Errno 1] Operation not permitted: '/dev/i2c-1'

The same problem occurs on RPi3b running on the latest haos-9.3 system. I tried to diagnose the problem, the conclusions are as below.

Actual behavior

Addon Logs:

  File "/usr/lib/python3.10/site-packages/mqtt_io/server.py", line 128, in _init_module
    return module_class(module_config)
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/sensor/__init__.py", line 22, in __init__
    self.setup_module()
  File "/usr/lib/python3.10/site-packages/mqtt_io/modules/sensor/bme280.py", line 38, in setup_module
    self.bus = SMBus(self.config["i2c_bus_num"])
  File "/usr/lib/python3.10/site-packages/smbus2/smbus2.py", line 280, in __init__
    self.open(bus)
  File "/usr/lib/python3.10/site-packages/smbus2/smbus2.py", line 310, in open
    self.fd = os.open(filepath, os.O_RDWR)
PermissionError: [Errno 1] Operation not permitted: '/dev/i2c-1'
[11:29:09] WARNING: MQTT IO crashed, halting add-on
s6-rc: info: service legacy-services: stopping
[11:29:10] INFO: MQTT IO stopped
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

mqtt-io_log.txt

Steps to reproduce

The plugin configuration is as follows /config/mqtt-io/config.yml:

mqtt:
  host: core-mosquitto
  user: homeassistant
  password: [hidden]
  topic_prefix: mqtt-io
sensor_modules:
  # BME280 on I2C bus
  - name: bme_sensor
    module: bme280
    i2c_bus_num: 1
    chip_addr: 0x76
sensor_inputs:
  - name: sen1_temperature
    module: bme_sensor

Sensor BME280 connected to i2c-1 interface GPIO RPi4.

Additional tests

1. Read GPIO i2c from RPI4 host:

Check the operation of the BME280 sensor directly from the host:

[root@home /]# i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --
[root@home /home/awitt/temp]# read_bme280 --i2c-address 0x76
1002.46 hPa
  49.42 %
  24.11 C

2. Read GPIO i2c from container addon-mqtt-io

Then I run the same commands in the mqtt-io container running in HA. I'm starting the add-on with minimal configuration /config/mqtt-io/config.yml

mqtt:
  host: core-mosquitto
  user: homeassistant
  password: [hidden]
  topic_prefix: mqtt-io

then from the host CLI enter the mqtt-io container:

[root@home /]# docker exec -it addon_a0d7b954_mqtt-io bash

then in the container:

apk add --no-cache i2c-tools && i2cdetect -y 1

as a result of the command, I get the response:

a0d7b954-mqtt-io:~# apk add --no-cache i2c-tools && i2cdetect -y 1
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/aarch64/APKINDEX.tar.gz
(1/1) Installing i2c-tools (4.3-r1)
Executing busybox-1.35.0-r17.trigger
OK: 89 MiB in 54 packages
Error: Could not open file `/dev/i2c-1': Operation not permitted
a0d7b954-mqtt-io:~#

mqtt-io_docker_inspect.txt

3. Read GPIO i2c from new alpine container

I'm running the alpine: latest container with permissions:
SYS_RAWIO
/dev/mem
/dev/gpiomem

[root@home /]# docker run -it --rm --cap-add SYS_RAWIO --device /dev/mem --device /dev/gpiomem alpine:latest sh

and run i2c test:

[root@home /]# docker run -it --rm --cap-add SYS_RAWIO --device /dev/mem --device /dev/gpiomem alpine:latest sh
/ # apk add --no-cache i2c-tools && i2cdetect -y 1
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/aarch64/APKINDEX.tar.gz
(1/1) Installing i2c-tools (4.3-r1)
Executing busybox-1.35.0-r17.trigger
OK: 6 MiB in 15 packages
Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory
/ #

4. Read GPIO i2c from new alpine container (/dev/i2c-1)

I'm running the alpine: latest container with permissions:
/dev/i2c-1

[root@home /]#  docker run -it --rm --device /dev/i2c-1 alpine:latest sh
/ # apk add --no-cache i2c-tools && i2cdetect -y 1
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/aarch64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/aarch64/APKINDEX.tar.gz
(1/1) Installing i2c-tools (4.3-r1)
Executing busybox-1.35.0-r17.trigger
OK: 6 MiB in 15 packages
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --
/ #

System Info

[root@home /]# uname -a
Linux home 5.15.74-v8+ #1595 SMP PREEMPT Wed Oct 26 11:07:24 BST 2022 aarch64 GNU/Linux

[root@home /]# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Add-on version: 0.1.3
You are running the latest version of this add-on.
System: Debian GNU/Linux 11 (bullseye) (aarch64 / raspberrypi4-64)
Home Assistant Core: 2022.10.5
Home Assistant Supervisor: 2022.10.2

Questions

  1. How do I get the plug to work? In the docker container called with the parameters --cap-add SYS_RAWIO --device / dev / mem --device / dev / gpiomem it wont work.

  2. Changing the parameters SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0666" oraz SUBSYSTEM=="gpio", GROUP="gpio", MODE="0666" it doesn't help

  3. The problem seems to be resolved after mapping /dev/i2c-1. So, should this parameter be added to the plugin configuration?

returned a non-zero code: 56

The command
'/bin/bash -o pipefail -c apk add --no-cache --virtual .build-dependencies build-base=0.5-r3 libffi-dev=3.4.2-r1 py3-wheel=0.37.1-r0 python3-dev=3.10.8-r0 &&
apk add --no-cache py3-bcrypt=3.2.2-r0 py3-cryptography=3.4.8-r1 py3-pip=22.1.1-r0 python3=3.10.8-r0 &&
pip install -r /tmp/requirements.txt &&
pip install Adafruit_DHT==1.4.0 --install-option="--force-pi2" &&
find /usr \( -type d -a -name test -o -name tests -o -name '__pycache__' \) -o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) -exec rm -rf '{}' + &&
apk del --no-cache --purge .build-dependencies'
returned a non-zero code: 56

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

dockerfile
mqtt-io/Dockerfile
  • ghcr.io/hassio-addons/base 15.0.9
github-actions
.github/workflows/ci.yaml
.github/workflows/deploy.yaml
.github/workflows/labels.yaml
.github/workflows/lock.yaml
.github/workflows/pr-labels.yaml
.github/workflows/release-drafter.yaml
.github/workflows/stale.yaml
pip_requirements
mqtt-io/requirements.txt
  • adafruit-circuitpython-ads1x15 ==2.2.19
  • adafruit-circuitpython-ahtx0 ==1.0.21
  • adafruit-circuitpython-mcp230xx ==2.5.13
  • Adafruit-MCP3008 ==1.0.2
  • bme680 ==1.1.1
  • gpiod ==2.2.1
  • gpiozero ==2.0.1
  • paho-mqtt ==1.6.1
  • nfcpy ==1.0.4
  • pcf8574 ==0.1.3
  • pcf8575 ==0.3
  • pi-ina219 ==1.4.1
  • pifacecommon ==4.2.2
  • pifacedigitalio ==3.0.5
  • pyserial ==3.5
  • RPi.bme280 ==0.2.4
  • RPi.GPIO ==0.7.1
  • smbus2 ==0.4.3
  • w1thermsensor ==2.3.0
regex
mqtt-io/Dockerfile
  • ghcr.io/hassio-addons/base 15.0.9
mqtt-io/build.yaml
  • ghcr.io/hassio-addons/base 15.0.9
  • ghcr.io/hassio-addons/base 15.0.9
  • ghcr.io/hassio-addons/base 15.0.9
mqtt-io/Dockerfile
  • alpine_3_19/build-base 0.5-r3
  • alpine_3_19/git 2.43.4-r0
  • alpine_3_19/libffi-dev 3.4.4-r3
  • alpine_3_19/py3-wheel 0.42.0-r0
  • alpine_3_19/python3-dev 3.11.9-r1
  • alpine_3_19/py3-bcrypt 4.1.1-r0
  • alpine_3_19/py3-cryptography 41.0.7-r0
  • alpine_3_19/py3-pip 23.3.1-r0
  • alpine_3_19/python3 3.11.9-r1

  • Check this box to trigger a request for Renovate to run again on this repository

.

.

MQTT IO addon fails to start on RPI 4 with Home Assistant OS 12.1

Problem/Motivation

MQTT IO addon fails to start

Expected behavior

(What you expected to happen)

Actual behavior


Add-on: MQTT IO
Expose GPIO modules and digital sensors via MQTT for remote control and monitoring.

Add-on version: 0.4.0
You are running the latest version of this add-on.
System: Home Assistant OS 12.1 (aarch64 / raspberrypi4-64)
Home Assistant Core: 2024.3.3
Home Assistant Supervisor: 2024.03.1

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
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
[09:24:14] INFO: Starting MQTT IO...
2024-04-05 09:24:17 mqtt_io.main [ERROR] MqttIo crashed!
Traceback (most recent call last):
File "/usr/lib/python3.11/site-packages/mqtt_io/main.py", line 107, in main
mqtt_gpio.run()
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 1269, in run
self._init_gpio_modules()
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 244, in _init_gpio_modules
self.gpio_modules[gpio_config["name"]] = _init_module(
^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 128, in _init_module
return module_class(module_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/gpio/init.py", line 106, in init
self.setup_module()
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/gpio/raspberrypi.py", line 25, in setup_module
import RPi.GPIO as gpio # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/RPi/GPIO/init.py", line 23, in
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/usr/lib/python3.11/site-packages/mqtt_io/main.py", line 115, in
main()
File "/usr/lib/python3.11/site-packages/mqtt_io/main.py", line 107, in main
mqtt_gpio.run()
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 1269, in run
self._init_gpio_modules()
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 244, in _init_gpio_modules
self.gpio_modules[gpio_config["name"]] = _init_module(
^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/server.py", line 128, in _init_module
return module_class(module_config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/gpio/init.py", line 106, in init
self.setup_module()
File "/usr/lib/python3.11/site-packages/mqtt_io/modules/gpio/raspberrypi.py", line 25, in setup_module
import RPi.GPIO as gpio # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/RPi/GPIO/init.py", line 23, in
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
[09:24:18] 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
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service base-addon-log-level: stopping
s6-rc: info: service base-addon-log-level successfully stopped
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service base-addon-banner: stopping
s6-rc: info: service base-addon-banner successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

Config file

mqtt:
  host: localhost
  status_payload_running: available
  status_payload_stopped: unavailable
  status_payload_dead: unavailable
  topic_prefix: torngardsbio
  user: "******"
  password: "********"
  ha_discovery:
    enabled: yes

gpio_modules:
  - name: rpi
    module: raspberrypi

digital_inputs:
  - name: East_50
    module: rpi
    pin: 18
    pullup: yes
    on_payload: "ON"
    off_payload: "OFF"
    ha_discovery:
       name: East_50

Steps to reproduce

I have a more or less clean HA installation on a 32Gb memory card. Raspberry Pi 4, 8Gb RAM.

Proposed changes

(If you have a proposed change, workaround or fix,
describe the rationale behind it)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.