I am attempting to get temperature readings from 1wire DS18b20 sensors connected to GPIO pin on my raspberry Pi running OpenHABianPi.
I have downloaded and installed the latest stable OpenHABianPi form here: openHABian hassle-free openHAB Setup
I did a lot of google research to figure out this problem, and ultimately followed this guide on using script to get temperature from 1wire device connected to GPIO:
My “Ger-glish” isn’t as gut as it used to be, but I think I got the basic concept.
So, in order to make my setup work in openHABianPi setup, here is what I did:
- Created the following script in “/etc/openhab2/scripts/”:
“onewiretemp.sh”
#!/bin/bash
wert=`cat /sys/bus/w1/devices/$1/w1_slave | tail -n1 | cut -d '=' -f2`
wert2=`echo "scale=3; $wert/1000 * 9.0 / 5.0 + 32.0" | bc`
echo $wert2
2.Created 2 Items to run script (one for each of my 2 sensors):
“OneWireTemp1.items”
Number onewiretemp1ExitValue "Temp1 is [%.1f °F]" <temperature> {channel="exec:command:onewiretemp1:exit"}
AND:
“OneWireTemp2.items”
Number onewiretemp2ExitValue "Temp2 is [%.1f °F]" <temperature> {channel="exec:command:onewiretemp2:exit"}
3.Created 2 Things to run the script with the corresponding UID
"OneWireTemp.things"
exec:command:onewiretemp1 [command="bash /etc/openhab2/scripts/onewiretemp.sh@@28-blahblah"]
“OneWireTemp2.things”
exec:command:onewiretemp2 [command="bash /etc/openhab2/scripts/onewiretemp.sh@@28-blahblah2"]
OpenHab automagically adds the “Things” to the default sitemap, however, the values do not correspond with the actual values of the sensors.
No matter what the sensors are reporting at the terminal, the value of the thing in openHab is always “127”. I have messed around with the “Transform” functions (i.e. REGEX) , to no avail.
I’ve also created custom sitemaps and included:
item=onewiretemp1ExitValue
item=onewiretemp2ExitValue
Neither the default nor my custom sitemaps report the correct values for the temp sensors.
I have also attempted to create new “Things” from the exec binding in Paper and HABmin UI (instead of creating a things file), and then link to my custom items.
So far, I have not been able to get the temperature to read out correctly through OpenHab.
I also tested that I could run the original script as the openhab user (through ssh to raspberry pi box) and get a useable temperature. This was successful:
pi@openHABianPi:/etc/openhab2/scripts$ sudo -u openhab ./onewiretemp.sh 28-blahblah
70.250
Result is perfect, script runs under openhab user, DS18b20 value is 70.250 (Fahrenheit). Great! Now if only I could see this through OpenHab…
There is a nearly identical use case post:
This person relied on the same post I reference at the beginning of my post here, however does not explain how. And to address the issue of OWServer: It will not read from GPIO connected 1wire sensors, I have already been down this road.
So, what am I doing wrong in OpenHab? I feel like I am not implementing things and items correctly… Or maybe I need to use Output instead of ExitValue…?
Any help is greatly appreciated.