### Item Type Selection

TinkerForge RED Brick example of switching a LED On / Off by using Type Selection.
The example relates to B4H HowTo TinkerForge RED Brick > openHAB Sample IO-16 LED Switch.
io16test.items
//Selection item to be defined as number because switch case command is by number 0 and 1 as defined in the mappings in the sitemap file.
Number outa0s "LED A0"
io16test.sitemap
sitemap io16test label="IO-16 Test"
{
Frame
{
Selection item=outa0s label="LED A0 Switch" mappings=[0="ON",1="OFF"]
}
}
io16test.rules
import org.openhab.core.library.types.*
import java.util.Date
import java.text.SimpleDateFormat
rule "LED A0 Switch Selection"
when
Item outa0s received command
then
logInfo( "FILE", "Command received: " + receivedCommand)
var SimpleDateFormat df = new SimpleDateFormat( "YYY-MM-dd HH:mm:ss" )
var String Timestamp = df.format ( new Date() )
switch(receivedCommand) {
case 0 : {
sendCommand(outa0, ON)
logInfo( "FILE", Timestamp + " - State " + "ON")
labelinfo.postUpdate("A0 ON " + Timestamp)
}
case 1 : {
sendCommand(outa0, OFF)
logInfo( "FILE", Timestamp + " - State " + "OFF")
labelinfo.postUpdate("A0 OFF " + Timestamp)
}
}
end

Changed: , Category: TinkerForge openHAB, File: T6C267M1988.htm, ID: 1988