mirror of
https://github.com/nymea/nymea-plugins.git
synced 2026-10-24 14:55:39 +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 nymea
|
||||||
import board
|
import Adafruit_DHT
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
pollTimer = None
|
pollTimer = None
|
||||||
|
|
||||||
@ -51,6 +23,7 @@ def setupThing(info):
|
|||||||
def thingRemoved(thing):
|
def thingRemoved(thing):
|
||||||
if len(myThings()) is 0:
|
if len(myThings()) is 0:
|
||||||
global pollTimer
|
global pollTimer
|
||||||
|
del pollTimer
|
||||||
pollTimer = None
|
pollTimer = None
|
||||||
|
|
||||||
|
|
||||||
@ -60,16 +33,20 @@ def refreshSensor(thing):
|
|||||||
if thing.thingClassId == dht11ThingClassId:
|
if thing.thingClassId == dht11ThingClassId:
|
||||||
gpio = thing.paramValue(dht11ThingRpiGpioParamTypeId)
|
gpio = thing.paramValue(dht11ThingRpiGpioParamTypeId)
|
||||||
logger.log("GPIO pin:", gpio)
|
logger.log("GPIO pin:", gpio)
|
||||||
dhtDevice = adafruit_dht.DHT11(piPinMap[gpio], use_pulseio=False)
|
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, gpio)
|
||||||
thing.setStateValue(dht11TemperatureStateTypeId, dhtDevice.temperature)
|
logger.log("Temperature: %s, Humidity: %s" % (temperature, humidity))
|
||||||
thing.setStateValue(dht11HumidityStateTypeId, dhtDevice.humidity)
|
|
||||||
|
thing.setStateValue(dht11TemperatureStateTypeId, temperature)
|
||||||
|
thing.setStateValue(dht11HumidityStateTypeId, humidity)
|
||||||
|
|
||||||
elif thing.thingClassId == dht22ThingClassId:
|
elif thing.thingClassId == dht22ThingClassId:
|
||||||
gpio = thing.paramValue(dht22ThingRpiGpioParamTypeId)
|
gpio = thing.paramValue(dht22ThingRpiGpioParamTypeId)
|
||||||
logger.log("GPIO pin:", gpio)
|
logger.log("GPIO pin:", gpio)
|
||||||
dhtDevice = adafruit_dht.DHT22(piPinMap[gpio], use_pulseio=False)
|
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, gpio)
|
||||||
thing.setStateValue(dht22TemperatureStateTypeId, dhtDevice.temperature)
|
logger.log("Temperature: %s, Humidity: %s" % (temperature, humidity))
|
||||||
thing.setStateValue(dht22HumidityStateTypeId, dhtDevice.humidity)
|
|
||||||
|
thing.setStateValue(dht22TemperatureStateTypeId, temperature)
|
||||||
|
thing.setStateValue(dht22HumidityStateTypeId, humidity)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logger.crit("Unhandled thing class:", thing.thingClassId)
|
logger.crit("Unhandled thing class:", thing.thingClassId)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user