TinkerForge Weather Station

Make projects using openHAB & openHABian.
rwblinn
Site Admin
Posts: 224
Joined: 07 Oct 2017, 12:16

TinkerForge Weather Station

Postby rwblinn » 21 Dec 2017, 19:26

openHAB Make Project - TinkerForge Weather Station v20171221.

Objectives
To build a Weather Station measuring in regular intervals the Temperature (C), Humidity (%RH), Pressure (mBar) and Luminance (Lux).
Display the measured values in the openHAB Basic UI, in a Node-RED flow and on a TinkerForge LCD 20x4.
This example is taken from the TinkerForge Weather Station project.
The Weather Station frame is build with MakerBeam components.

Its a learning project to understand basics of defining openHAB configurations, usage of the TinkerForge binding and defining a Node-RED flow with openHAB2 and Dashboard nodes.

openHAB Basic-UI and the Weather Station Frame
Image

Node-RED Dashboard
Image

Hardware
  • 1x Raspberry Pi 3 Model B v1.2
  • 1x TinkerForge Master Brick v200
  • 1x TinkerForge Barometer Bricklet v100
  • 1x TinkerForge Humidity Bricklet v110
  • 1x TinkerForge AmbientLight Bricklet v200
  • Nx MakerBeam material

Download
Configuration openHAB and Node-RED flows.

TinkerForge Brick Daemon
Install the brick daemon brickd.
openHABian does not contain the brickd and also when adding the TinkerForge binding via the openHAB Paper UI, brickd is not installed.

Code: Select all

cd /etc/openhab2/scripts
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
rm *.deb

TinkerForge Configurations
tinkerforge.config
The configuration file is located in

Code: Select all

/var/lib/openhab2/config/org/openhab/tinkerforge.config

There is no change required. Default content:

Code: Select all

hosts="127.0.0.1"
service.pid="org.openhab.tinkerforge"


tinkerforge.cfg
The Tinkerforge services configuration is located in

Code: Select all

/etc/openhab2/services

Per default the local host is defined.
Added the refresh interval of sensor values for devices which do not support callbacks will be polled with a configurable interval, the default is 60000 milliseconds.

Code: Select all

# IP addresses / Hostnames  of the hosts running the brickd (optional port separated by a colon, defaults to 4223)
# Define the local host
hosts=127.0.0.1
#Set the Refresh Interval
refresh=1000


openHAB Configurations
The configuration files defines are
  • tfweather.items - items being the temperature, pressure, humidity, ambient light and the LCD display.
  • tfweather.sitemap - simple layout showing the measured values and a switch to turn the LCD display back light on/off.
  • tfweather.rules - handle measured value changes and switching the LCD back light.

tfweather.items

Code: Select all

Number TF_Humidity            "Humidity [%.2f %%RH]" <humidity> {tinkerforge="uid=kcz"}
Number TF_Barometer_Pressure    "Pressure [%.2f mBar]" <pressure> {tinkerforge="uid=jXZ"}
Number TF_Barometer_Temperature   "Temperature [%.2f °C]" <temperature> {tinkerforge="uid=jXZ, subid=temperature"}
Number TF_AmbientLight         "Luminance [%.1f Lux]" <light> {tinkerforge="uid=yyc"}
String TF_LCD               "LCD" {tinkerforge="uid=rTS"}
Switch TF_LCDBacklight        "LCD Backlight" {tinkerforge="uid=rTS, subid=backlight"}
Switch TF_Button0             "Button0" {tinkerforge="uid=rTS, subid=button0"}

tfweather.sitemap

Code: Select all

sitemap tfweather label="TinkerForge Mini Weather Station"
{
    Frame {
        Text item=TF_Barometer_Temperature
        Text item=TF_Humidity
        Text item=TF_Barometer_Pressure
        Text item=TF_AmbientLight
   }
   Frame {
      Switch item=TF_LCDBacklight
   }
}

tfweather.rules

Code: Select all

// Sleep timer
var Integer initialSleepTime = 10

rule "Weatherstation LCD init from Backlight"
when
    Item TF_LCDBacklight changed or System started
then
    createTimer(now.plusSeconds(initialSleepTime)) [|
        sendCommand(TF_LCD, "TFNUM<00>Temperature:")
        sendCommand(TF_LCD, "TFNUM<019>C")
        sendCommand(TF_LCD, "TFNUM<10>Humidity   :")
        sendCommand(TF_LCD, "TFNUM<119>%")
        sendCommand(TF_LCD, "TFNUM<20>Pressure   :")
        sendCommand(TF_LCD, "TFNUM<217>hPa")
        sendCommand(TF_LCD, "TFNUM<30>Luminance  :")
        sendCommand(TF_LCD, "TFNUM<317>Lux")
      
        sendCommand(TF_LCD, String::format("TFNUM<013>%4s", TF_Barometer_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_Pressure.state.format("%.0f")))
        sendCommand(TF_LCD, String::format("TFNUM<313>%4s", TF_AmbientLight.state.format("%.0f")))
    ]
