Problems with DHT sensor platorm

I had an old DHT11 sensor so I thought id hook it directly to my Pi3 to give me a rough means to monitor the ambient temperature around all my media gear. Here is the entry in my config

sensor:
  platform: dht
  name: 'DHT11 sensor'
  sensor: DHT11
  pin: 4
  monitored_conditions:
    - temperature
    - humidity

But im getting errors in my log and the sensor does not show?

2017-12-10 23:37:29 ERROR (MainThread) [homeassistant.components.sensor] Error on device update!
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 217, in async_add_entity yield from entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)                                       
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.                                   
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()                                                                         
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception                                                                   
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)                                             
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/dht.py", line 125, in update self.dht_client.update()                                                                
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/util/__init__.py", line 306, in wrapper result = method(*args, **kwargs)                                                        
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/dht.py", line 160, in update self.sensor, self.pin)
  File "/srv/homeassistant/lib/python3.5/site-packages/Adafruit_DHT/common.py", line 94, in read_retry humidity, temperature = read(sensor, pin, platform)
  File "/srv/homeassistant/lib/python3.5/site-packages/Adafruit_DHT/common.py", line 81, in read return platform.read(sensor, pin)                                                       
  File "/srv/homeassistant/lib/python3.5/site-packages/Adafruit_DHT/Raspberry_Pi_2.py", line 34, in read raise RuntimeError('Error accessing GPIO.')
RuntimeError: Error accessing GPIO.                                                      
2017-12-10 23:37:29 ERROR (MainThread) [homeassistant.components.sensor] Error on device update!                                                                                    
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 217, in async_add_entity
    yield from entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/dht.py", line 125, in update
    self.dht_client.update()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/util/__init__.py", line 306, in wrapper
    result = method(*args, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/dht.py", line 160, in update
    self.sensor, self.pin)
  File "/srv/homeassistant/lib/python3.5/site-packages/Adafruit_DHT/common.py", line 94, in read_retry
    humidity, temperature = read(sensor, pin, platform)
  File "/srv/homeassistant/lib/python3.5/site-packages/Adafruit_DHT/common.py", line 81, in read
    return platform.read(sensor, pin)
  File "/srv/homeassistant/lib/python3.5/site-packages/Adafruit_DHT/Raspberry_Pi_2.py", line 34, in read
    raise RuntimeError('Error accessing GPIO.')
RuntimeError: Error accessing GPIO.
2017-12-11 02:48:30 ERROR (Thread-35) [pychromecast.socket_client] Failed to connect, retrying in 5.0s
2017-12-11 02:48:30 ERROR (Thread-26) [pychromecast.socket_client] Failed to connect, retrying in 5.0s
2017-12-11 04:30:13 ERROR (Thread-25) [pychromecast.socket_client] Failed to connect, retrying in 5.0s
2017-12-11 04:30:15 ERROR (Thread-34) [pychromecast.socket_client] Failed to connect, retrying in 5.0s
2017-12-11 05:30:11 ERROR (Thread-5) [homeassistant.components.sensor.speedtest] Error executing speedtest: Command '['/srv/homeassistant/bin/python3', '/srv/homeassistant/lib/python3.5/site-packages/speedtest.py', '--simple']' returned non-zero exit status 1
2017-12-11 06:00:08 ERROR (Thread-26) [pychromecast.socket_client] Error reading from socket.
2017-12-11 06:00:08 ERROR (Thread-35) [pychromecast.socket_client] Error reading from socket.
2017-12-11 06:00:38 ERROR (Thread-26) [pychromecast.socket_client] Failed to connect, retrying in 5.0s
2017-12-11 06:00:38 ERROR (Thread-35) [pychromecast.socket_client] Failed to connect, retrying in 5.0s
2017-12-11 06:00:47 ERROR (Thread-25) [pychromecast.socket_client] Failed to connect, retrying in 5.0s
2017-12-11 12:00:11 ERROR (Thread-14) [homeassistant.components.sensor.speedtest] Error executing speedtest: Command '['/srv/homeassistant/bin/python3', '/srv/homeassistant/lib/python3.5/site-packages/speedtest.py', '--simple']' returned non-zero exit status 1

