Log which binding sent which commands to items


is it possible to log where a command came from?

Here is an example of what I mean:

rule "LogLight"
        Item Light_FF_Bath_Ceiling received command
    logInfo("Light_FF_Bath_Ceiling", "Where did the command came from?")

This is in the demo house of openHAB 1.x. Is there any way to determine which binding or even which class has sent the command?

I appreciate your help.


You can split your Items in one for each binding plus one for the UI. You will have to use rules to combine the updates, certainly.


thank you for your reply. :slight_smile:

Is there any way to achieve this without having to create one binding for each item? It doesn’t have to be openHAB 1.x. I’m fine with 2.x too. :stuck_out_tongue:

If not I will look through the code of openHAB and might add it myself. :slight_smile:


edit: And could you please explain a little bit further what you mean with using rules to combine the updates? Thank you very much for your help. :slight_smile:

I don’t think openHAB gives information about the source of an update (at least you could get information in debug-mode, because the binding itself would log additional informations, but that’s not what you want).
So you have to ensure that every source generates different updates, e.g. if you normally would define an item:

Switch MyItem "Light [%s]" {knx="...", zwave="...", mios="..."}

to ensure, that the light can be switched with different sources from all three buses, you have to set five Items:

Group MyItem
Switch MyItem_knx   "Light knx"   (MyItem) {knx="..."} //receive only
Switch MyItem_zwave "Light zwave" (MyItem) {zwave="..."} //receive only
Switch MyItem_mios  "Light mios"  (MyItem) {mios="..."} //receive only
Switch MyItem_UI    "Light [%s]"  (MyItem)  //receive only
Switch MyItem_send "Light Relais" (MyItem) {whatever} //send only

The Group itself has to be persisted (not MyItem* but MyItem !).
And a rule:

var boolean MyLock=false

rule "MyItem"
    Item MyItem_knx   received command or
    Item MyItem_zwave received command or
    Item MyItem_mios  received command or
    Item MyItem_UI    received command 
    if (!MyLock) {
        MyLock = true
        if (MyItem.lastUpdate.name!="MyItem_send") {
            logInfo("MyItem","Command received from {}",MyItem.lastUpdate.name)
            if(MyItem_knx.state   != MyItem_send.state) MyItem_knx.sendCommand(receivedCommand)
            if(MyItem_zwave.state != MyItem_send.state) MyItem_zwave.sendCommand(receivedCommand)
            if(MyItem_mios.state  != MyItem_send.state) MyItem_mios.sendCommand(receivedCommand)
            if(MyItem_UI.state    != MyItem_send.state) MyItem_UI.postUpdate(receivedCommand)
        MyLock = false

This is not tested, but in theory, you would get the information because every binding has its own item. The rule is then to synchronise the Items. The rule will be triggered multiple times, therefore you have to lock the rule. I’m totally sure this whole thing is very hacky :wink:

One of the goals of OH is to provide an abstraction between the devices/things and the logic that drives your home automation. From that perspective your rule shouldn’t care where the event came from, only that the event occurred. If the rule does something different based on where the event came from, you should separate your config into separate Items so you get different events based on where it is coming from.

Assuming that it is possible to preserve the source of an event and make it available to the rule easily, I’m not certain it would be accepted in a PR as it goes against this abstraction. In OH 2 there is even more layers of abstraction between the actual device/sensor and the rules adding at least one more layer that the info would have to pass through.

Given this, my question back to you is what are you trying to achieve?

I’ve found a lot of people come to this forum asking a technical question like this having already formulated an approach to solve their problem but once their end goals are revealed we can suggest an easier or alternative way to reach the end goal. One that doesn’t require additions or changes to the code.