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:
- 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:192.168.1.12:tempMin}
Number aComplexDevice_tempMax "Max. temp." (temperatures) {complexDevice:192.168.1.12:tempMax}
etc...
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.
- 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:192.168.1.12}
Number aComplexDevice_tempMin "Min. temp." (temperatures)
Number aComplexDevice_tempMax "Max. temp." (temperatures)
etc...
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")
}
ComplexDeviceBinding.java’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