User Tools

Site Tools


dh22

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
dh22 [2021/12/14 22:32] – created admindh22 [2021/12/19 21:07] (current) admin
Line 1: Line 1:
-====== DH22 ======+====== DH22 - HomeAssistant ====== 
 + 
 +Get values (temperature and humidity) from DH22, round the values and send it to HomeAssistant
  
 <code python> <code python>
-#!/usr/bin/python+#!/usr/bin/python3
  
-import os, sys 
 import Adafruit_DHT import Adafruit_DHT
 import time import time
 import requests import requests
-import html 
  
 def sendData(name, sensor, value, unit): def sendData(name, sensor, value, unit):
Line 22: Line 22:
 sensor = Adafruit_DHT.DHT22 sensor = Adafruit_DHT.DHT22
  
-# The GPIO17 - Board number 11 +# The GPIO17 - Board number 3 
-pin = '17'+pin = '2'
  
 humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
Line 31: Line 31:
     now = time.strftime('%d-%m-%Y %H:%M:%S', time.localtime(epoch))     now = time.strftime('%d-%m-%Y %H:%M:%S', time.localtime(epoch))
  
-    sendData('Pi Humidity', 'radiopi_humidity', humidity, '%'+    sendData('KitchenPi Humidity', 'kitchenpi_humidity', round(humidity, 3), '%'
-    sendData('Pi Temperature', 'radiopi_temperature', temperature, 'C')+    sendData('KitchenPi Temperature', 'kitchenpi_temperature', round(temperature, 3), 'C')
  
     print('"{0:s}","{1:0.1f}","{2:0.1f}"'.format(now, temperature, humidity))     print('"{0:s}","{1:0.1f}","{2:0.1f}"'.format(now, temperature, humidity))
dh22.1639517551.txt.gz · Last modified: 2021/12/14 22:32 by admin