Page 1 of 2

DHT11 Help !!!

Posted: Sunday 18 October 2020 22:30
by arhangel76
Hello everybody,I tried different tutorials but I can't add this sensor DHT11 in domoticz,please help me with an updated tutorial.

I thank you from the bottom of my heart. :idea:

Re: DHT11 Help !!!

Posted: Monday 19 October 2020 7:04
by kiddigital
Please provide more details on your setup and how you have connected the sensor and which Domoticz hardware module you are trying to use for this.

Re: DHT11 Help !!!

Posted: Monday 19 October 2020 8:36
by arhangel76
ok,sorry for poor details,i use raspberry pi 3,and last version of domoticz,i succeed to conect and setup 4 5v relays and i need to add this sensor.
this is my conections:
vcc- +3,3v
gnd
signal - pin7

Re: DHT11 Help !!!

Posted: Monday 19 October 2020 9:51
by Jan Jansen
@arhangel76,

viewtopic.php?f=12&t=9531>>may help you further.

Re: DHT11 Help !!!

Posted: Monday 19 October 2020 14:39
by kiddigital
@arhangel76 ,

There are a few options/path you can look at. It does not work straight out of the box without doing anything.

There are a few 'hardware' modules to try:
- 1-Wire (System)
- generic sysgpio
- I2C sensors
- Raspberry GPIO sensors

Your sensor is not an I2C sensor and as far as I know not a (Dallas) 1-Wire compatible sensor, so I would guess to start with GPIO.

I know that I have a few sensor on my raspberry (the one that runs Domoticz) through a HAT board (Automation HAT) where Domoticz reads the data using the 'generic sysgpio' module. But therefor I have to 'configure' sysfs GPIO (tell which gpio pins have which function) at boot before starting Domoticz.

From the sourcecode of the 'Raspberry GPIO sensors': (Maybe start here?)

Code: Select all

Connection information:
	This hardware uses the pins of the Raspebrry Pi's GPIO port.
	Please read:
	http://wiringpi.com/pins/special-pin-functions/
	http://wiringpi.com/pins/ for more information
	As we cannot assume domoticz runs as root (which is bad), we won't take advantage of wiringPi's numbering.
	Consequently, we will always use the internal GPIO pin numbering as noted the board, including in the commands below

	Pins have to be exported and configured beforehand and upon each reboot of the Pi, like so:
	- For output pins, only one command is needed:
	gpio export <pin> out

	- For input pins, 2 commands are needed (one to export as input, and one to trigger interrupts on both edges):
	gpio export <pin> in
	gpio edge <pin> both

	Note: If you wire a pull-up, make sure you use 3.3V from P1-01, NOT the 5V pin ! The inputs are 3.3V max !

Re: DHT11 Help !!!

Posted: Monday 19 October 2020 18:13
by arhangel76
the idea is that in the command line it works perfectly what I want is to add it in the web page

Re: DHT11 Help !!!

Posted: Monday 19 October 2020 20:44
by kiddigital
Therefor one of the hardware modules should be able to read the sensor and put the readings into sensors.

Or do it yourself through scripts (using a Dummy sensor), see earlier suggestion.

The forum and Wiki have plenty examples.

Re: DHT11 Help !!!

Posted: Tuesday 20 October 2020 17:29
by arhangel76
So there is no exact tutorial for such a thing....
im beginer and i dont understand all....

Re: DHT11 Help !!!

Posted: Tuesday 20 October 2020 20:30
by kiddigital
Not that I know off, but maybe we can help one step at the time...

You say it works from the commandline. Can you show your command(s) and the output per command?

DHT11 Help !!!

Posted: Wednesday 21 October 2020 0:43
by arhangel76
Ok i will post that...
Thank for try to help me

Re: DHT11 Help !!!

Posted: Thursday 22 October 2020 20:59
by arhangel76
ok look picture:

https://prnt.sc/v4sw0f

Re: DHT11 Help !!!

Posted: Friday 23 October 2020 6:52
by kiddigital
Ok, so you run a script. If you post the content of the script, than will tell use more.

Re: DHT11 Help !!!

Posted: Friday 23 October 2020 6:58
by arhangel76
#!/bin/sh

# Domoticz server
SERVER="127.0.0.1:8080"
# DHT IDX
DHTIDX="10"

# DHTPIN
DHTPIN="4"

sleep 5

sudo nice -20 python /home/root/domoticz/scripts/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://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TE$
#echo curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&sval$

TEMP=""
HUM=""

Re: DHT11 Help !!!

Posted: Friday 23 October 2020 7:08
by kiddigital
arhangel76 wrote:

Code: Select all

#!/bin/sh

# Domoticz server
SERVER="127.0.0.1:8080"
# DHT IDX
DHTIDX="10"

# DHTPIN
DHTPIN="4"

sleep 5

sudo nice -20 python /home/root/domoticz/scripts/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://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&svalue=$TE$
#echo curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=0&sval$

TEMP=""
HUM=""
Ok, your script look (almost) ok.
Can you show the Devices overview of Domoticz? Especially Device with idx 10 as your script uses that one?

Re: DHT11 Help !!!

Posted: Friday 23 October 2020 7:17
by arhangel76
do you mean this?

#! /bin/bash

printf "Set GPIO"
printf "\n"

#relay pos1
echo 17 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio17/active_low"
echo high > /sys/class/gpio/gpio17/direction

#relay pos2
echo 27 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio27/active_low"
echo high > /sys/class/gpio/gpio27/direction

#relay pos3
echo 22 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio22/active_low"
echo high > /sys/class/gpio/gpio22/direction

#relay pos4
echo 23 > /sys/class/gpio/export
sudo sh -c "echo '1' >> /sys/class/gpio/gpio23/active_low"
echo high > /sys/class/gpio/gpio23/direction
exit 0

Re: DHT11 Help !!!

Posted: Friday 23 October 2020 7:21
by kiddigital
Not really, this is a different script. When do you run this script?

Please make a screenshot of Domoticz Device settings screen showing Device 10

Re: DHT11 Help !!!

Posted: Friday 23 October 2020 7:25
by arhangel76

Re: DHT11 Help !!!

Posted: Friday 23 October 2020 7:34
by kiddigital
arhangel76 wrote:

Code: Select all

#!/bin/sh

# Domoticz server
SERVER="127.0.0.1:8080"
# DHT IDX
DHTIDX="10"

# DHTPIN
DHTPIN="4"

sleep 5

sudo nice -20 python /home/root/domoticz/scripts/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

Try changing this line:

Code: Select all

# Send data
curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=udevice&idx=$DHTIDX&nvalue=$TEMP&svalue=$TEMP
It sets the **nValue** (numeric) of the Sensor (sensor 10).

Also it also sends $TEMP instead of $TE$. (Is that a typo?)

Re: DHT11 Help !!!

Posted: Friday 23 October 2020 7:39
by arhangel76
probably the editing error

Re: DHT11 Help !!!

Posted: Friday 23 October 2020 7:47
by arhangel76