Connect SDK Binding - sprehn/openhab GitHub Wiki
Connect SDK binding is currently work in progress. You can beta test these releases, if you like.
Documentation of the Connect SDK binding Bundle
Introduction
The Connect SDK binding allows you to connect an LG WebOS TV to the openhab bus. Other devices supported by the ConnectSDK framework (e.g. AppleTV) are currently not supported.
For installation of the binding, please see Wiki page Bindings.
Binding Configuration
For this binding no configuration is required in your openhab.cfg file. An optional configuration entry exists to configure the local ip.
############################## Connect SDK Binding #########################
# Local IP to bind to. This is optional and only has to be set if the binding is unable to detect it.
#connectsdk:localIp=192.168.1.117
Item Binding Configuration
Item strings simply consist of three components - the device name (can be an IP or hostname on your network), the Control Class and the actual property. All three parameters are only separated by a colon.
String LG_TV0_Channel "Channel: [%s]" { connectsdk="lgwebostv.fritz.box:TVControl:channel" }
Switch LG_TV0_ChannelUp "Channel Up" { connectsdk="lgwebostv.fritz.box:TVControl:up" , autoupdate="false"}
Switch LG_TV0_ChannelDown "Channel Down" { connectsdk="lgwebostv.fritz.box:TVControl:down", autoupdate="false" }
/* read only properties */
String LG_TV0_ChannelName "Channel: [%s]" { connectsdk="lgwebostv.fritz.box:TVControl:channelName" }
Number LG_TV0_Volume "Volume: [%s]" { connectsdk="192.168.1.128:VolumeControl:volume" }
Switch LG_TV0_VolumeUp "Volume Up" { connectsdk="lgwebostv.fritz.box:VolumeControl:up", autoupdate="false" }
Switch LG_TV0_VolumeDown "Volume Down" { connectsdk="lgwebostv.fritz.box:VolumeControl:down", autoupdate="false"}
Dimmer LG_TV0_VolumeUpDown "Volume" { connectsdk="lgwebostv.fritz.box:VolumeControl:updown"}
Switch LG_TV0_Mute "Mute" { connectsdk="lgwebostv.fritz.box:VolumeControl:mute" }
Switch LG_TV0_Power "Power" { connectsdk="lgwebostv.fritz.box:PowerControl:power", autoupdate="false" }
String LG_TV0_MediaPlayState "State" { connectsdk="lgwebostv.fritz.box:MediaControl:playState"}
Switch LG_TV0_MediaRewind "Rewind" { connectsdk="lgwebostv.fritz.box:MediaControl:rewind", autoupdate="false" }
Switch LG_TV0_MediaPlay "Play" { connectsdk="lgwebostv.fritz.box:MediaControl:play", autoupdate="false" }
Switch LG_TV0_MediaPause "Pause" { connectsdk="lgwebostv.fritz.box:MediaControl:pause", autoupdate="false" }
Switch LG_TV0_MediaForward "Forward" { connectsdk="lgwebostv.fritz.box:MediaControl:forward", autoupdate="false" }
Switch LG_TV0_MediaStop "Stop" { connectsdk="lgwebostv.fritz.box:MediaControl:stop", autoupdate="false" }
String LG_TV0_Input "Input" { connectsdk="lgwebostv.fritz.box:ExternalInputControl:input" }
String LG_TV0_Toast { connectsdk="lgwebostv.fritz.box:ToastControl:toast" }
The following class property combinations are, and their associated item types are shown below. The RO and RW in the Direction column indicate which properties are read only (RO) or read/write (RW) or write only (WO)
Class | Property | Type Supported | Direction | Description |
---|---|---|---|---|
TVControl | channel | String | RW | TV channel |
TVControl | up | Switch | WO | One TV channel up |
TVControl | down | Switch | WO | One TV channel down |
TVControl | channelName | String | RO | Name of the current channel |
TVControl | program | String | RO | Name of the current program (untested - TV does not seem to provide value) |
VolumeControl | volume | Number | RW | TV volume. Note this only produces reasonable values when using internal speakers. Connected to an external amp the volume can only be controlled using up and down. |
VolumeControl | up | Switch | WO | One volume step up |
VolumeControl | down | Switch | WO | One volume step down |
VolumeControl | updown | Dimmer | WO | Up and down in one binding. This is an experiment. |
VolumeControl | mute | Switch | RW | Mute |
PowerControl | power | Switch | WO | Power, only power off is currently supported by connect sdk for WebOS |
MediaControl | playState | String | RO | Play State (untested - TV does not seem to provide value) |
MediaControl | rewind | Switch | WO | Rewind |
MediaControl | play | Switch | WO | Play |
MediaControl | pause | Switch | WO | Pause |
MediaControl | forward | Switch | WO | Forward |
MediaControl | stop | Switch | WO | Stop |
ExternalInputControl | input | String | RW | Select external input, e.g. HDMI_1. (unclear how to select TV again) |
ToastControl | toast | String | WO | Display a notification message on the TV |
This is an example of a matching sitemap fragment:
Frame label="TVControl" {
Text item=LG_TV0_Channel
Selection item=LG_TV0_Channel mappings=[1=ARD, 2=ZDF, 6=VOX]
Switch item=LG_TV0_ChannelUp mappings=[ON="Up"]
Switch item=LG_TV0_ChannelDown mappings=[ON="Down"]
Text item=LG_TV0_ChannelName
}
Frame label="TVVolume" {
Text item=LG_TV0_Volume
Switch item=LG_TV0_VolumeUp mappings=[ON="Up"]
Switch item=LG_TV0_VolumeDown mappings=[ON="Down"]
Switch item=LG_TV0_Mute
}
Frame label="TVPower" {
Switch item=LG_TV0_Power
}
Frame label="TVInput" {
Selection item=LG_TV0_Input mappings=[HDMI_1=Playstation, HDMI_3="Apple TV"]
}
Frame label="TVMedia" {
Text item=LG_TV0_MediaPlayState
Switch item=LG_TV0_MediaRewind mappings=[ON="Rewind"]
Switch item=LG_TV0_MediaPlay mappings=[ON="Play"]
Switch item=LG_TV0_MediaPause mappings=[ON="Pause"]
Switch item=LG_TV0_MediaForward mappings=[ON="Forward"]
Switch item=LG_TV0_MediaStop mappings=[ON="Stop"]
}
Powering ON
Connect SDK currently does not support powering on WebOS devices (WebOSTVService does not support capability PowerControl.ON). However, there is an alternative way to power on the device via wake on lan. In the settings menu of your TV you need to enable the option to allow Apps to remotely turn on the television. In openhab, you need to include and configure the WOL binding.
Add an item, such as this
Switch LG_TV0_WOL "Power WOL" { wol="192.168.1.255#3c:cd:93:c2:20:e0" }
Note: Network Broadcast IP, not device IP and device's MAC address:
Add a rule, such as this:
Item LG_TV0_Power received command ON
then
sendCommand( LG_TV0_WOL, ON)
end
After sending the WOL event to the TV it does takes a few seconds until device is detected on the network and openhab connects.
Toast Messages
One of the great things about WebOS is, that it allows you to send small messages to the TV and it will display them as a little notification on the screen.
As an example you could send a toast message to the TV once the TV connects to openhab when it is powered on.
rule "Welcome Message"
when
Item LG_TV0_Power changed to ON
then
LG_TV0_Toast.sendCommand("Welcome to Openhab")
end
As another example you could display who is calling (number or even real names) on your TV when the phone rings.
Items (based on fritzbox binding)
Switch Incoming_Call "Call [%s]" { fritzbox="inbound" }
Call Active_Call "Connected to [%2$s]" { fritzbox="active" }
Call Incoming_Call_No "Caller [%2$s]" { fritzbox="inbound" }
Rule
rule "call on"
when
Item Incoming_Call changed to ON
then
val CallType call = Incoming_Call_No.state as CallType
logInfo("incoming_call on", call.origNum.toString)
val HashMap<String, String> phoneBook =
newLinkedHashMap(
"01234567891" -> "Brother",
"01234567892" -> "Sister",
"01234567893" -> "Friend")
val String caller = phoneBook.getOrDefault(call.origNum.toString,call.origNum.toString)
LG_TV0_Toast.sendCommand("Call: "+ caller)
end