How to show DHT22 stats on HAB panel

It works now :smiley:
I forgot to change the “Number” to “String”.

Thank you so much for your help. So This is my solution now:

items:

String Temp "Temperature [%.2f C]" <temperature> {channel="exec:command:temp:output"}
String Hum "Humidity [%d %%]" <humidity> {channel="exec:command:hum:output"}

scripts:
temp.py


#!/usr/bin/env python2.7

import sys

import Adafruit_DHT



sensor = Adafruit_DHT.DHT22

pin = 18



humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)



if humidity is not None and temperature is not None:

    print('{0:0.2f}'.format(temperature))

else:

    print('Failed to get reading. Try again!')

    sys.exit(1)

hum.py

#!/usr/bin/env python2.7
import sys

import Adafruit_DHT



sensor = Adafruit_DHT.DHT22

pin = 18

humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

if humidity is not None and temperature is not None:

     print('{0:0.2f}'.format(humidity))

else:

     print('Failed to get reading. Try again!')

     sys.exit(1)

Things:

Thing exec:command:hum [command="/usr/bin/python2  /opt/openhab2/conf/scripts/hum.py", interval=15, autorun=true]

Thing exec:command:temp [command="/usr/bin/python2  /opt/openhab2/conf/scripts/temp.py", interval=15, autorun=true]

1 Like