Page 1 of 1

DTH11 Sensor in Domoticz

Posted: Monday 20 April 2020 18:55
by dbertone76
Hallo,
i' ve installed correctly DTH11, temperature sensor hardware and it's all ok. I followed th einstruction in this link https://www.domoticz.com/forum/viewtopic.php?t=9531, if I run the command "$ python AdafruitDHT.py 11 17" i receive the correct result
Temp=22.0* Humidity=64.0%.
Now i am not able to use this sensor in domoticz. How i can do? Thank you ;)

Re: DTH11 Sensor in Domoticz

Posted: Monday 20 April 2020 19:37
by freijn
If you run the command it's a 1 shot only.

Did you do the last part as well?

Then add a Crontab with Crontab -e
add follow command
*/5 * * * * /home/pi/domoticz/scripts/dht_11.sh

save with STRG +O and exit with STRG + X

Now the cronjob refresh every 5 Minutes the Temp

Re: DTH11 Sensor in Domoticz

Posted: Monday 20 April 2020 20:06
by dbertone76
i used this ssh script
-----------------------------------------------------------------------------------------------------


#!/bin/bash
# Domoticz server
SERVER="192.168.1.84:8080"
# DHT IDX Dummy
DHTIDX="17"
#
#DHTPIN Gpio Pin
DHTPIN="17"

TEMP=""

until [ -n "$TEMP" ] ; do
sleep 5
sudo nice -20 AdafruitDHT.py 11 $DHTPIN > temp.txt
TEMP=$(cat temp.txt|grep Temp|cut -d"=" -f2|cut -d" " -f1)

done
TEMP=$(cat temp.txt|cut -d"=" -f2|cut -d" " -f1)
HUM=$(cat temp.txt|cut -d"=" -f3|cut -d" " -f1)
echo $TEMP
echo $HUM
# Send data
#curl -s -i -H "Accept: application/json" "http://192.168.1.84:8080/json.htm?type= ... EMP;$HUM;2"
TEMP=""
HUM=""
rm temp.txt

-------------------------------------------------------------------------------------------------------------

in var/tmp i see temp.txt but it's empty, there are no value.
i don't know where is the mistake. in the forum i find several file for dht11.sh but i not be able to find the correct version.

Re: DTH11 Sensor in Domoticz

Posted: Monday 20 April 2020 21:04
by dbertone76
i resolved the problem relating the temp.txt file, non it's ok, but i have got he problem relating the update of value in domoticz. I think there's a problem relating this piece of scritp.
http://127.0.0.1/json.htm?type=command& ... EMP;$HUM;2


--------------------------------------------------------------------------------------------------------------------------------------------
#!/bin/sh
# Domoticz server
SERVER="127.0.0.1"
# DHT IDX
DHTIDX="17"

# DHTPIN
DHTPIN="17"

# TEMP FILE
TMPFILE="/var/tmp/temp.txt"

cpt=0
while [ $cpt -lt 6 ]
do
TEMP=""

sleep 5

sudo nice -20 /home/pi/Adafruit_Python_DHT/examples/AdafruitDHT.py 11 $DHTPIN > /var/tmp/temp.txt
#TEMP=$(cat /var/tmp/temp.txt | grep "Temp" | awk '{ print $3 }')
#TEMP=$(cat /var/tmp/temp.txt | grep "Temp")

TEMP=$(awk ' /Temp/ {print substr ($0,6,4)}' /var/tmp/temp.txt)
#HUM=$(awk ' /Hudmidity/ {print substr ($0,0)}' /var/tmp/temp.txt)
#HUM=$(awk ' /Humidity/ {print 1$}' /var/tmp/temp.txt)
HUM=$(awk ' /Humidity/ {print substr ($0,22,4)}' /var/tmp/temp.txt)
echo $TEMP
echo $HUM

# Send data
curl -s -i -H "Accept: application/json" "http://127.0.0.1/json.htm?type=command& ... EMP;$HUM;2"

TEMP=""
HUM=""

#rm $TMPFILE
exit 0
#fi
#echo $cpt
cpt=$(($cpt+1))
done
exit 1

Re: DTH11 Sensor in Domoticz

Posted: Tuesday 21 April 2020 21:36
by freijn
Hi

in the first post you used the correct url. 192.168.1.84:8080

The last post is missing the port number.

In a browser you can test your update url by using the 192.168.1.84:8080 and see if that updates, then change the url in the script to the working one.

Also in the first post url you have hardcoded idx 5 and by variable idx 17. Please double check the correct idx .

Cheers,
Frank

Re: DTH11 Sensor in Domoticz

