Switch Mapping for String Item

Hello,

i am using the HarmoyHub Binding which uses a String item for switching available Harmony activities (e.g. “TV”, “DVD”, “Radio”, etc…):

String HarmonyActivity "Aktivität [%s]" { channel="harmonyhub:hub:HarmonyHub:currentActivity" }

I want to have a switch item for use in the HomeKit Integration which has a mapping
0 = "OFF"
1 = "TV"
to control the Harmony Hub activity.

How can I create such an item? Mapping directly in the .item-File seems not to be possible…

Thanks for your help!

I set mine up using a sitemap and a rule (though you could skip the sitemap if you are using another interface and just setup the item and the rule). I don’t have mine in front of me, but basically (no promises that there are no typos ;-):

Switch item=HarmonySwitch

Rule "Hamony"
when
  Item HamonySwitch changed
then
  if (HarmonySwitch == 1) {
     HarmonyActivity.sendCommand("TV")
  } else {
    HarmonyActivity.sendCommand("OFF")
end

For mine I used a selection element in my sitemap and used switch / case in my rule for different activities.

Thanks @rgerrans the works of course, did not thought about rules.
I had expected a more elegant way to do this directly within the item configuration but this seems not to be possible with OH2…

You can use a Switch widget in a sitemap with a mappings element to send different string commands to your String item:

items/your.items

String HarmonyActivity "Aktivität [%s]" { channel="harmonyhub:hub:HarmonyHub:currentActivity" }

sitemaps/your.sitemap.fragment

Switch item=HarmonyActivity mappings=[OFF=OFF,TV=TV,HDMI1=HDMI1]

@watou But this does not help for the HomeKit integration as wrote in my original question…

The rule approach @rgerrans offered (with the change to if (HarmonySwitch.state == 1) { would be the best option I can think of.

I’ not sure if it not possible. Take a look to the example from the xbmc1 binding for openhab2.

Switch XBMC_Power "XBMC Power" {xbmc=">[#openelec|System.Shutdown]", wol="192.168.1.0#xx:xx:xx:xx:xx:xx", nh="openelec:80"}

XBMC binding (for KODI) (1.x)