I try to setup AM2302 in HA 0.42.3 on RPi 3. HA installed in virtual env.
I got
17-04-14 16:17:04 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
17-04-14 16:17:06 ERROR (MainThread) [homeassistant.setup] Not initializing sensor.dht because could not install dependency http://github.com/adafruit/Adafruit_Python_DHT/archive/da8cddf7fb629c1ef4f046ca44f42523c9cf2d11.zip#Adafruit_DHT==1.3.0
17-04-14 16:17:06 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.dht: Could not install all requirements.
17-04-14 16:17:06 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up: * sensor.dht Please check your config, notification_id=invalid_config, title=Invalid config, domain=persistent_notification, service=create, service_call_id=1978607632-1>
17-04-14 16:17:06 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up: * sensor.dht Please check your config, notification_id=invalid_config, title=Invalid config, domain=persistent_notification, service=create, service_call_id=1978607632-2>
17-04-14 16:17:06 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: old_state=None, entity_id=persistent_notification.invalid_config, new_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up: * sensor.dht Please check your config; title=Invalid config @ 2017-04-14T16:17:06.980242+07:00>>
17-04-14 16:17:06 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1978607632-1>
17-04-14 16:17:07 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1978607632-2>
Apr 14 16:17:04 ha hass[725]: 17-04-14 16:17:04 WARNING (MainThread) [homeassistant.setup] Setup of sensor is taking over 10 seconds.
Apr 14 16:17:06 ha hass[725]: Command "/srv/homeassistant/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-0mk7ztmf-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-s_9nunnw-record/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/include/site/python3.4/Adafruit-DHT --home=/tmp/tmpjjyfo3hr" failed with error code 1 in /tmp/pip-0mk7ztmf-build/
Apr 14 16:17:06 ha hass[725]: 17-04-14 16:17:06 ERROR (MainThread) [homeassistant.setup] Not initializing sensor.dht because could not install dependency http://github.com/adafruit/Adafruit_Python_DHT/archive/da8cddf7fb629c1ef4f046ca44f42523c9cf2d11.zip#Adafruit_DHT==1.3.0
Apr 14 16:17:06 ha hass[725]: 17-04-14 16:17:06 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.dht: Could not install all requirements.
Apr 14 16:17:06 ha hass[725]: 17-04-14 16:17:06 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=message=The following components and platforms could not be set up:
Apr 14 16:17:06 ha hass[725]: * sensor.dht
Apr 14 16:17:06 ha hass[725]: Please check your config, notification_id=invalid_config, title=Invalid config, domain=persistent_notification, service=create, service_call_id=1978607632-1>
import paho.mqtt.client as mqtt
import time
import sys
import Adafruit_DHT
time.sleep(10) #Sleep to allow wireless to connect before starting MQTT
mqttc = mqtt.Client(client_id="lr_am2302")
mqttc.username_pw_set("usename", password="password")
mqttc.connect("localhost", port=1883, keepalive=60)
mqttc.loop_start()
topic_temp = "sensor/livingroom/temp"
topic_humidity = "sensor/livingroom/humidity"
while True:
try:
humidity, temp = Adafruit_DHT.read_retry(22, 24) #22 is the sensor type(22 for DHT22/AM2302, 11 for DHT11), 24 is the GPIO pin number.
if temp is not None:
temp = round(temp, 2)
mqttc.publish(topic_temp, payload=temp, retain=True)
if humidity is not None:
humidity = round(humidity, 2)
mqttc.publish(topic_humidity, payload=humidity, retain=True)
time.sleep(120)
except (EOFError, SystemExit, KeyboardInterrupt):
mqttc.disconnect()
sys.exit()
For me the solution was to add the user that runs homeassistant (in my case homeassitant) to the gpio group, in order to give him the rigths to read GPIOs