### Sample IO-16 Port State

TinkerForge RED Brick example of switching a LED ON / OFF which is connected to Port A0 of the IO-16 Bricklet.
Brick Setup:
RED Brick > Master Brick > IO-16 Bricklet > Port A0 > LED 3.3v.
Test LED via Brick Viewer
Befor building the openHAB files via the Brick Viewer > Settings > openHAB, test if the setup is working via the Brick Viewer > IO-16 Bricklet.
Steps:
Select Tab IO-16 Bricklet.
Setting A0 Port Direction to Output, the LED can be turned ON / OFF via changing the value Low to High vv.
openHAB Files Folder
The openHAB files are stored in /etc/openhab/ with owner openhab.
The configuration files are stored in /etc/openhab/configurations.
The Log file in /var/log/openhab with openhab.log etc.
Overview
In the openHAB configuration file "openhab.cfg", the IO-16 bricklet and the ports used are configured.
In the items file, the IO-16 port is defined using the data defined in the configuration file.
In the sitemaps file, the Switch is defined.
openHAB Configuration File openhab.cfg
tinkerforge:hosts=127.0.0.1
tinkerforge:io16.uid=gkM
tinkerforge:io16.type=bricklet_io16
tinkerforge:io16.debouncePeriod=100
tinkerforge:io16outa0.uid=gkM
tinkerforge:io16outa0.subid=outa0
tinkerforge:io16outa0.type=io_actuator
tinkerforge:io16outa0.defaultState=true
Note: use the Brick Viewer > Tab IO-16 Bricklet to obtain the UID of the IO-16 Bricklet.
openHAB Items File io16test.items
Switch outa0 "LED A0" { tinkerforge="uid=gkM, subid=outa0" }
rules
//When switching the LED, write an entry in the openhab log file (/var/log/openhab).
import org.openhab.core.library.types.*
import java.util.Date
import java.text.SimpleDateFormat
rule "LED Switch"
when
Item outa0 changed
then
var SimpleDateFormat df = new SimpleDateFormat( "YYY-MM-dd HH:mm:ss" )
var String Timestamp = df.format ( new Date() )
if (outa0.state == ON)
logInfo( "FILE", Timestamp + " - State " + "ON")
else
logInfo( "FILE", Timestamp + " - State " + "OFF" )
end
openHAB Sitemap File io16test.sitemap
sitemap io16test label="IO-16 Test"
{
Frame
{
Switch item=outa0
}
}
Note: Ensure the sitemap name in the sitemap file, is the same as the sitemapfile itself, e.g.
sitemap io16test and io16test.sitemap.
Open the sitemap in the Webbrowser
Open http://red-brick-ipaddress:8080/openhab.app?sitemap=io16test
Example:
http://192.168.0.30:8080/openhab.app?sitemap=io16test

Changed: , Category: TinkerForge openHAB, File: T6C267M1993.htm, ID: 1993