Building IoT systems with openHAB
Matt Porter
Konsulko [email protected]
Overview
+ Timeline + Frameworks and Protocols + openHAB architecture + openHAB features + openHAB configuration + openHAB examples + Demo
Timeline
+ ARPANET online in 1969 with “things” talking
Network Control Program (NCP)
+ Internet born in 1983: ARPANET “things” start talking TCP/IP
+ Many Internet connected appliances created from
1990 to present
+ Kevin Ashton (Auto-ID) coins “IoT” in 1999 + Media goes into a frenzy about IoT that just won’t quit.
+ openHAB started in 2010
Frameworks
+ AllJoyn - framework for distributed applications
+ https://allseenalliance.org/developers/learn/architecture
+ IOTivity - framework for Machine to Machine(M2M) communication
+ Kura - OSGi-based framework for M2M applications
+ Mihini - Lua-based M2M framework
+ openHAB - Home Automation and IoT gateway framework
+ ...
Protocols
+ CoAP (Constrained Application Protocol)
+ request/response, low overhead, translates to HTTP
+ MQTT
+ pub/sub, low overhead
+ RESTful HTTP
+ request/response, one way from devices to service
+ XMPP (Extensible Messaging and Presence
Protocol)
+ pub/sub, built in authentication
+ ...
MQTT
+ OASIS standard: MQTT v3.1.1 + Publish/Subscribe and hub/spoke model
+ MQTT brokers provides the communication hub
+ Mosquitto 1.3.4 broker supports MQTT v3.1.1 + Fixed header required, variable header and payload optional
+ Fixed header just 2 bytes
openHAB basics
+ FOSS automation software
+ Eclipse Public License 1.0
+ Written mostly in Java + Central automation hub + Hardware/protocol agnostic
+ Many bindings http://www.openhab.org/features-tech.html
+ Component-based architecture
+ Each component is an OSGi bundle
openHAB architecture
+ Event bus
+ Asynchronous communication bus
+ Repository
+ Persistent storage
+ Items
+ Objects that can be read or written + Have a type and state
+ Bindings
+ Translate event bus events to/from external system
+ Actions
+ Programmatic methods available for use by scripts/rules
openHAB features
+ Plugin framework + Rules engine + Logging mechanism + UI abstraction
+ Sitemap - Tree structure of UI widgets + Item UI Providers - Dynamic UI configuration
+ UI implementations
+ Web + Android + iOS
+ Designer tool - graphic configuration of runtime
openHAB add-ons
+ Actions
+ HTTP - access URL on event + Mail - ancient notification technology + Pushover/Prowl - notifications + Twitter - Tweet that your toilet flushed
+ Bindings
+ Bluetooth - device proximity events
+ GPIO - Linux sysfs-based GPIO events + KNX - home automation events + MQTT - raw protocol support + OneWire - various sensor events + Serial - RS-232 will never die + ZWave - home automation events
Running openHAB
+ Runs well on any x86 or ARM board with 512MB+
RAM
+ OpenJDK or Oracle JREs are supported
+ Some bindings may not work on OpenJDK on ARM
+ Packaged on some distros
+ Debian Cloudbees repository has the core and all bindings packaged
+ openhab-runtime + openhab-addon-*
+ $ cat /etc/apt/sources.list.d/openhab.list deb http://repository-openhab.forge.cloudbees.com/release/1.6.1/apt-repo/ /
openHAB configuration
$(openhab)/configurations/ openhab.cfg items/*.items persistence/*.persist rules/*.rules scripts/*.script sitemaps/*.sitemap transform/*.map
openhab.cfg
######################## Mail Action configuration #################################### ## The SMTP server hostname, e.g. "smtp.gmail.com" mail:hostname=smtp.gmail.com
Global settings are in this config file
# the SMTP port to use (optional, defaults to 25 (resp. 587 for TLS)) mail:port=587
# the username and password if the SMTP server requires authentication mail:username=torvalds mail:password=linux1991
# The email address to use for sending mails mail:from=Not Really Linus <[email protected]>
# set to "true", if TLS should be used for the connection # (optional, defaults to false) mail:tls=true
home.items
Contact FrontDoor "Front Door [MAP(en.map):%s]" {mqtt="<[openhab: /house/frontdoor:state:default]"}
Contact GarageDoor "Garage Door [MAP(en.map):%s]" {zwave="3: command=sensor_binary"}
openHAB rules
+ Java-like
+ Imports + Variable declarations + Rules
var VarType var1 rule “rule name” when
<trigger1> or <trigger2> then
<execute_actions> end
openHAB triggers
+ Item/Event-based
Item <item> received command [<command>] Item <item> changed [from <state>] [to <state>]
+ Time-based
Time is midnight
+ System-based
System started
openHAB actions
+ Actions used in rules engine to accomplish a task + Core actions
sendCommand() postUpdate() logInfo()
+ Binding actions
sendMail() pushNotification() sendTweet() sendXbmcNotification()
home.rules
If the state of the door item changes, send a notification indicating the state of the door.
rule "Notify Front Door" when
Item FrontDoor changed then
end pushover("Front door is " + FrontDoor.state.toString) rule "Notify Garage Door" when
Item GarageDoor changed then
end pushover("Garage door is " + GarageDoor.state.toString)