Make sure you are running the latest version of Home Assistant before reporting an issue.
You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:
Home Assistant release (hass --version):
0.27.1
Python release (python3 --version):
Python 3.4.2
Component/platform:
Raspberry Pi Model B Revision 2.0 512MB RAM / DHT11 Sensor
Description of problem:
Getting errors
Expected:
Can not see the DHT11 sensor in Home Assistant after upgrading to latest version.
Problem-relevant configuration.yaml entries and steps to reproduce:
This is the line inside my configuration.yaml file
sensor: !include devices/sensors.yaml
This is the code inside the sensors.yaml file
# DHT11 Temperature/Humidity Sensor
- platform: dht
sensor: DHT11
pin: 17
name: DHT11
monitored_conditions:
- temperature
- humidity
# polling_interval: 10000
# scan_interval: 10
# interval_seconds: 10
Error
16-09-01 09:53:46 homeassistant.components.sensor: Error while setting up platform dht
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 98, in _setup_platform
discovery_info)
File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/dht.py", line 65, in setup_platform
DHTSensor(data, variable, SENSOR_TYPES[variable][1], name))
File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/dht.py", line 85, in __init__
self.update()
File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/dht.py", line 104, in update
self.dht_client.update()
File "/usr/local/lib/python3.4/dist-packages/homeassistant/util/__init__.py", line 296, in wrapper
result = method(*args, **kwargs)
File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/sensor/dht.py", line 134, in update
self.pin)
File "/root/.homeassistant/deps/Adafruit_DHT/common.py", line 90, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/root/.homeassistant/deps/Adafruit_DHT/common.py", line 76, in read
platform = get_platform()
File "/root/.homeassistant/deps/Adafruit_DHT/common.py", line 48, in get_platform
from . import Raspberry_Pi
File "/root/.homeassistant/deps/Adafruit_DHT/Raspberry_Pi.py", line 22, in <module>
from . import Raspberry_Pi_Driver as driver
ImportError: cannot import name 'Raspberry_Pi_Driver'
16-09-01 09:55:34 homeassistant.helpers.condition: Value cannot be processed as a number: unknown
16-09-01 09:55:53 homeassistant.helpers.condition: Value cannot be processed as a number: unknown
16-09-01 09:55:53 homeassistant.helpers.condition: Value cannot be processed as a number: unknown
Additional info:
@roidayan could you have a look at this one?
Raspberry_Pi_Driver should be in Raspberry_Pi_Driver.cpython-34m.so
Can you check you have this file /root/.homeassistant/deps/Adafruit_DHT/Raspberry_Pi_Driver.cpython-34m.so ?
you can also do the following test:
# cd /root/.homeassistant/deps/Adafruit_DHT
# python3 -c "import Raspberry_Pi_Driver as driver; print(driver.__file__)"
expected output:
/root/.homeassistant/deps/Adafruit_DHT/Raspberry_Pi_Driver.cpython-34m.so
I get similar errors but with a DHT22. I have the file present and get the expected output.
you get the expected output and still get the error in the log "cannot import name 'Raspberry_Pi_Driver'" ?
No I don't get the import error, I get something about needing to run as sudo, am rebuilding atm, if it continues I'll post the exact error.
maybe you run an older version of home-assistant were the imported Adafruit_DHT library required root. latest version of home-assistant fetches newer version of Adafruit_DHT that doesn't require root (tested on raspbian).
Hi I got it working in the end by adding hass to groups gpio & root. It wouldn't work until I did that. Latest raspian using the all in one HA installer.
I really wouldn't add the hass user to root. Adding it to the gpio group should enough.
I tried doing that initially and it didn't work. I know according to the current help it should but it didn't.
Assume it's something in the all in one installer that causes it? I didn't read anything about having to add hass to gpio either, shouldn't the all in one set everything up so a simple .yaml modification gets anything working? That is the way the instructions come across.
Are you on Raspbian distribution?
Can you try updating to latest kernel and latest firmware using rpi-update?
Please also separate your issue to a different thread. The original issue is Python import and not accessing gpio as non-root user.
Hi, yes I downloaded everything within the last 3 days, Raspian Jessie, then the all in one using the instructions given. Being new to HA and not linux literate, I made sure I followed each step very carefully. Apologies for hijacking the thread, I guess I don't have an issue now, was just trying to clear up what I did and how I got it working.
I also got around this problem by adding hass to groups gpio & root. This does not surprise me that this is what's required. Tony D. from Adafruit said the Adafruit driver the the DHT series devices must be run as admin because it depends on C or C++ code that directly accesses memory locations. This was necessary because of the speed required to capture the burst of data. Got this info from his youtube videos. Looking forward to the day this sensor can be read without having to be an admin.
This is incorrect and not related to speed in any way. Root was needed because of access to the gpio that was not exposed in older kernels. In latest Raspbian kernel it is now possible to use gpio through the new new /dev/gpiomem interface which requires 2 things. To be in group gpio which the pi user is already in and update to the app/lib that use the gpio to actually use /dev/gpiomem.
So using latest Raspbian make sure you use latest kernel and firmware as well and you are in a group gpio and check that you have /dev/gpiomem and homr-assistant already fetch the latest ads fruit lib for dht11 that will use /dev/gpiomem.
The issue described here is Python error only. When/if someone is using old kernel/fw/gpiomem doesn't exists/.. then error that root is required will appear in the log.
Then again merely updating the kernel and fw and making sure the user being used is in group gpio (user pi already is) then error for requiring shouldn't appear. And it's not the issue described here.
Roidayan,
I formatted an SD card this past weekend for use on a Pi 3, installed the latest Raspbian Jesse, updated and installed home assistant in a virtual environment with instructions provided at https://home-assistant.io/getting-started/installation-raspberry-pi/ that creates a user called homeassistant to run home assistant in a virtual environment. I've since updated home assistant in hope of resolving my issue. It was only resolved when I did the same as acornatm. That is, by ensuring the homeassistant user was not only added the GPIO group, but adm as well.
Roidayan, what are you doing differently than acornatm and I to make DHT sensors show up for you? Or are you speaking from opinion?
My understanding, that comes from Tony DiCola of Adafruit, seems to explain why admin is needed. That is, even though recent releases of Raspian no longer require admin to use GPIO , admin is still required to use the Adafruit DHT sensor library because it utilizes memory mapped IO for speed purposes to capture the data.
Reference this video:
Raspberry Pi & Python Internet 'Thing' Pt. 3 with Tony D! @adafruit
see time position 11:56
On Mon, Sep 12, 2016 at 11:06 PM, Roi Dayan [email protected] wrote:
This is incorrect and not related to speed in any way. Root was needed because of access to the gpio that was not exposed in older kernels. In latest Raspbian kernel it is now possible to use gpio through the new new /dev/gpiomem interface which requires 2 things. To be in group gpio which the pi user is already in and update to the app/lib that use the gpio to actually use /dev/gpiomem.
So using latest Raspbian make sure you use latest kernel and firmware as well and you are in a group gpio and check that you have /dev/gpiomem and homr-assistant already fetch the latest ads fruit lib for dht11 that will use /dev/gpiomem.
The issue described here is Python error only. When/if someone is using old kernel/fw/gpiomem doesn't exists/.. then error that root is required will appear in the log.
Then again merely updating the kernel and fw and making sure the user being used is in group gpio (user pi already is) then error for requiring shouldn't appear. And it's not the issue described here.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
Roidayan,
My error might be different than that posted here, but my problem matched that in 'Expected' at top of this thread. That is, I could not see the DHT readings in the app until my user was added to group adm. I added my comments because what worked for atmacorn worked for me and thought it might be useful. I can provide my errors here or if you advise, I can open another issue.
Hi @uberknot,
Thanks for the detailed input.
I never tried the raspberry installation instructions but they seem to be the same as the normal procedure described here https://home-assistant.io/getting-started/installation-virtualenv/ beside of creating a new user. I basically installed in virtualenv folder with the default user pi.
Notice the video is from April and he mentioned in the video that the library is using the fast memory access interface /dev/mem (instead of sysfs or something else) which requires root because this is what he had at the time to access the gpio. (not because working with root is faster but because only root can access /dev/mem)
The commit to fix the library was introduced in Jun. see here https://github.com/adafruit/Adafruit_Python_DHT/commit/98df7ee89d54bcb384ea1597b4818def4f944c2a
You mentioned you needed to be in group adm and maybe this is correct, I haven't verified it.
here are the default groups user pi is in by default:
uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),101(input),108(netdev),997(gpio),998(i2c),999(spi)
so both adm and gpio are there. I see also i2c and spi that you might need in the future to access some features.
Since I used the default user pi I didn't have to do anything to make gpio access work without root.
I think the raspberry installation guide here was written before or without considering the gpiomem access. so I guess it should be just updated to set correct groups.
as for the issue. before adding gpio,adm groups to your homeassistant user. did you get python import error as described here? what is the exact error you got? can you copy paste?
I'll try to verify this as well.
@riaandeyzel @uberknot Verified and tested several times in the creation of the new installation guide for the Raspberry Pi.
The DHT sensors will work on a Raspbian Lite installation, installed in a Virtual Env on a separate user. The new user will need to be added to the gpio group.
To read the full guide have a look here.
@uberknot,
I did some tests. I removed user pi from group adm and restarted hass. I didn't get any errors and I can still get readings from DHT11.
Removing the pi user from the gpio group did give me an error from the dht component:
Sep 14 08:23:45 raspberrypi hass[15452]: RuntimeError: Error accessing GPIO.
And also from the binary sensor component:
Sep 14 08:23:33 raspberrypi hass[15452]: RuntimeError: No access to /dev/mem. Try running as root!
It logs it wants access to /dev/mem but I think it's a fallback from gpiomem since being in the gpio group didn't generate any error.
So the error is not the same as described in this issue which is a python import error and I only needed group gpio.
I think it might have been an issue with the all-in-one installer, I rebuilt from scratch with Jessie Lite +2.8.2 and the new pi instructions yesterday (because the all-in-one script now doesn't work), and can confirm that I can see my DHT22 simply by adding the user homeassistant to the gpio group.
What was a problem for me this time was following the instructions for autostarting . I got it working in the end, but probably not the right way. When I finally worked out that the autostart script needs the user changing to homeassistant and the ExecStart=/srv/h...a/h..a_venv/bin/hass it asks you for a password. I got round that by doing sudo su before entering the script. So now it's all working but I have no idea if that was the right way. The instructions for pi installation are perfect but the autostart section should really be added to the end of it, and made as copy&paste as the rest of the install instructions.
Sorry to elongate the thread with irrelevance, but once again I'm new to this, so forgive. I would have no idea where to post my non-issues anyway! Seems like the op either sorted it, gave up, or committed sudoku.
@Landrash @roidayan @acornatm
First, thank all of you for your input.
Second, I'm really digging this application and looking forward to see what I can do with it.
Third, since users are having success seeing DHT sensors without having to add the user to the admin group, I feel I should investigate further. I plan to start from scratch with a fresh install of Jesse Lite and will report my results here with any errors encountered. Before I do so, I can say the only thing I did different from the install instructions was to use the full install of Raspian instead of the lite version. Not sure why this would make a difference.
Thanks again.
@riaandeyzel Can we consider this to be resolved?
Update to my DHT sensor issue:
I did a fresh install using Raspian Lite, this time on a Pi 2. I no longer have to add the home-assistant user to the adm group. Not sure why, but my problem seems to have been using the regular Raspian distro. Doing so, caused me not to see my DHT sensors without adding the home-assistant user to the admin group.
I used the following instructions:
Raspberry Pi installation:
https://home-assistant.io/getting-started/installation-raspberry-pi/
And auto start:
https://home-assistant.io/getting-started/autostart-systemd/
All, thank you for your comments. My issue is resolved.
@uberknot 👍
We can close this issue.