After trying some things with the DHT22 in openhab3 (openHAB 3.0.2), I turn to you.
I tried to bring the output value from my bash script, which is stored in /etc/openhab/scripts, with items and things into my openhab.
I also used the EXEC binding, but it only gives me strings, which is of little use for a temperature sensor, because I want to display the values in a diagram.
Unfortunately all without success.
That’s why I ask myself the question:
“How can I include the temperature sensor DHT22 or DHT11 in Openhab3 without much trouble?”.
I have connected the DHT22 to a RaspberryPi 3 via the pins. To read the sensor I use the library “loldht” (https://github.com/technion/lol_dht22) to get stable values.
PIN=7
INPUT=$(/etc/openhab/lol_dht22/loldht $PIN | grep "Temperature")
NUM=1.00
HUMST=$(echo $INPUT|cut -d " " -f3)
TEMPST=$(echo $INPUT|cut -d " " -f7)
HUM=$(awk '{print $1*$2}' <<<"${NUM} ${HUMST}")
TEMP=$(awk '{print $1*$2}' <<<"${NUM} ${TEMPST}")
if [ "$1" = "HUM" ]; then
echo $HUM
fi
if [ "$1" = "TEMP" ]; then
echo $TEMP
fi
I call the script in the shell of the RaspberryPi (under raspbian) with the command:
/bin/bash /etc/openhab/scripts/dht22.sh TEMP
As result I get depending on which parameter I enter, “HUM” for the humidity or “TEMP” for my temperature. For example
The Exec binding will only support String as an output. So you’ll need to transform the String to a Number, even better a Number:Temperature. You can use a profile for that I think though.
You’ll need to install the JS transformation and use a transformation along the lines of
(function(i) {
return i + " °C" ;
})(input)
Make the Item be a Number:Temperature and I believe it will parse the string returned by the transformation.
If not you’ll have to write a Rule and use a proxy Item.
No, you need to apply this to the Exec binding Channel.
That’s the OH 1.x exec binding config. It will not work with the 2.x/3.x version of the binding and it will not work in OH 3 at all. Review the Exec binding’s docs. You will see in that the example Items in the doc do not resemble that Item’s config in any way.
Bindings connect to technologies. In this case it’s connecting to a command line script and external programs.
A Transformation is used to transform the states of Items. The Exec transformation lets you pass the value to an external script or program to transform it to something else. You are not using an external script to transform the Item’s state.
Hey @rlkoshak it works, or at least pretends to work.
When I have the thing like this I only get 0 out and not the numerical value of my script.
I think it’s because of REGEX unfortunately I have no idea about it because I’m a beginner.
I hope you can also help me in this case to get the dht22 running.
Greetings @3D_Schorsch
Make sure the REGEX transform is installed. I don’t think it’s required though.
I don’t mess with.things files so if you have an error there I can’t really help beyond saying almost all syntax errors are impossible when using the UI.
When things don’t work simplify. Keep the Item as String without any transformation. If that works add the transformation. If that works only then change to a Number:Temperature. If that doesn’t work then you’ll need to use a rule.
Sorry to be off topic but reading dht22 with raspberry pi 3 is not a bit of an overkill?
I would suggest using wemos d1 mini running tasmota with mqtt and everything become both cheap and easy to use
Sounds like they also run openHAB on the Pi, and are interested in the ambient temperature in the same area. Sounds appropriate - I’m doing the same as my Pi lives in the loft, but also runs other services.
@hafniumzinc yes that’s exactly how it is! i’m running openhab on the Raspberry Pi with the dht22 sensor connected to it.
If I want to use more DHT22 in the house in the future this is certainly a good idea @Marian_Grigore, I’ll keep that in mind.
@3D_Schorsch did you ever manage to solve the issue with the 0 as the response instead of the proper temperature?
I have tried to do the same but am stuck there.
Yes, I also had the thought that I have several areas where I connect per line the DHT22 and then send over the network to the Openhab.
In the meantime I have connected another Raspberry Pi in the basement, which reads out the DHT22 for me there.