Configuring a DHT22 sensor in Domoticz

      5 Comments on Configuring a DHT22 sensor in Domoticz

First get Domoticz installed on the Raspberry Pi.

sudo curl -L install.domoticz.com | sudo bash

Choose between HTTP and HTTPS protocol definition for connecting to the Domoticz web console.

Select the installation folder, default set to /home/pi/domoticz/

The settings, HTTP and HTTPS web interface definitions, are kept in the daemon script. You can easily edit this script by using sudo nano /etc/init.d/domoticz.sh.

Now introduce the DHT22 sensor script to the Domoticz installation.

#!/bin/bash
# Domoticz server
# Please replace [SERVER] and [PORT] to reflect the Domoticz server specifications
SERVER="[SERVER]:[PORT]"
# DHT IDX
# The number of the IDX in the list of peripherals
DHTIDX="18"
# DHTPIN
# The GPIO or connects DHT11
DHTPIN="22"
# TMPFILE: path for temporary file in place to avoid the RAMDRIVE
TMPFILE="/var/tmp/dht22.txt"
# Retry loop, try 5 times
cpt=1
while [ $cpt -lt 6 ]
do
TEMP=""
echo Attempt: $cpt
sudo nice -20 /home/pi/Adafruit_Python_DHT/examples/AdafruitDHT.py 22 $DHTPIN > $TMPFILE
TEMP=$(cat $TMPFILE | awk -F "=" '{print $2}' | awk -F "." '{print $1}')
HUM=$(cat $TMPFILE | awk -F "=" '{print $3}' | awk -F "." '{print $1}')
echo "Temp=" $TEMP
echo "Humid=" $HUM
# Send data
curl -s -i -H 'Accept: application/json' "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;0"
TEMP=""
HUM=""
exit 0
cpt=$(($cpt+1))
done
exit 1

5 thoughts on “Configuring a DHT22 sensor in Domoticz

  1. Martin Pavlík

    Thank you Berry,

    I’ve managed to make your script work with dht-22. I am noob in domoticz. How do I add the DHT-22 sensor in the GUI?

    When I run your script I end up with

    smc@osmc:~/domoticz/scripts$ ./dht-22.sh
    Attempt: 1
    Temp= 22
    Humid= 56
    HTTP/1.1 200 OK
    Content-Length: 24
    Content-Type: application/json;charset=UTF-8
    Cache-Control: no-cache
    Pragma: no-cache
    Access-Control-Allow-Origin: *

    {
    “status” : “ERR”
    }

    not sure what is needed on domoticz side of things.

    Reply
  2. Martin Pavlík

    Figured it out

    osmc@osmc:~/domoticz/scripts$ ./dht-22.sh
    Attempt: 1
    Temp= 22
    Humid= 58
    HTTP/1.1 200 OK
    Content-Length: 53
    Content-Type: application/json;charset=UTF-8
    Cache-Control: no-cache
    Pragma: no-cache
    Access-Control-Allow-Origin: *

    {
    “status” : “OK”,
    “title” : “Update Device”
    }
    osmc@osmc:~/domoticz/scripts$

    I needed to add dummy sensor as per http://blog.briankmarsh.com/domoticz/ and update DHTIDX accordingly

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.