[SOLVED] DHT22 not reading

I’m having a trouble reading temperature from DHT22 sensor(script in running fine in command line), what i’'ve done so far:

Items are named home.items

Number Temp “Temperature [%.1f °C]” {exec="<[/usr/bin/python /etc/openhab2/scripts/DHT22.py:10000:REGEX((.*?))]"}

script is named DHT22.py(script is working 100%)

import Adafruit_DHT

sensor = Adafruit_DHT.DHT11
pin = 4
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print(‘Failed to get reading. Try again!’)



Text item=Temp

what is showing up in the basic ui

thank you in advance

Please use code fences.


Does the script work when run as the openhab user?

sudo -u openhab python DHT22.py

See How to solve Exec binding problems for other trouble shooting ideas.

okay i’ve tried

sudo -u openhab python DHT22.py

and it does not work.

Aren’t you in the /etc/openhab2 directory trying to run a script in the /etc/openhab2/scripts directory?

1 Like

thank you, I haven’t noticed that mistake now the command works

sudo -u openhab python DHT22.py

1 Like

Do I need any specific bindings?
And here I found some errors for Temp in log.

The errors in the log indicate you have a line in your sitemap to display the Item Temp but there is no such Item defined.

Check for typos in your .items file. Try a restart of OH just to be sure you are starting from a cleanish state.

Do you see the .items file Temp is defined in loading in openhab.log? Any errors during the loading of that file?

Rebooted the Pi and there were no temp errors in sight.

In items I have this:

Number Temp “Temperature [%.1f °C]” {exec="<[/usr/bin/python /etc/openhab2/scripts/DHT22.py:10000:REGEX((.*?))]"}

and in sitemap

Text item=Temp icon=“temperature”

Could you confirm that the syntax is correct?

No but openHAB itself and VSCode with the openHAB extension can. If you don’t see any errors in openhab.log when it loads the file, there are no syntax errors.