Theoretic: rare query of binding with complex results

Hi All,

I have a theoretic question: our device can report several values for a query. If I make a binding for it, I have basically 2 possibilities:

  1. Make several items, one for each value, and configure different binding parameters for them but for the same device:
Number aComplexDevice_tempMin "Min. temp." (temperatures) {complexDevice:}
Number aComplexDevice_tempMax "Max. temp." (temperatures) {complexDevice:}

This way the binding will be instantiated several times, each continuing to poll the device, making the whole request in each poll and selecting the configured value. This introduces unnecessary overhead, since the values are needed rarely and one binding instance per device would be more appropriate.

  1. Make a “write-only” item and several “read-only” ones. The write-only one would be used to trigger the binding query, which would then update the read-only ones. This update could occur in a try/catch block, so the .items file would not have to define every read-only variable, only the interesting ones. Other rules would then observe these items for value update. The items would then look like so:
String aComplexDevice    {complexDevice:}
Number aComplexDevice_tempMin "Min. temp." (temperatures)
Number aComplexDevice_tempMax "Max. temp." (temperatures) 

Note the name structure.A Groovy rule triggering the query would look like:

void execute(Event event) {
    Item aComplexDevice = Global.itemRegistry.getItem("aComplexDevice");
    Openhab.sendCommand(aComplexDevice, "something")
}’s appropriate method would look like:

protected void internalReceiveCommand(String itemName, Command command) {
    for (KeContactPBindingProvider provider : this.providers) {
        InetAddress address = provider.getAddress(itemName);
        int port = provider.getPort(itemName);
        Map<String,Object> result = complexQuery(address, port, command);
        ItemRegistry itemRegistry = //somehow obtain it
        for(String key: result.keySet()) {
            try {
                String readOnlyName = itemName + "_" + key;
                Item item = itemRegistry.getItem(readOnlyName);
                eventPublisher.postUpdate(readOnlyNameName, new DecimalType(result.get(key)));
            catch(ItemNotFoundException infe) {} // item not defined, don't care

I’m not very familiar with item possibilities. Is there a more suitable third possibility?

Thank you in advance, best regards: Balazs Bamer

Assuming you are working with OH 2 (I’d recommend all new bindings be written for OH 2), you would create one Thing with multiple Channels. Each Channel is associated with the one value or control point. See,, and

If you are working with OH 1.8, look at the zwave, HTTP, and KNX bindings for how they handled this situation. From what you describe in 2, this is a very similar situation these bindings have solved.

To a large degree the “write” device to request a refresh is typically handled internal to the binding and configured with a polling period in the cfg file, assuming that is the only thing you would write to it.

Keep in mind I’ve not coded on OH and the above is based strictly on my conclusions from watching the behavior of various bindings.

Thank you for the answer. Unfortunately we are still tied to 1.8, but later we will migrate to 2.0. Until then I will use my second variant, since there are other commands t osend it as well.

Best regards: Balazs Bamer

One approach that may be worth considering is whether it makes sense to make the write Item be an Action instead of an Item.

I can’t really decide, but I think an item is more appropriate for me.