New plugin: DHT11/DHT22/AM2302

pull/460/head
Michael Zanetti 2021-08-02 17:14:10 +02:00
parent 057251df08
commit 6cacf37d3c
8 changed files with 254 additions and 0 deletions

11
debian/control vendored
View File

@ -209,6 +209,17 @@ Description: nymea.io plugin for denon
This package will install the nymea.io plugin for denon
Package: nymea-plugin-dht
Architecture: any
Depends: ${shlibs:Depends},
${misc:Depends},
nymea-plugins-translations,
python3-pip,
Description: nymea.io plugin for DHT11/DHT22/AM2302
This plugin add support for the DHT11, DHT22 and AM2302 temperature and humidity
sensors to nymea.
Package: nymea-plugin-doorbird
Architecture: any
Depends: ${shlibs:Depends},

3
debian/nymea-plugin-dht.install.in vendored Normal file
View File

@ -0,0 +1,3 @@
dht/integrationplugindht.json usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/dht/
dht/integrationplugindht.py usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/dht/
dht/requirements.txt usr/lib/@DEB_HOST_MULTIARCH@/nymea/plugins/dht/

21
dht/README.md Normal file
View File

@ -0,0 +1,21 @@
# DHT11/DHT22/AM2302
This plugin allows to read temperature and humidity sensor values from DHT11, DHT22 and AM2302 sensors using the Adafruit_DHT library.
> IMPORTANT: This plugin will only work on Raspberry Pi and BeagleBone Black devices.
## Supported Things
* DHT11
* DHT22
* AM2302
## Requirements
* Nymea is installed on a Raspberry Pi or BeagleBone Black device
* The sensor must be connected to a GPIO properly. Please see the [Adafruit website](https://learn.adafruit.com/dht/connecting-to-a-dhtxx-sensor) for more informations how to connect it
* The package “nymea-plugin-dht” must be installed
## More
[Adafruit DHTxx documentation](https://learn.adafruit.com/dht)

5
dht/dht.pro Normal file
View File

@ -0,0 +1,5 @@
TEMPLATE = aux
OTHER_FILES = integrationplugindht.json \
integrationplugindht.py

View File

@ -0,0 +1,93 @@
{
"name": "dht",
"displayName": "DHT11/DHT22/AM3202",
"id": "04172a94-6c04-4ce7-9f12-fc95a83faabb",
"vendors": [
{
"name": "aosong",
"displayName": "AOSONG",
"id": "8b8677a0-7f27-45c1-95ba-367d7ddc611f",
"thingClasses": [
{
"id": "e81d51c8-ea50-44ef-846d-15b4bc8a34dc",
"name": "dht11",
"displayName": "DHT11",
"createMethods": ["User"],
"interfaces": ["temperaturesensor", "humiditysensor"],
"paramTypes": [
{
"id": "b22a85fa-04c6-4100-8592-e6b73f7758ce",
"name": "rpiGpio",
"displayName": "Raspberry Pi GPIO",
"type": "QString",
"defaultValue": "4",
"allowedValues": ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27"]
}
],
"stateTypes":[
{
"id": "0601aff0-77cf-4514-ac01-dd00b1abde87",
"name": "temperature",
"displayName": "Temperature",
"displayNameEvent": "Temperature changed",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0
},
{
"id": "e8a37289-db0e-4fd8-b1d0-7a8fdf4f68bf",
"name": "humidity",
"displayName": "Humidity",
"displayNameEvent": "Humidity changed",
"type": "double",
"unit": "Percentage",
"defaultValue": 0,
"minValue": 0,
"maxValue": 100
}
]
},
{
"id": "6978e5fe-7abf-4a37-898b-0391e83f2d8f",
"name": "dht22",
"displayName": "DHT22/AM2302",
"createMethods": ["User"],
"interfaces": ["temperaturesensor", "humiditysensor"],
"paramTypes": [
{
"id": "aaf2b9aa-ae46-44c2-9e3c-d2aebee54a8a",
"name": "rpiGpio",
"displayName": "Raspberry Pi GPIO",
"type": "QString",
"defaultValue": "4",
"allowedValues": ["2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27"]
}
],
"stateTypes":[
{
"id": "d94e4b35-db5f-4774-9872-7ae8f804a52f",
"name": "temperature",
"displayName": "Temperature",
"displayNameEvent": "Temperature changed",
"type": "double",
"unit": "DegreeCelsius",
"defaultValue": 0
},
{
"id": "52ad8bb2-4ae8-400e-be5d-8d6bdce218f2",
"name": "humidity",
"displayName": "Humidity",
"displayNameEvent": "Humidity changed",
"type": "double",
"unit": "Percentage",
"defaultValue": 0,
"minValue": 0,
"maxValue": 100
}
]
}
]
}
]
}

View File

@ -0,0 +1,85 @@
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
}
pollTimer = None
def setupThing(info):
logger.log("SetupThing for DHT11/22:", info.thing.name)
try:
refreshSensor(info.thing)
logger.log("Refreshed sensor values successfully. Setup went well.")
info.finish(nymea.ThingErrorNoError)
except:
logger.log("Error fetching sensor values. Setup failed.")
info.finish(nymea.ThingErrorHardwareFailure, "Error reading sensor values. Please verify if the sensor is properly connected and you've selected the correct GPIO.")
return
global pollTimer
if pollTimer is None:
pollTimer = nymea.PluginTimer(5, pollSensors)
def thingRemoved(thing):
if len(myThings()) is 0:
global pollTimer
pollTimer = None
def refreshSensor(thing):
logger.log("Refreshing sensor values:", thing.name)
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)
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)
else:
logger.crit("Unhandled thing class:", thing.thingClassId)
def pollSensors():
for thing in myThings():
try:
refreshSensor(thing)
except:
logger.warn("Error refreshing sensor values for", thing.name)

