hassio-addons/addon-mqtt-io

Error when retrieving values from DHT22 Sensor

Closed this issue · 9 comments

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

We'll get there!

Opened up #18 to deal with that :)

We'll get there!

Opened up #18 to deal with that :)

Great! I'll wait and update as soon as I see it pop up and then report back to you :)

On my Home Assistant instance it still says the latest update is 0.1.1, is there anyway to force it to check for the 0.1.2 update? So I could test if the problem is resolved? :)

Go to setting -> updates -> Top right menu, check for updates.
The 0.1.2 version is being built and should be available any moment now.

2022-07-25 15:28:51 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 81, in read
    return platform.read(sensor, pin)
  File "/usr/lib/python3.10/site-packages/Adafruit_DHT/Raspberry_Pi_2.py", line 34, in read
    raise RuntimeError('Error accessing GPIO.')
RuntimeError: Error accessing GPIO.
2022-07-25 15:28:51 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 81, in read
    return platform.read(sensor, pin)
  File "/usr/lib/python3.10/site-packages/Adafruit_DHT/Raspberry_Pi_2.py", line 34, in read
    raise RuntimeError('Error accessing GPIO.')
RuntimeError: Error accessing GPIO.

This is the new error message that pops up when using the new 0.1.2 update. I'm using a Raspberry Pi 3B if that is important

Probably caused by:

https://github.com/adafruit/Adafruit_Python_DHT/blob/8f5e2c4d6ebba8836f6d31ec9a0c171948e3237d/source/Raspberry_Pi_2/pi_2_mmio.c#L43-L46

Not sure how to solve that.

I understand! But once again thank you so much for the help <3 If you need me to test something hit me up!

There hasn't been any activity on this issue recently, so we clean up some of the older and inactive issues.
Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thanks!

Did anyone manage to solve this at all? I've got the same problem of the RuntimeError: Error accessing GPIO. with an almost identical setup.