end

rule "Goodbye"
when
   System shuts down
then
   sendCommand(TF_LCDBacklight, OFF)
end

rule "Weather Station LCD Backlight"
when
    Item TF_Button0 changed
then
    if (TF_LCDBacklight.state == ON) {
        sendCommand(TF_LCDBacklight, OFF)
   }
   else {
        sendCommand(TF_LCDBacklight, ON)
   }
end

rule "Weatherstation LCD update temperature"
when
   Item TF_Barometer_Temperature received update
then
   sendCommand(TF_LCD, String::format("TFNUM<013>%4s", TF_Barometer_Temperature.state.format("%.1f")))
end

rule "Weatherstation LCD update humidity"
when
   Item TF_Humidity received update
then
   sendCommand(TF_LCD, String::format("TFNUM<113>%4s", TF_Humidity.state.format("%.1f")))
end

rule "Weatherstation LCD update airpressure"
when
   Item TF_Barometer_Pressure received update
then
   sendCommand(TF_LCD, String::format("TFNUM<213>%4s", TF_Barometer_Pressure.state.format("%.0f")))
end

rule "Weatherstation LCD update ambientLight"
when
   Item TF_AmbientLight received update
then
   sendCommand(TF_LCD, String::format("TFNUM<313>%4s", TF_AmbientLight.state.format("%.0f")))
end


References
Must reads:
TinkerForge Binding
TinkerForge Configuration Examples

Node-RED
The measured values are displayed as a Dashboard, with gages and a toggle switch to turn the LCD back light on/off.
Access the dashboard: http://openhabianpi:1880/ui.
To create the Node-RED flow, access http://openhabianpi:1880.

This is a rather simple flow and opts for enhancements, like ui_charts, alarm notification if a threshold is reached.

Node-RED Dashboard
This module provides a set of nodes in Node-RED to create a user interface. Installation steps:

Code: Select all

cd /usr/lib/node_modules
sudo npm i node-red-dashboard

A Node-RED Restart is required (from a terminal run node-red-stop followed by node-red-start).

Node-RED openHAB2 Module
The openHAB2 module node-red-contrib-openhab2 provides Nodes facilitating automation of openHAB items with Node-RED.
For this example, the openHAB items used are (defined in tfweather.items): TF_Humidity, TF_Barometer_Pressure, TF_Barometer_Temperature, TF_LCDBacklight.

Node-RED openHAB2 Nodes
openHAB2 Controller Nodes
Configuration node for communication with an openHAB controller. Configuration:

Code: Select all

Name : OH2 Controller
Protocol : http
Host : 127.0.0.1


Nodes openhab2-in
These nodes listen to state changes of the selected openHAB items (via the openHAB2 controller "OH2 Controller"): TF_Humidity, TF_Barometer_Pressure, TF_Barometer_Temperature
The message injected via Channel 1 (Channel 2 is not used) are send to the ui_gauges. The ui_gauges use the msg.payload property, which holds the measured value.

Node openhab2-out
This nodes sends commands to the selected openHAB Item, i.e. TF_LCDBacklight. The TF_LCDBacklight accepts payload of ON or OFF (see also tfweather.rules).
The payload is set by a ui_switch as string "ON" or "OFF".

Node-RED Flow (extract)

Code: Select all

    {
        "type": "openhab2-in",
        "itemname": "TF_Barometer_Temperature",
    },
    {
        "type": "ui_gauge",
        "title": "Temperature",
        "label": "C",
        "format": "{{value}}",
        "min": "14",
        "max": "24",
    },
    {
        "type": "openhab2-in",
        "itemname": "TF_Barometer_Pressure",
    },
    {
        "type": "ui_gauge",
        "title": "Pressure",
        "label": "mBar",
        "format": "{{value | number:2 }}",
        "min": "1000",
        "max": "1040",
    },
    {
        "type": "openhab2-in",
        "itemname": "TF_Humidity",
    },
    {
        "type": "ui_gauge",
        "title": "Humidity",
        "label": "%RH",
        "format": "{{value}}",
        "min": "0",
        "max": "100",
    },
    {
        "type": "openhab2-out",
        "itemname": "TF_LCDBacklight",
        "topic": "ItemCommand",
    },
    {
        "type": "ui_switch",
        "label": "LCD Backlight",
        "passthru": true,
        "decouple": "false",
        "onvalue": "ON",
        "onvalueType": "str",
        "offvalue": "OFF",
        "offvalueType": "str",
    },
    {
        "type": "openhab2-controller",
        "name": "OH2 Controller",
        "protocol": "http",
        "host": "localhost",
        "port": "8080",
        "path": "",
        "username": "",
        "password": ""
    },

Return to “Make”



Who is online