How can I get data of DHT22 that connected to GPIO on Raspberry running Openhab

Try this:


Number	tmp_keller					"Keller [%.1f °C]"	
Number	humidity_keller		  			"Keller [%.1f %%]"


rule "Keller"
	Time cron "0 */5 * * * ?"
	val TEMP = executeCommandLine("/", 5000)
	if (TEMP.toString().length <= 5) tmp_keller.postUpdate(TEMP)
	val HUMID = executeCommandLine("/", 5000)
	if (HUMID.toString().length <= 5) humidity_keller.postUpdate(HUMID)
	logInfo("Keller", "Temperatur: " + TEMP.toString() + "°C, Feuchte: " + HUMID.toString() + "%")

wtf…it works now :scream:
1000 x thx fo your help.
next step: some graphs, but not today anymore :slight_smile:

sry but these are my first steps with openhab.
i understand the item, sitemap things but i should work with rules-wiki.

also dann danke nochmals stefan!!!

Cool! Glad i could help! Feel free to ask if there are questions within that small code!

Gerne, dafür ist das Ganze hier :wink:

Today i test the script, and i have strange reading from DHT11 sensor, the value of temperature and humidity from the sensors are floating. If temperature is 9 degree Celsius one reading is 9 next reading is 4. and humidity is the same if humidity is 35% one reading is 35% some readings after is 140%. I use DHT11 reading every 5 seconds, power sensors with 3.3V and i have resistor 4K8 to VCC and Signal. Trying also to read sensor every 60sek… the same think, down on the link is picture of the chart. Is anybody have idea whats wrong? what have to check?

I have a DTH11, its working ok when I run it from the command line using horschte instructions, but the SItemap shows no values. The text and the icons are there but ther are no values for temp or the Humidity.

I should be missing something. There are no errors in the logs.

I also tried spy0r aproach and the same thing happens.

Any idea what I’m doing wrong ?

Thanks for the help

If you don’t provide any information that is almost impossible …
Post your items and sitemap entries and tell us on which topic you are receiving your temp and hum values.

1 Like

Sorry for beeing short on the information. Here goes:

sitemap default label=“Sitemap Vila Alice”{
Frame label=“Demo” {
Text item=Temp1 label="Temperatura1 [%.2f ºC]"
Switch item=Wifi_ZAP label="ZAP"
Text item=temp_k
Text item=humidity_keller
Text item=TempA

Switch Wifi_ZAP “ZAP” {channel=“network:device:192_168_1_1:online”}
Number Temp1 “Temperatura1 [%.2f C]” {exec="<[python /etc/openhab2/scripts/]"}
Number temp_k “Keller [%.1f °C]”
Number humidity_keller “Keller[%.1f %%]”
Number TempA “TemperaturaA [%.2f C]” {exec="<[sudo /usr/bin/python /etc/openhab2/scripts/

rule "Keller"
Time cron "0 */5 * * * ?"
val TEMP = executeCommandLine(“python /etc/openhab2/scripts/”, 5000)
if (TEMP.toString().length <= 5) tmp_keller.postUpdate(TEMP)
val HUMID = executeCommandLine(“python /etc/openhab2/scripts/”, 5000)
if (HUMID.toString().length <= 5) humidity_keller.postUpdate(HUMID)
logInfo(“Keller”, "Temperatur: " + TEMP.toString() + "°C, Feuchte: " + HUMID.toString() + “%”)

As I mentioned before and both run ok on the command line.
There’s no error on the log
The sitemap apears Ok, but no values are dispalyed.

This is the display of the Sitemap (copy /paste):

  • ºC
  • °C
  • %
  • C

Unfortunately I have never used any Phyton scripts with the exec binding and therefore am not able to help.
The only hint I can give you: is openHAB able to read the *.py scripts?
When you execute them from the command line you normally have a different user (or even root) as whether you want openHAB (user:group openhab:openhab) to read the file …

1 Like

Thanks for your hint.

After your answer I checked the permissions in:

and followed the info in:

In the Paper UI its already working
Thanks :slight_smile:


Hi guys

I’m new with openhab.
Can anyone do like a step by step guide how to get the DHT working?
ex: Go to items tab, do this and this then install with SSH Adafrui DHT…

Hi Friends, I’m doing the above. But I can not read the OH2 data. Please be glad if you share some more descriptive information.

Below is the code I am writing;
Number HomeTemperature “Temperature [%.1f °C]” {exec="<[/usr/bin/python /home/openhabian/*?))]"}

Have you used openhab.openhab for the group.user ?

Hi Stefan, I like your ssh approach to remote raspberrys. I am stuck at the following: As far as I see the executeCommandLine launches as user openhab? Who did you manage to generate ssh keys for this user in order to login to the remote raspberry?

just use “sudo -u openhab” or “su openhab” before keygen/ssh-copy-id!

Just for completeness sake, may I add this link

1 Like

That did the trick! Many thanks.

I directly read out the oneWire ds18b20 but it should be similar for the dth22.

1 Like

Thanks, I think I am getting pretty close.
However in the Log-file it shows that I still have a permissions problem.

==> /var/log/openhab2/openhab.log <==

2019-01-04 12:17:00.077 [WARN ] [] - Execution failed (Exit value: -559038737. Caused by Cannot run program “/etc/openhab2/scripts/” (in directory “.”): error=13, Permission denied)

I checked the permissions of the scripts folder:
[12:09:15] openhabian@openHABianPi:~$ ls -ld /etc/openhab2/scripts/
drwxrwxr-x+ 2 openhab openhabian 4096 Jan 4 11:53 /etc/openhab2/scripts/

I tried to chmod the directory to 777 with sudo chmod 777 /etc/openhab2/scripts/ via SSH, but it doesn’t work.

The python scripts themselves work. I can execute them via SSH (even without su command) and get the measurement values.
Since I don’t need the su command when I run the files I don’t get why it doesn’t work when I run the exec via the rules.

Can someone help me along?

I needed to add pyhton before the path to the script.

Thefore my code looks like this:

val TEMP = executeCommandLine(“python /etc/openhab2/scripts/”, 5000)

This also solved my permission problem that I described lower in the thread.