OpenHAB
Contents |
openHAB Downloads
http://www.openhab.org/downloads.html
openHAB MiOS binding
https://github.com/openhab/openhab/tree/master/bundles/binding/org.openhab.binding.mios
Tools
Creating openHAB configuration files (items, sitemap, rrd4j persistence)
Adjust unit_name and output_directory.
items
https://github.com/openhab/openhab/wiki/Explanation-of-items
Place *.items in: /openHAB/runtime/configurations/items
sitemap
https://github.com/openhab/openhab/wiki/Explanation-of-Sitemaps
Place *.sitemap in: /openHAB/runtime/configurations/sitemaps
rrd4j persistence
https://github.com/openhab/openhab/wiki/Persistence
Add rrd4j.persist_add to the Items section in /openHAB/runtime/configurations/persistence/rrd4j.persist and make sure that the strategies used are defined in the Strategies section.
Luup code for MiOS devices
-- by Ap15e local unit_name = 'house' local output_directory = '/dataMine' local device_types = { [ 'urn:schemas-upnp-org:device:DimmableLight:1' ] = { 'Dimmer' , ' [%d]%' , '<slider>' , '/service/Dimming1/LoadLevelStatus,command:MAP(miosDimmerCommand.map)' }, [ 'urn:schemas-upnp-org:device:BinaryLight:1' ] = { 'Switch' , '' , '' , '/service/SwitchPower1/Status,command:ON=SwitchPower1/SetTarget(newTargetValue=1)|OFF=SwitchPower1/SetTarget(newTargetValue=0),in:MAP(miosSwitchIn.map)' }, [ 'urn:schemas-micasaverde-com:device:TemperatureSensor:1' ] = { 'Number' , ' [%.1f °C]', '<temperature>' , '/service/TemperatureSensor1/CurrentTemperature' }, [ 'urn:schemas-micasaverde-com:device:HumiditySensor:1' ] = { 'Number' , ' [%d]%' , '' , '/service/HumiditySensor1/CurrentLevel' }, [ 'urn:schemas-micasaverde-com:device:MotionSensor:1' ] = { 'Contact', ' [%s]' , '<contact>' , '/service/SecuritySensor1/Tripped,in:MAP(miosContactIn.map)' }, [ 'urn:schemas-micasaverde-com:device:LightSensor:1' ] = { 'Number' , ' [%.2f]%' , '' , '/service/urn:micasaverde-com:serviceId:LightSensor1/CurrentLevel' }, [ 'urn:schemas-micasaverde-com:device:DoorSensor:1' ] = { 'Contact', ' [%s]' , '<contact>' , '/service/SecuritySensor1/Tripped,in:MAP(miosContactIn.map)' }, [ 'urn:schemas-upnp-org:device:Heater:1' ] = { 'Number' , ' [%.1f °C]', '<temperature>' , '/service/urn:upnp-org:serviceId:TemperatureSetpoint1_Heat/CurrentSetpoint' }, [ 'urn:schemas-micasaverde-com:device:UvSensor:1' ] = { 'Number' , ' [%d]' , '' , '/service/urn:upnp-org:serviceId:UvSensor1/CurrentLevel' }, [ 'urn:schemas-micasaverde-com:device:RainSensor:1' ] = { 'Number' , ' [%.1f]' , '' , '/service/urn:upnp-org:serviceId:RainSensor1/CurrentTRain' }, [ 'urn:schemas-micasaverde-com:device:ScaleSensor:1' ] = { 'Number' , ' [%.1f]' , '' , '/service/urn:micasaverde-com:serviceId:ScaleSensor1/Weight' }, [ 'urn:schemas-micasaverde-com:device:BarometerSensor:1' ] = { 'Number' , ' [%.2f]hPa', '' , '/service/urn:upnp-org:serviceId:BarometerSensor1/CurrentPressure' }, [ 'urn:schemas-micasaverde-com:device:WindSensor:1' ] = { 'Number' , ' [%.1f]' , '<wind>' , '/service/urn:upnp-org:serviceId:WindSensor1/AvgSpeed' }, [ 'urn:schemas-micasaverde-com:device:SmokeSensor:1' ] = { 'Contact', ' [%s]' , '<contact>' , '/service/urn:upnp-org:serviceId:SmokeSensor1/Tripped,in:MAP(miosContactIn.map)' }, [ 'urn:demo-micasaverde-com:device:weather:1' ] = { 'String' , ' [%s]' , '' , '/service/urn:micasaverde-com:serviceId:Weather1/Condition' }, [ 'urn:schemas-ap15e-com:device:DAD' ] = { 'String' , ' [%s]' , '<sun>' , '/service/urn:upnp-ap15e-com:serviceId:DAD1/Sunrise_HHMMSS' }, [ 'urn:schemas-micasaverde-com:device:WindowCovering:1' ] = { 'Switch' , '' , '<rollershutter>', '/service/SwitchPower1/Status,command:ON=SwitchPower1/SetTarget(newTargetValue=1)|OFF=SwitchPower1/SetTarget(newTargetValue=0),in:MAP(miosSwitchIn.map)' } } function normalize_name( s ) s = string.gsub( s or '', '[%s-/%.:]', '_' ) return '_' .. s end function write_items() outf = io.open( output_directory .. '/' .. unit_name .. '.items', 'w\n' ) outf:write( 'Group Rooms (All)\n' ) for k, v in pairs( device_types ) do t = string.match( k or '', '%:(%a*)%:1' ) outf:write( 'Group _' .. tostring( t ) .. 's "' .. tostring( t ) .. 's" (Rooms)\n' ) outf:write( 'Number _' .. tostring( t ) .. 'sChartPeriod\n' ) end for k, v in pairs( luup.rooms ) do outf:write( 'Group ' .. normalize_name( tostring( v ) ) .. ' "' .. tostring( v ) .. '" <' .. normalize_name( tostring( v ) ) .. '> (Rooms)\n' ) end outf:write( 'Group _no_room "no room" <_no_room> (Rooms)\n' ) for k, v in pairs(luup.devices) do dt = device_types[ v.device_type ] if dt ~= nil then t = string.match( v.device_type or '', '%:(%a*)%:1' ) outf:write( tostring( dt[ 1 ] ) .. ' ' .. normalize_name( tostring( v.description ) ) .. ' "' .. tostring( v.description ) .. tostring( dt[ 2 ] ) .. '" ' .. tostring( dt[ 3 ] ) .. ' (' .. normalize_name( tostring( luup.rooms[ v.room_num ] ) ) .. ',_' .. tostring( t ) .. 's) {mios="unit:' .. tostring( unit_name ) .. ',device:' .. k .. tostring( dt[ 4 ] ) .. '"}\n' ) end end outf:close() end -- function write_items() function write_sitemap() outf = io.open( output_directory .. '/' .. unit_name .. '.sitemap', 'w\n' ) outf:write( 'sitemap ' .. unit_name .. ' label="Main Menu"\n' ) outf:write( '{\n' ) outf:write( ' Frame {\n' ) outf:write( ' Group item=Rooms label="Rooms"\n' ) outf:write( ' }\n' ) for k, v in pairs( device_types ) do t = string.match( k or '', '%:(%a*)%:1' ) p = '_' .. tostring( t ) .. 'sChartPeriod' i = '_' .. tostring( t ) .. 's' outf:write( ' Frame {\n' ) outf:write( ' Switch item=' .. p .. ' label="Chart Period" mappings=[0="Hour", 1="Day", 2="Week"]\n' ) outf:write( ' Chart item=' .. i .. ' period=h refresh=600 visibility=[' .. p .. '==0, ' .. p .. '=="Uninitialized"]\n' ) outf:write( ' Chart item=' .. i .. ' period=D refresh=600 visibility=[' .. p .. '==1]\n' ) outf:write( ' Chart item=' .. i .. ' period=W refresh=600 visibility=[' .. p .. '==2]\n' ) outf:write( ' }\n' ) end outf:write( '}\n' ) outf:close() end -- persistence_rrd4j() function write_persistence_rrd4j() outf = io.open( output_directory .. '/rrd4j.persist_add', 'w' ) for k, v in pairs( device_types ) do t = string.match( k or '', '%:(%a*)%:1' ) i = '_' .. tostring( t ) .. 's' outf:write( i .. '* : strategy = everyChange, everyMinute, restoreOnStartup\n' ) end outf:close() end -- write_persistence_rrd4j() write_items() write_sitemap() write_persistence_rrd4j()
Tips & Tricks
Synchronizing Vera's devices with openHAB
Mount ~/openHAB/runtime/configurations/items on Vera (see http://forum.micasaverde.com/index.php/topic,16452.msg125963.html#msg125963) and write the items file via Apps -> Develop Apps -> Edit Startup Lua.