I am trying to add a temperature sensor to openhab but i cant get data from the script when executing it in openhab.
The last image is form the terminal when openhab is running and not getting any data.
Thanks for any help
I am trying to add a temperature sensor to openhab but i cant get data from the script when executing it in openhab.
The last image is form the terminal when openhab is running and not getting any data.
Thanks for any help
Iâm pretty sure you have to call python for using python scripts. You could set the item Temp
to String to see, if there is any output from the script, even errors.
Please try to post text, itâs way easier to read (especially if at phoneâŠ)
I think you didnât get the point your Item should be like
Number Temp "Temperature [%.1f °C]" <temperature> (Kjeller) {exec="<[/usr/bin/python /opt/openhab/configurations/scripts/TempTest.py:10000:REGEX((.*?))]"}
so call the python interpreter and consign the script (the complete filename, please)
Maybe itâs necessary to replace the space with @@, so it would look like [..]in/python@@/opt/openhab/conf[..]
Thank you so much for your help. I am now getting the data into openhab I am new to openhab/programming in general and there is much to learn
Could you please write down the solution? just in case, another user has similar problemsâŠ
I did just what you wrote above. adding the [..] /usr/bin/python@@/opt/openhab/conf[..]
and it worked.
Thanks!
Hi sir, How can I write a demo.scipts instead of TempTest.py. I want to get data of DHT22 that connected with GPIO on Raspberry running Openhab
An other approach is to run the default python script and add to it some lines of Python to publish temperature and pressure to an mqtt server.
Then install mqtt binding at OH and add the items temperature and pressure as numbers.
Step by step
install adafruit dht library
https://github.com/adafruit/Adafruit_Python_DHT
install mtqq server
https://github.com/eclipse/paho.mqtt.python
copy adafruit example AdafruitDHT.py to /home/pi
https://github.com/adafruit/Adafruit_Python_DHT/tree/master/examples
and add these lines at the bottom:
import paho.mqtt.client as mqtt
mqttc = mqtt.Client(âmosquitto_pubâ)
mqttc.connect(âlocalhostâ, 1883)
mqttc.publish(âhome/temperatureâ, â{0:0.1f}â.format(temperature, humidity))
mqttc.publish(âhome/humidityâ, â{1:0.1f}â.format(temperature, humidity))
mqttc.loop(2)
if humidity is not None and temperature is not None:
print âTemperature={0:0.1f}* Humidity={1:0.1f}%â.format(temperature, humidity)
else:
print 'Failed to get reading. Try again!'
sys.exit(1)
mqtt:mymosquitto.url=tcp://localhost:1883
mqtt:mymosquitto.retain=true
5,10,15,20,25,30,35,40,45,50,55 * * * * sudo /home/pi/AdafruitDHT.py 22 4
Number HomeTemperature âTemperature [%.2f °C]â (sensors) { mqtt="<[mymosquitto:home/temperature:state:default]" }
and
Number HomeHumidity âHumidity [%.2f %]â (sensors) { mqtt="<[mymosquitto:home/humidity:state:default]" }
Enjoy