35
dht/requirements.txt Normal file
View File

@ -0,0 +1,35 @@
adafruit-circuitpython-dht==3.6.1 \
--hash=sha256:dc7ff98c82db88531affea7c92b7bc470ab1002730c3fd0cf54bafc020f6e333 \
--hash=sha256:7267c9d5bfc96ace5614ab92cba335343a768c9e72eec388e50e43f484e9b7b8
Adafruit-Blinka==6.13.0 \
--hash=sha256:acbcfb778dc5e37ad9ef0aa1e1998e597a99c8a2a08b0dda58c05681950ea1f2 \
--hash=sha256:4749873ee982f86d9fda03c1b81b01c042dfe8eda026b14dc98375e1866d3f0a
pyftdi==0.53.2 \
--hash=sha256:5ba6de65bfc7f9ac9ace145d0a3b5f6f24778a405876bd96a4e361437cc4ce77 \
--hash=sha256:eb88b0583c2ece4f1072ae7951f841f25fb71770833bb53d234c2936adc40841
Adafruit-PureIO==1.1.9 \
--hash=sha256:2caf22fb07c7f771d83267f331a76cde314723f884a9570ea6f768730c87a879 \
--hash=sha256:17473ffd6f00af6d4be37579baabc396cfceb682b305272e457f078241b6fd0e
pyusb==1.1.0 \
--hash=sha256:d69ed64bff0e2102da11b3f49567256867853b861178689671a163d30865c298 \
--hash=sha256:65686357bf89ec727189fbee1cf93b2cf15b82117ec17f88817137445db2c4e2
pyserial==3.5 \
--hash=sha256:3c77e014170dfffbd816e6ffc205e9842efb10be9f58ec16d3e8675b4925cddb \
--hash=sha256:c4451db6ba391ca6ca299fb3ec7bae67a5c55dde170964c7a14ceefec02f2cf0
Adafruit-PlatformDetect==3.15.3 \
--hash=sha256:726782879e1dc18c1b2f50301ab3f04c3a7817a54e35c955ee2bb64a6d60df74 \
--hash=sha256:e8c349cab441458886fb333e70e7d1134329cb23e5590a13da05d5a53df8c988
RPi.GPIO==0.7.0 \
--hash=sha256:7424bc6c205466764f30f666c18187a0824077daf20b295c42f08aea2cb87d3f \
--hash=sha256:6a4791f41cafc2ee6e4cb70e5bd31fadc66a0cfab29b38df8723a98f6f73ad5a
sysv-ipc==1.1.0 \
--hash=sha256:0f063cbd36ec232032e425769ebc871f195a7d183b9af32f9901589ea7129ac3 \
--hash=sha256:30611dccecd8fa0dc9f83d4d465e5047692df0ec9a095abef8b90ccc64afbdaf \
--hash=sha256:4bbbe4e5ad5ab859e6d21fc8ff3e3b01082b959fa5c2cd76289dbcd56350c5f9 \
--hash=sha256:61190b934b0277f7a189092dcabceee8d9736fd73de90fd9b50ea69f0bac4723 \
--hash=sha256:ff6e3c98d8aa3e1ae5378d86869c4699c76f94318705d08085c97fb010770a31 \
--hash=sha256:3cc523ce39338200c0ad7735c48267a26735690977b4eb4879bd8e10b4e7a82d
rpi-ws281x==4.3.0 \
--hash=sha256:0b9549687ab7117acbc4bac0e92742fd2c8290fd204514d72fed91c06ba2e805 \
--hash=sha256:656f86d9cda8ff2e2b0368c17b6afdf898234d414133bcc10f214864a6843453 \
--hash=sha256:e62576713938f81a4448711c41646caded0684b1df2ee4ff43ccd32d1dddd81f

View File

@ -14,6 +14,7 @@ PLUGIN_DIRS = \
daylightsensor \
denon \
doorbird \
dht \
dweetio \
dynatrace \
elgato \