Looks like mine. Though out of curiosity, does it work without the name line?

  name: 'DHT11 sensor'

That’s one bit mine doesn’t have. Other than that I guess perhaps the pin number?

If I remove the name I still don’t see the sensor in my front end.
I’ve highlighted which pin the dht11 is attached to. Which is 4? Just to make sure I haven’t made a stupid schoolboy error.
Is the error regard gpio access the problem here?

Yeah, looks right to me.

I use pin 14, the one just above.

Is it the sensor itself maybe?

I can vouch for the DHT22 being a great replacement!

I’m really not sure.
The sender was working when last used so don’t see any reason it’d stop working

I think I may have a similar problem. I have tried installing a working DHT22 (tested with the Adafruit_DHT, both python2.7 and unofficial python3.5 releases) on a Raspberry Pi B+. The pin is correct.

I’m using Raspbian Stretch with Homeassistant 0.59.1 installed in a python virtual env.

Every time I try to boot the device I release the below error.

   Tue Dec 12 2017 10:43:00 GMT+0000 (GMT Standard Time)

Error on device update!
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 217, in async_add_entity
    yield from entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/dht.py", line 125, in update
    self.dht_client.update()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/util/__init__.py", line 306, in wrapper
    result = method(*args, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/sensor/dht.py", line 160, in update
    self.sensor, self.pin)
  File "/srv/homeassistant/lib/python3.5/site-packages/Adafruit_DHT/common.py", line 94, in read_retry
    humidity, temperature = read(sensor, pin, platform)
  File "/srv/homeassistant/lib/python3.5/site-packages/Adafruit_DHT/common.py", line 81, in read
    return platform.read(sensor, pin)
  File "/srv/homeassistant/lib/python3.5/site-packages/Adafruit_DHT/Raspberry_Pi_2.py", line 34, in read
    raise RuntimeError('Error accessing GPIO.')
RuntimeError: Error accessing GPIO.

I’ve tried editing the Adafruit_DHT files in the HA virtualenv. It shouldn’t be a GPIO permissions issue as they are not needed post Jessie.

I assume there are issues with the Adafruit_DHT implementation that HA is using, is there anyway in changing this, or testing it?

That lines up with my working ones, which are running an older version of Hassbian with HA 0.57 on it.

Have you tried installing Adafruit DHT on its own and test the sensor

cd ~
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo python3 setup.py install

and test it using

cd examples
adafruit_dht.py 11 4

I might try changing the dht.py requirements, and delete the current adafruit_dht python package

REQUIREMENTS = ['https://github.com/adafruit/Adafruit_Python_DHT']

I haven’t tried using the Adafruit library since upgrading to Stretch.
But I did use it whilst on Jessie lite and it worked fine.

I guess I can try that later.

What do you mean by this…change what and how and to what?

When the DHT component is loaded up by HA it installs the required adafruit_DHT program. I think the one currently in the requirements is incorrect and causing issues with GPIO interface,

This fork i’ve made has the requirements change https://github.com/googanhiem/home-assistant/blob/dev/homeassistant/components/sensor/dht.py

Still haven’t tested it.

I installed the Adafruit library via git-clone etc and it works OK, so I think you are correct.
Have you filed an issue?

How can I test your changes?

I’ve tested the changes, and they didn’t work. For some reason HA using adafruit_dht isn’t able to communicate with the GPIO pins.

I’m going to try a couple other things, but I’m out of ideas.

I’ve written a binary sensor using adafruit_dht example script to act as a stopgap, I’ll share that once its stable.

Ah OK, most strange

I was planning on writing a simple python programme that would read the temp sensor every x minutes and send it to HA using MQTT (paho)
But im interested in your binary sensor so will wait for that!
Thanks

im still having difficulties getting a DHT sensor to work with the component?

for anyone that may stumble upon this I found a solution.
your home assistant user must be added to the gpio group, in my case the user is homeassistant

sudo adduser homeassistant gpio

then a reboot of the pi is required sudo reboot

in actual fact it took 2 reboots for this to work for me?

4 Likes

Thanks for the tip. I was struggling with this.

Sorry, Im new to this and have the same issue.
Can you explain how you did it?
10x

Hi
How do I putty on Has.io?
Thanks.