### Sample TinkerForge Weather Data

TinkerForge (TF) Example Weather Data. Project name used is WeatherCube.
Purpose to display the actual Temperature, Humidity and Airpressure on the TF LCD 20x 4 bricklet, but also
in a Browser.
References
https://github.com/openhab/openhab/wiki/Tinkerforge-Binding
http://www.tinkerforge.com/en/doc/Embedded/Raspberry_Pi.html
Setup
Hardware
A TF Master Brick is connected via USB with the Raspberry Pi.
The TF Master Brick has 4 TF Bricklets connected:
Humidity with uid=kcz
Temperature with uid=nfu
Barometer with uid=jXZ
LCD 20x4 Display with uid=rTS
Software
The TF Brick Deamon and Brick Viewer are installed.
Brick Deamon
$sudo apt-get install libusb-1.0-0 libudev0 pm-utils
$wget http://download.tinkerforge.com/tools/brickd/linux/brickd_linux_latest_armhf.deb
$sudo dpkg -i brickd_linux_latest_armhf.deb
Brick Viewer
$sudo apt-get install python python-qt4 python-qt4-gl python-opengl python-serial
$wget http://download.tinkerforge.com/tools/brickv/linux/brickv_linux_latest.deb
$sudo dpkg -i brickv_linux_latest.deb
openHAB TinkerForge Bindings
org.openhab.action.tinkerforge-1.8.1.jar
org.openhab.binding.tinkerforge-1.8.1.jar
Define the openHAB Configuration
Folder: /opt/openhab/configurations
File: openhab.cfg
Amended with TF host IP addresses:
#TinkerForge
#https://github.com/openhab/openhab/wiki/Tinkerforge-Binding
tinkerforge:hosts=127.0.0.1 192.168.0.58 localhost
Define the Items
Folder: /opt/openhab/configurations/items
File: weathercube.items
//openHAB Project WeatherCube by Robert W.B. Linn
//https://github.com/openhab/openhab/wiki/Explanation-of-items
//Changed: 20160315
//Define Text Item which is updated when a value has changed
String labelinfo "Label Info" { }
//Special char % with double %
Number TF_Humidity "Humidity [%.1f %%RH]" { tinkerforge="uid=kcz" }
//Special char grad as \u00B0 - see www.utf8-chartable.de
Number TF_Temperature "Temperature [%.1f \u00B0C]" { tinkerforge="uid=nfu" }
//mbar with no decimal
Number TF_Barometer "Barometer [%.0f mBar]" { tinkerforge="uid=jXZ" }
//LCD 20x4 Display
String TF_LCD "LCD" { tinkerforge="uid=rTS"}
Switch TF_LCDBacklight "LCDBacklight" { tinkerforge="uid=rTS, subid=backlight"}
Switch TF_Button0 "Button0" { tinkerforge="uid=rTS, subid=button0"}
Switch TF_Button1 "Button1" { tinkerforge="uid=rTS, subid=button1"}
Switch TF_Button2 "Button2" { tinkerforge="uid=rTS, subid=button2"}
Switch TF_Button3 "Button3" { tinkerforge="uid=rTS, subid=button3"}
Define the Sitemap
Folder: /opt/openhab/configurations/sitemaps
File: weathercube.sitemap
//openHAB Project WeatherCube by Robert W.B. Linn
//https://github.com/openhab/openhab/wiki/Explanation-of-sitemaps
//Changed: 20160315
sitemap tf_weather_station label="Weather Cube"
{
Frame label="Weather Cube"
{
Text item=TF_Temperature icon="temperature" valuecolor=[>25="red",>15="green",>5="orange",<5="blue"]
Text item=TF_Humidity
Text item=TF_Barometer
Text item=labelinfo label="Last Change [%s]" icon="info"
Switch item=TF_LCDBacklight
}
}
Define the Rules
Folder: /opt/openhab/configurations/rules
File: weathercube.rules
//openHAB Project WeatherCube by Robert W.B. Linn
//https://github.com/openhab/openhab/wiki/Rules
//Changed: 20160315
import org.openhab.core.library.types.*
import java.util.Date
import java.text.SimpleDateFormat
rule "WeatherCube Value Changed"
when
Item TF_Temperature received update or
Item TF_Humidity received update or
Item TF_Barometer received update
then
//Set the time format. This could also be like YYYY:MM:DD HH:mm:ss
var SimpleDateFormat df = new SimpleDateFormat( "HH:mm" )
var String Timestamp = df.format ( new Date() )
//Update the sitemap item - the label has a text "Last Change"
labelinfo.postUpdate(Timestamp)
//Update LCD
sendCommand(TF_LCD, "TFNUM<00>Temperature: C")
sendCommand(TF_LCD, "TFNUM<10>Humidity : %")
sendCommand(TF_LCD, "TFNUM<20>Pressure : hPa")
sendCommand(TF_LCD, "TFNUM<30>Changed : ")
sendCommand(TF_LCD, String::format("TFNUM<013>%4s", TF_Temperature.state.format("%.1f")))
sendCommand(TF_LCD, String::format("TFNUM<113>%4s", TF_Humidity.state.format("%.1f")))
sendCommand(TF_LCD, String::format("TFNUM<213>%4s", TF_Barometer.state.format("%.0f")))
sendCommand(TF_LCD, String::format("TFNUM<313>%s", Timestamp))
end
rule Goodbye
when
System shuts down
then
sendCommand(TF_LCDBacklight, OFF)
end
rule "WeatherCube LCD Backlight"
when
Item TF_Button0 received update
then
if (TF_Button0.state == ON)
sendCommand(TF_LCDBacklight, ON)
else
sendCommand(TF_LCDBacklight, OFF)
end
Access the Sitemap via Browser
URL is (using the Raspberry Pi IP Address):
http://192.168.0.58:8080/openhab.app?sitemap=weathercube
openHAB Logfile entry examples:
2016-03-15 11:09:52.774 [INFO ] [runtime.busevents ] - TF_Barometer state updated to 1029.003
2016-03-15 11:09:52.776 [INFO ] [runtime.busevents ] - TF_Temperature state updated to 14.12
2016-03-15 11:09:52.780 [INFO ] [runtime.busevents ] - labelinfo state updated to 2016-03-15 11:09:52
2016-03-15 11:05:11.667 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'weathercube.rules'
2016-03-15 10:58:20.744 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'weathercube.items'

Changed: 2018-06-07 09:32, Category: WebApps openHAB, File: T6C228M1684.htm, ID: 1684