mirror of
https://github.com/nymea/nymea-plugins.git
synced 2026-07-19 00:54:53 +02:00
DHT: Move to different python lib
Seems the circuitpython one is not very reliable
This commit is contained in:
parent
eff66ea2f4
commit
6d5605f43b
@ -1,33 +1,5 @@
|
||||
import nymea
|
||||
import board
|
||||
import adafruit_dht
|
||||
|
||||
piPinMap = {
|
||||
"2": board.D2,
|
||||
"3": board.D3,
|
||||
"4": board.D4,
|
||||
"5": board.D5,
|
||||
"6": board.D6,
|
||||
"7": board.D7,
|
||||
"8": board.D8,
|
||||
"9": board.D9,
|
||||
"10": board.D10,
|
||||
"11": board.D11,
|
||||
"12": board.D12,
|
||||
"13": board.D13,
|
||||
"16": board.D16,
|
||||
"17": board.D17,
|
||||
"18": board.D18,
|
||||
"19": board.D19,
|
||||
"20": board.D20,
|
||||
"21": board.D21,
|
||||
"22": board.D22,
|
||||
"23": board.D23,
|
||||
"24": board.D24,
|
||||
"25": board.D25,
|
||||
"26": board.D26,
|
||||
"27": board.D27
|
||||
}
|
||||
import Adafruit_DHT
|
||||
|
||||
pollTimer = None
|
||||
|
||||
@ -51,6 +23,7 @@ def setupThing(info):
|
||||
def thingRemoved(thing):
|
||||
if len(myThings()) is 0:
|
||||
global pollTimer
|
||||
del pollTimer
|
||||
pollTimer = None
|
||||
|
||||
|
||||
@ -60,16 +33,20 @@ def refreshSensor(thing):
|
||||
if thing.thingClassId == dht11ThingClassId:
|
||||
gpio = thing.paramValue(dht11ThingRpiGpioParamTypeId)
|
||||
logger.log("GPIO pin:", gpio)
|
||||
dhtDevice = adafruit_dht.DHT11(piPinMap[gpio], use_pulseio=False)
|
||||
thing.setStateValue(dht11TemperatureStateTypeId, dhtDevice.temperature)
|
||||
thing.setStateValue(dht11HumidityStateTypeId, dhtDevice.humidity)
|
||||
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, gpio)
|
||||
logger.log("Temperature: %s, Humidity: %s" % (temperature, humidity))
|
||||
|
||||
thing.setStateValue(dht11TemperatureStateTypeId, temperature)
|
||||
thing.setStateValue(dht11HumidityStateTypeId, humidity)
|
||||
|
||||
elif thing.thingClassId == dht22ThingClassId:
|
||||
gpio = thing.paramValue(dht22ThingRpiGpioParamTypeId)
|
||||
logger.log("GPIO pin:", gpio)
|
||||
dhtDevice = adafruit_dht.DHT22(piPinMap[gpio], use_pulseio=False)
|
||||
thing.setStateValue(dht22TemperatureStateTypeId, dhtDevice.temperature)
|
||||
thing.setStateValue(dht22HumidityStateTypeId, dhtDevice.humidity)
|
||||
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, gpio)
|
||||
logger.log("Temperature: %s, Humidity: %s" % (temperature, humidity))
|
||||
|
||||
thing.setStateValue(dht22TemperatureStateTypeId, temperature)
|
||||
thing.setStateValue(dht22HumidityStateTypeId, humidity)
|
||||
|
||||
else:
|
||||
logger.crit("Unhandled thing class:", thing.thingClassId)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user