Today connected DHT22 temp & humidity sensor and get readings via ssh on openhabian.
But I can not get readings in sitemap. Exec binding installed, on beginning I had and issue with whitelist but solved by adding command to the list. Command itself checked via ssh.
Added also last execution to check but also nothing appear DateTime Dht111 "Last time executed [%1$tH:%1$tM]" {channel="exec:command:dht:lastexecution"}
I’m beginner so MQTT a little bit complicated for me - I would like to access that readings with simplest method. Spent all day reading posts but I can not figure out what’s wrong.
does the openhab user ( the user the openhab java process is running under ) have read access to /home/fox/mydht2.py ?
your python script seems to run in an endless loop; I would suggest to make it returning a single value
in first step use a script that emulates your script and returns a single ( random ) value; once that works continue using your script that reads from GPIO
Switch Dht22 {channel="exec:command:dht:run"}
DateTime Dht111 "Last time executed [%1$tH:%1$tM]" {channel="exec:command:dht:lastexecution"}
thing
```Thing exec:command:dht [command="/usr/bin/python3 /home/fox/mydht2.py", interval=15, transform="REGEX((.*?))", autorun=true]
sitemap
``` Text item=Dht11 label="Przyklad [%.0f]"
Text item=Dht111
Switch item=Dht22
So after script change something changed in sitemap but still no expected results??? Which script can be more simple?
I would suggest to modify the python script and update the item via REST API with your required frequency. I”m using the same method with a Wemos and a DS18B20. Another method is updating via mqtt.
Text item=Dht11 label="Temperature [%s °C]"
Text item=Dht33 label="Humidity [%s %%]"
mydht2.py:
import Adafruit_DHT
# Set sensor type : Options are DHT11,DHT22 or AM2302
sensor=Adafruit_DHT.DHT22
# Set GPIO sensor is connected to
gpio=18
# Use read_retry method. This will retry up to 15 times to
# get a sensor reading (waiting 2 seconds between each retry).
humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio)
# Reading the DHT11 is very sensitive to timings and occasionally
# the Pi might fail to get a valid reading. So check if readings are valid.
if humidity is not None and temperature is not None:
print('{0:0.1f}'.format(temperature, humidity))
else:
print('Failed to get reading. Try again!')
mydht3.py:
import Adafruit_DHT
# Set sensor type : Options are DHT11,DHT22 or AM2302
sensor=Adafruit_DHT.DHT22
# Set GPIO sensor is connected to
gpio=18
# Use read_retry method. This will retry up to 15 times to
# get a sensor reading (waiting 2 seconds between each retry).
# humidity,
humidity, temperature = Adafruit_DHT.read_retry(sensor, gpio)
# Reading the DHT11 is very sensitive to timings and occasionally
# the Pi might fail to get a valid reading. So check if readings are valid.
if humidity is not None and temperature is not None:
print('{1:0.1f}'.format(temperature, humidity))
else:
print('Failed to get reading. Try again!')`