Skip to content

Instantly share code, notes, and snippets.

@pezhore
Last active July 27, 2016 15:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pezhore/b36cdd7cd128920ace7e to your computer and use it in GitHub Desktop.
Save pezhore/b36cdd7cd128920ace7e to your computer and use it in GitHub Desktop.
Simple bash script that will poll for data on a DHT22 sensor and push to a Domoticz system
#!/bin/bash
# Domoticz server
SERVER="localhost:8080"
# IDX DHT
# The number of the IDX in the list of peripherals
DHTIDX="4"
#DHTPIN
# THE GPIO or connects DHT11
DHTPIN="17"
# If you have a DHT22 change further down the line Adafruit_DHT 11 by 22 Adafruit_DHT
# TMPFILE: path for temporary file in place to avoid the RAMDRIVE
# Scriptures on the SD card
# Otherwise be written way or the file containing the temperature
# /tmp/temper.txt Is a good choice if not installed RAMDRIVE
# Www.easydomoticz.com visit to learn all
TMPFILE="/var/tmp/temper.txt"
# Modified patrick from 03/08/15 to question 5 times max
cpt=0
while [ $cpt -lt 6 ]
do
TEMP=""
sleep 5
sudo nice -20 /home/pi/domoticz/scripts/AdafruitDHT.py 2302 $DHTPIN > $TMPFILE
TEMP=$(cat $TMPFILE|grep Temp |awk '{print $1}')
if [ $TEMP ]
then
TEMP=$(cat $TMPFILE|grep Temp |awk '{print $1}' |sed -r 's/^.*=//' | sed -r 's/\*//')
HUM=$(cat $ $TMPFILE |grep Temp |awk '{print $2}' | sed -r 's/^.*=//' | sed -r 's/\%//')
if [ $(echo "$HUM < 30" |bc) ]
then
COMFORT=2
elif [ $(echo "$HUM < 40" |bc) ]
then
COMFORT=0
elif [ $(echo "$HUM < 60" |bc) ]
then
COMFORT=1
else
COMFORT=3
fi
echo "TEMP: $TEMP"
echo "HUM: $HUM"
echo "COMFORT: $COMFORT"
# send data
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;$COMFORT"
TEMP=""
HUM=""
#rm $TMPFILE
exit 0
fi
echo "CPT: $cpt"
cpt=$(($cpt+1))
done
exit 1
@github0123456789
Copy link

Thanks for the script. I noticed that line 35 contains a typo. Please remove the double $.
The script works perfectly with Domoticz.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment