Obtain binding from item

I’ve searched for a long time for an answer: how do I obtain the bindings of an item?

For example, I have an item KitchenTemp item with the following homematic binding:

Number KitchenTemp "Temperature kitchen [%.1f °C]" <temperature> (gTemp) {
  homematic="address=LEQ4745704, channel=2, parameter=ACTUAL_TEMPERATURE"
}

How do I access the binding data (address, channel etc.) from a rule? For example something like this (not working):

rule "Test"
when
  KitchenTemp received update
then
  // does not work!
  var String addr = KitchenTemp.bindings.homematic.address
end

I also tried org.openhab.binding.homematic.internal.common.HomematicContext but without success:

rule "Test"
when
  KitchenTemp received update
then
  var HomematicContext ctx = HomematicContext.getInstance()
  ctx.getProviders().forEach([ Object p | 
      logInfo("Test", "Provider: " + p.class.name)
  ])
end

However, class HomematicContext seems to be inaccessible from rules.

Thanks in advance,

Daniel

You don’t. By design Rules, Persistence, and Sitemaps are completely unaware of the specific bindings Items are bound to.

That’s a pity, but thanks for your response.

What is your use case for needing this information? There may be another way to achieve the same thing.

I want to reset the sticky unreach messages of Homematic devices. For example, I have the following item:

Switch FooSU     "Foo [MAP(unreach.map):%s]"
  <sysinfo> (gSys, gSysMsg) {
    homematic="address=LEQ47503343, channel=0, parameter=STICKY_UNREACH, forceUpdate=true"
  }

Simply setting the switch to OFF does not really reset the STICKY_UNREACH flag on CCU. So I tried to define another Homematic variable which should contain the device address and a switch and wrote a Homematic script to reset the STICKY_UNREACH flag of the device with the specified address whenever the switch is set to ON.

Here are the additional items:

Switch SysMsgReset      "Reset sys messages"
  {
    homematic="address=BidCoS-RF, channel=3, parameter=PRESS_SHORT, forceUpdate=true"
  }
String SysMsgResetAdr   "Address to reset sys message"
  {
    homematic="variable=SysMsgResetAddr"
  }

I’d like to use the following rule:

rule "Reset sys messages"
when
  Item gSysMsg received update
then
  var item = gSysMsg.members.sortBy[lastUpdate].last
  if (item.state == OFF) {
    // This does not work unfortunately:
    var String addr = item.bindings.homematic.address
    sendCommand(SysMsgResetAdr, addr)
    sendCommand(SysMsgReset, ON)
  }
end

Well, if something like this is going to be possible it has to be implemented in the Homematic binding itself.

However, if I understand what you are trying to do, you might be able to achieve the same thing by creating a switch for each address and finding the correct Item based on the Item’s name. For example:

val  addrItem = gSysAddrs.members.filter[a|a.name = "Homematic_Addr_" + item.name]
addrItem.sendCommand(ON)

Thanks for the suggestion, but I’ve tried that way already. The problem is that the Homematic binding does not reliably reset the STICKY UNREACH flag in the CCU. In CCU the STICKY UNREACH flag is available twice: in channel 0 of a device there are data point BidCos-RF.LEQ1234567:0.STICKY_UNREACH and AL-LEQ1234567:0.STICKY_UNREACH. Both must be reset in order to clear this flag. That’s the reason why I wrote a Homematic script and would call it with the address from the binding.