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.
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.
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.