Posted: Wednesday 22 April 2020 15:37
by dbertone76
I used the correct ip 192.168.1.84:8080 and the result is:
---------------------------------------------------------------------------------------------------------------------------
pi@raspberrypi:~/domoticz/scripts $ ./dht_11.sh
22.0
63.0
HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: DMZSID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
------------------------------------------------------------------------------------------------------------------------------

and sensor is not updated in domoticz. If in my browser i try to type
http://192.168.1.84:8080/json.htm?type= ... ue=55;55;2"
everything go well. i think it's only a permission problem, but i can't resolve it :roll:




----------------------------------------------------------------------------------
#!/bin/sh
# Domoticz server
SERVER="192.168.1.84:8080"/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2"

# DHT IDX
DHTIDX="17"

# DHTPIN
DHTPIN="17"

# TEMP FILE
TMPFILE="/var/tmp/temp.txt"

cpt=0
while [ $cpt -lt 6 ]
do
TEMP=""

sleep 5

sudo nice -20 /home/pi/Adafruit_Python_DHT/examples/AdafruitDHT.py 11 $DHTPIN > /var/tmp/temp.txt
#TEMP=$(cat /var/tmp/temp.txt | grep "Temp" | awk '{ print $3 }')
#TEMP=$(cat /var/tmp/temp.txt | grep "Temp")

TEMP=$(awk ' /Temp/ {print substr ($0,6,4)}' /var/tmp/temp.txt)
#HUM=$(awk ' /Hudmidity/ {print substr ($0,0)}' /var/tmp/temp.txt)
#HUM=$(awk ' /Humidity/ {print 1$}' /var/tmp/temp.txt)
HUM=$(awk ' /Humidity/ {print substr ($0,22,4)}' /var/tmp/temp.txt)
echo $TEMP
echo $HUM

# Send data
# curl -s -i -H "Accept: application/json" "http://192.168.1.84:8080/json.htm?type= ... EMP;$HUM;2"
# curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&c=getauth&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2"
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2"

TEMP=""
HUM=""

#rm $TMPFILE
exit 0
#fi
#echo $cpt
cpt=$(($cpt+1))
done
exit 1

Re: DTH11 Sensor in Domoticz

Posted: Wednesday 22 April 2020 17:27
by freijn
Now change in your script

SERVER="192.168.1.84:8080"/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2"

into

SERVER="192.168.1.84:8080"

and test again

Re: DTH11 Sensor in Domoticz

Posted: Wednesday 22 April 2020 17:47
by dbertone76
sorry the code that i use is correct "SERVER="192.168.1.84:8080" , was only a problem of past and copy in my post relating the string .
if i try with this string
SERVER="192.168.1.84" i have not error problem in shell, but domoticz sensor is not update.
----------------------------------------------------------------------------------------------------------------------------
#!/bin/sh
# Domoticz server
SERVER="192.168.1.84:8080"
# DHT IDX
DHTIDX="17"

# DHTPIN
DHTPIN="17"

# TEMP FILE
TMPFILE="/var/tmp/temp.txt"

cpt=0
while [ $cpt -lt 6 ]
do
TEMP=""

sleep 5

sudo nice -20 /home/pi/Adafruit_Python_DHT/examples/AdafruitDHT.py 11 $DHTPIN > /var/tmp/temp.txt
#TEMP=$(cat /var/tmp/temp.txt | grep "Temp" | awk '{ print $3 }')
#TEMP=$(cat /var/tmp/temp.txt | grep "Temp")

TEMP=$(awk ' /Temp/ {print substr ($0,6,4)}' /var/tmp/temp.txt)
#HUM=$(awk ' /Hudmidity/ {print substr ($0,0)}' /var/tmp/temp.txt)
#HUM=$(awk ' /Humidity/ {print 1$}' /var/tmp/temp.txt)
HUM=$(awk ' /Humidity/ {print substr ($0,22,4)}' /var/tmp/temp.txt)
echo $TEMP
echo $HUM

# Send data
# curl -s -i -H "Accept: application/json" "http://192.168.1.84:8080/json.htm?type= ... EMP;$HUM;2"
# curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&c=getauth&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2"
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2"
#curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?&username=pi=&password=danilo1976=&type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TEMP;$HUM;2"


TEMP=""
HUM=""

#rm $TMPFILE
exit 0
#fi
#echo $cpt
cpt=$(($cpt+1))
done
exit 1

Re: DTH11 Sensor in Domoticz

Posted: Wednesday 22 April 2020 20:35
by dbertone76
the solution is:

SERVER="192.168.1.84:8080" to SERVER="user:[email protected]:8080"