diff --git a/bundles/org.openhab.binding.openwebnet/README.md b/bundles/org.openhab.binding.openwebnet/README.md index b7b311701dc..36bead496d9 100644 --- a/bundles/org.openhab.binding.openwebnet/README.md +++ b/bundles/org.openhab.binding.openwebnet/README.md @@ -148,7 +148,7 @@ Thermo zones can be configured defining a `bus_thermo_zone` Thing for each zone - the `where` configuration parameter (`OpenWebNet Address`): - example BUS/SCS zone `1` --> `where="1"` -- the `standAlone` configuration parameter (`boolean`, default: `true`): identifies if the zone is managed or not by a Central Unit (4 or 99 zones). `standAlone=true` means no Central Unit is present in the system. +- the `standAlone` configuration parameter (`boolean`, default: `true`): identifies if the zone is managed or not by a Central Unit (4- or 99-zones). `standAlone=true` means no Central Unit is present in the system. Temperature sensors can be configured defining a `bus_thermo_sensor` Thing with the following parameters: @@ -156,19 +156,18 @@ Temperature sensors can be configured defining a `bus_thermo_sensor` Thing with - example sensor `5` of external zone `00` --> `where="500"` - example: slave sensor `3` of zone `2` --> `where="302"` -The (optional) Central Unit can be configured defining a `bus_themo_cu` Thing with the `where` configuration parameter (`OpenWebNet Address`) set to `where="0"`. +The (optional) Central Unit can be configured defining a `bus_themo_cu` Thing with the `where` configuration parameter (`OpenWebNet Address`) set to `where="#0"` for a 99-zone Central Unit or `where="#0#1"` for a 4-zone Central Unit. ##### Thermo Central Unit integration missing points - Read setPoint temperature and current mode -- Holiday activation command (all zones) -- Discovery +- Holiday/Vacation activation command #### Configuring Alarm and Auxiliary (AUX) **NOTE 1** Receiving AUX messages originating from the BUS is not supported yet, only sending messages to the BUS is supported -**NOTE 2** Alarm messages on BUS are not sent by MyHOMEServer1, therfore this gateway cannot be used to integrate the BTicino Alarm system +**NOTE 2** Alarm messages on BUS are not sent by MyHOMEServer1, therefore this gateway cannot be used to integrate the BTicino Alarm system BUS Auxiliary commands (WHO=9) can be used to send on the BUS commands to control, for example, external devices or a BTicino Alarm system. @@ -327,7 +326,7 @@ Bridge openwebnet:bus_gateway:mybridge "MyHOMEServer1" [ host="192.168.1.35", pa bus_energy_meter CENTRAL_Ta "Energy Meter Ta" [ where="51" ] bus_energy_meter CENTRAL_Tb "Energy Meter Tb" [ where="52" ] - bus_thermo_cu CU_3550 "99 zones central unit" [ where="0" ] + bus_thermo_cu CU_3550 "99 zones Central Unit" [ where="#0" ] bus_thermo_zone LR_zone "Living Room Zone" [ where="2"] bus_thermo_sensor EXT_tempsensor "External Temperature" [ where="500"] @@ -531,6 +530,7 @@ Special thanks for helping on testing this binding go to: [@rubenfuser](https://community.openhab.org/u/rubenfuser), [@stamate_viorel](https://community.openhab.org/u/stamate_viorel), [@marchino](https://community.openhab.org/u/marchino), -[@the-ninth](https://community.openhab.org/u/the-ninth) +[@the-ninth](https://community.openhab.org/u/the-ninth), +[@giacob](https://community.openhab.org/u/giacob) and many others at the fantastic openHAB community! diff --git a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/discovery/OpenWebNetDeviceDiscoveryService.java b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/discovery/OpenWebNetDeviceDiscoveryService.java index f1c8d675ed2..a4de4fb0555 100644 --- a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/discovery/OpenWebNetDeviceDiscoveryService.java +++ b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/discovery/OpenWebNetDeviceDiscoveryService.java @@ -59,6 +59,8 @@ public class OpenWebNetDeviceDiscoveryService extends AbstractDiscoveryService private @NonNullByDefault({}) OpenWebNetBridgeHandler bridgeHandler; private @NonNullByDefault({}) ThingUID bridgeUID; + private boolean cuFound = false; + public OpenWebNetDeviceDiscoveryService() { super(SUPPORTED_THING_TYPES, SEARCH_TIME_SEC); } @@ -72,6 +74,7 @@ public class OpenWebNetDeviceDiscoveryService extends AbstractDiscoveryService protected void startScan() { logger.info("------ SEARCHING for DEVICES on bridge '{}' ({}) ...", bridgeHandler.getThing().getLabel(), bridgeUID); + cuFound = false; bridgeHandler.searchDevices(); } @@ -237,15 +240,38 @@ public class OpenWebNetDeviceDiscoveryService extends AbstractDiscoveryService String whereConfig = w.value(); - // remove # from discovered thermo zone/central unit or alarm zone - if (OpenWebNetBindingConstants.THING_TYPE_BUS_THERMO_ZONE.equals(thingTypeUID) - || OpenWebNetBindingConstants.THING_TYPE_BUS_THERMO_CU.equals(thingTypeUID)) { - whereConfig = "" + ((WhereThermo) where).getZone(); - } else if (OpenWebNetBindingConstants.THING_TYPE_BUS_ALARM_ZONE.equals(thingTypeUID)) { - whereConfig = "" + ((WhereAlarm) where).getZone(); + // remove # from discovered alarm zone + if (OpenWebNetBindingConstants.THING_TYPE_BUS_ALARM_ZONE.equals(thingTypeUID)) { + whereConfig = "" + ((WhereAlarm) w).getZone(); } - if (w instanceof WhereZigBee && WhereZigBee.UNIT_02.equals(((WhereZigBee) where).getUnit())) { - logger.debug("UNIT=02 found (WHERE={}) -> will remove previous result if exists", where); + + Map properties = new HashMap<>(2); + + // detect Thermo CU type + if (OpenWebNetBindingConstants.THING_TYPE_BUS_THERMO_CU.equals(thingTypeUID)) { + cuFound = true; + logger.debug("CU found: {}", w); + if (w.value().charAt(0) == '#') { // 99-zone CU + thingLabel += " 99-zone"; + logger.debug("@@@@@ THERMO CU found 99-zone: where={}, ownId={}, whereConfig={}", w, ownId, + whereConfig); + } else { + thingLabel += " 4-zone"; + whereConfig = "#" + w.value(); + logger.debug("@@@@ THERMO CU found 4-zone: where={}, ownId={}, whereConfig={}", w, ownId, whereConfig); + } + } else if (OpenWebNetBindingConstants.THING_TYPE_BUS_THERMO_ZONE.equals(thingTypeUID)) { + if (cuFound) { + // set param standalone = false for thermo zone + properties.put(OpenWebNetBindingConstants.CONFIG_PROPERTY_STANDALONE, false); + } + whereConfig = "" + ((WhereThermo) w).getZone(); + logger.debug("@@@@@ THERMO ZONE found: where={}, ownId={}, whereConfig={}, standalone={}", w, ownId, + whereConfig, properties.get(OpenWebNetBindingConstants.CONFIG_PROPERTY_STANDALONE)); + } + + if (w instanceof WhereZigBee && WhereZigBee.UNIT_02.equals(((WhereZigBee) w).getUnit())) { + logger.debug("UNIT=02 found (WHERE={}) -> will remove previous result if exists", w); thingRemoved(thingUID); // remove previously discovered thing // re-create thingUID with new type thingTypeUID = OpenWebNetBindingConstants.THING_TYPE_ZB_ON_OFF_SWITCH_2UNITS; @@ -256,7 +282,6 @@ public class OpenWebNetDeviceDiscoveryService extends AbstractDiscoveryService OpenWebNetBindingConstants.THING_TYPE_ZB_ON_OFF_SWITCH, OpenWebNetBindingConstants.THING_TYPE_ZB_ON_OFF_SWITCH_2UNITS); } - Map properties = new HashMap<>(2); properties.put(OpenWebNetBindingConstants.CONFIG_PROPERTY_WHERE, whereConfig); properties.put(OpenWebNetBindingConstants.PROPERTY_OWNID, ownId); if (OpenWebNetBindingConstants.THING_TYPE_GENERIC_DEVICE.equals(thingTypeUID)) { diff --git a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetBridgeHandler.java b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetBridgeHandler.java index 73a3a75f94b..6522eae33cc 100644 --- a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetBridgeHandler.java +++ b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetBridgeHandler.java @@ -743,7 +743,8 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement if (str.indexOf('#') == 0) { // Thermo central unit (#0) or zone via central unit (#Z, Z=[1-99]) --> Z, // Alarm Zone (#Z) --> Z str = str.substring(1); - } else if (str.indexOf('#') > 0) { // Thermo zone Z and actuator N (Z#N, Z=[1-99], N=[1-9]) --> Z + } else if (str.indexOf('#') > 0 && str.charAt(0) != '0') { // Thermo zone Z and actuator N (Z#N, + // Z=[1-99], N=[1-9]) --> Z str = str.substring(0, str.indexOf('#')); } } diff --git a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetThermoregulationHandler.java b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetThermoregulationHandler.java index a7b9a87b4b4..cccc420ec35 100644 --- a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetThermoregulationHandler.java +++ b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetThermoregulationHandler.java @@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory; * commands/messages for Thermoregulation * Things. It extends the abstract {@link OpenWebNetThingHandler}. * - * @author Massimo Valla - Initial contribution + * @author Massimo Valla - Initial contribution. Added support for 4-zone CU * @author Andrea Conte - Thermoregulation * @author Gilberto Cocchi - Thermoregulation */ @@ -64,7 +64,7 @@ public class OpenWebNetThermoregulationHandler extends OpenWebNetThingHandler { private Thermoregulation.Function currentFunction = Thermoregulation.Function.GENERIC; private Thermoregulation.OperationMode currentMode = Thermoregulation.OperationMode.MANUAL; - private boolean isStandAlone = false; + private boolean isStandAlone = true; // true if zone is not associated to a CU private boolean isCentralUnit = false; @@ -95,18 +95,19 @@ public class OpenWebNetThermoregulationHandler extends OpenWebNetThingHandler { if (!isCentralUnit) { Object standAloneConfig = getConfig().get(OpenWebNetBindingConstants.CONFIG_PROPERTY_STANDALONE); if (standAloneConfig != null) { - // null in case of thermo_sensor isStandAlone = Boolean.parseBoolean(standAloneConfig.toString()); } + logger.debug("@@@@ THERMO ZONE INITIALIZE isStandAlone={}", isStandAlone); } else { - // central unit must have WHERE=0 - if (!deviceWhere.value().equals("0")) { - logger.warn("initialize() Invalid WHERE={} for Central Unit.", deviceWhere.value()); + // central unit must have WHERE=#0 or WHERE=0 or WHERE=#0#n + String w = deviceWhere.value(); + if (w == null || !("0".equals(w) || "#0".equals(w) || w.startsWith("#0#"))) { + logger.warn("initialize() Invalid WHERE={} for Central Unit.", deviceWhere.value()); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/offline.conf-error-where"); + return; } - // reset state of signal channels (they will be setted when specific messages // are received) updateState(CHANNEL_CU_AT_LEAST_ONE_PROBE_MANUAL, OnOffType.OFF); @@ -266,7 +267,7 @@ public class OpenWebNetThermoregulationHandler extends OpenWebNetThingHandler { private String getWhere(String where) { if (isCentralUnit) { - return "#0"; + return where; } else { return isStandAlone ? where : "#" + where; } @@ -295,6 +296,8 @@ public class OpenWebNetThermoregulationHandler extends OpenWebNetThingHandler { protected void handleMessage(BaseOpenMessage msg) { super.handleMessage(msg); + logger.debug("@@@@ Thermo.handleMessage(): {}", msg.toStringVerbose()); + if (isCentralUnit) { if (msg.getWhat() == null) { return; @@ -572,21 +575,21 @@ public class OpenWebNetThermoregulationHandler extends OpenWebNetThingHandler { @Override protected void refreshDevice(boolean refreshAll) { logger.debug("--- refreshDevice() : refreshing SINGLE... ({})", thing.getUID()); - if (isCentralUnit) { - // TODO: 4 zone central -> zone #0 CAN be also a zone with its temp.. with - // 99-zones central no! let's assume it's a 99 zone - try { - send(Thermoregulation.requestStatus("#0")); - } catch (OWNException e) { - logger.warn("refreshDevice() central unit returned OWNException {}", e.getMessage()); - } - - return; - } if (deviceWhere != null) { - String w = deviceWhere.value(); + + if (isCentralUnit) { + // TODO: 4 zone central -> zone #0 CAN be also a zone with its temp.. with + // 99-zones central no! let's assume it's a 99 zone + try { + send(Thermoregulation.requestStatus(w)); + } catch (OWNException e) { + logger.warn("refreshDevice() central unit returned OWNException {}", e.getMessage()); + } + return; + } + try { send(Thermoregulation.requestTemperature(w)); @@ -615,6 +618,8 @@ public class OpenWebNetThermoregulationHandler extends OpenWebNetThingHandler { } catch (OWNException e) { logger.warn("refreshDevice() where='{}' returned OWNException {}", w, e.getMessage()); } + } else { + logger.debug("refreshDevice() where is null"); } } } diff --git a/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/i18n/openwebnet.properties b/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/i18n/openwebnet.properties index 0eca8770231..7b646831e9f 100644 --- a/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/i18n/openwebnet.properties +++ b/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/i18n/openwebnet.properties @@ -89,7 +89,7 @@ thing-type.config.openwebnet.bus_on_off_switch.where.description = Example: A/PL thing-type.config.openwebnet.bus_scenario_control.where.label = OpenWebNet Address (where) thing-type.config.openwebnet.bus_scenario_control.where.description = Example: scenario control module address 53 --> where=53. On local bus: where=53#4#01 thing-type.config.openwebnet.bus_thermo_cu.where.label = OpenWebNet Address (where) -thing-type.config.openwebnet.bus_thermo_cu.where.description = The Central Unit can only assume where=0. +thing-type.config.openwebnet.bus_thermo_cu.where.description = For Thermo Central Unit 99-zones --> where=#0, for 4-zones --> where=#0#1 thing-type.config.openwebnet.bus_thermo_sensor.where.label = OpenWebNet Address (where) thing-type.config.openwebnet.bus_thermo_sensor.where.description = Example: sensor 3 of zone 2 --> where=302. Sensor 5 of external zone 00 --> where=500 thing-type.config.openwebnet.bus_thermo_zone.standAlone.label = Stand-alone diff --git a/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/BusThermoCentralUnit.xml b/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/BusThermoCentralUnit.xml index a660739a2d1..e0879bcc353 100644 --- a/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/BusThermoCentralUnit.xml +++ b/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/BusThermoCentralUnit.xml @@ -38,11 +38,11 @@ ownId - + - The Central Unit can only assume where=0. - 0 + For Thermo Central Unit 99-zones --> where=#0, for 4-zones --> where=#0#1 + diff --git a/bundles/org.openhab.binding.openwebnet/src/test/java/org/openhab/binding/openwebnet/internal/handler/OwnIdTest.java b/bundles/org.openhab.binding.openwebnet/src/test/java/org/openhab/binding/openwebnet/internal/handler/OwnIdTest.java index 3781c25b8b1..59a1371910a 100644 --- a/bundles/org.openhab.binding.openwebnet/src/test/java/org/openhab/binding/openwebnet/internal/handler/OwnIdTest.java +++ b/bundles/org.openhab.binding.openwebnet/src/test/java/org/openhab/binding/openwebnet/internal/handler/OwnIdTest.java @@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory; * using {@link OpenWebNetBridgeHandler} methods: normalizeWhere(), * ownIdFromWhoWhere(), ownIdFromMessage(), thingIdFromWhere() * - * @author Massimo Valla - Initial contribution, updates + * @author Massimo Valla - Initial contribution, various updates * @author Andrea Conte - Energy management * @author Giovanni Fabiani - Auxiliary message support */ @@ -59,7 +59,10 @@ public class OwnIdTest { * BUS Switch 51 51 1.51 51 * BUS Local Bus 25#4#01 25h4h01 1.25h4h01 25h4h01 * BUS Autom 93 93 2.93 93 - * BUS Thermo #1 or 1 1 4.1 1 + * BUS Thermo zone 1 1 4.1 1 + * BUS Thermo zone CU #1 1 4.1 1 + * BUS Thermo CU 99-z #0 0 4.0 0 + * BUS Thermo CU 4-z #0#1 0h1 4.0h1 0h1 * BUS Thermo actuator 1#2 1 4.1 1 * BUS TempSensor 500 500 4.500 500 * BUS Energy 51 51 18.51 51 @@ -76,15 +79,17 @@ public class OwnIdTest { public enum TEST { // @formatter:off - // msg, who, where, normW, ownId, thingId + // msg, who, where, normalizeWhere, ownId, thingId zb_switch("*1*1*789309801#9##", Who.fromValue(1), new WhereZigBee("789309801#9"), "789309800h9", "1.789309800h9", "789309800h9"), zb_switch_2u_1("*1*1*789301201#9##", Who.fromValue(1), new WhereZigBee("789301201#9"), "789301200h9", "1.789301200h9", "789301200h9"), zb_switch_2u_2("*1*1*789301202#9##", Who.fromValue(1), new WhereZigBee("789301202#9"), "789301200h9", "1.789301200h9", "789301200h9"), bus_switch("*1*1*51##", Who.fromValue(1), new WhereLightAutom("51"),"51", "1.51", "51"), bus_localbus("*1*1*25#4#01##", Who.fromValue(1), new WhereLightAutom("25#4#01"), "25h4h01", "1.25h4h01", "25h4h01"), bus_autom("*2*0*93##",Who.fromValue(2), new WhereLightAutom("93"), "93", "2.93", "93"), - bus_thermo_via_cu("*#4*#1*0*0020##", Who.fromValue(4), new WhereThermo("#1"), "1", "4.1", "1"), - bus_thermo("*#4*1*0*0020##", Who.fromValue(4), new WhereThermo("1"), "1", "4.1", "1"), + bus_thermo_zone("*#4*1*0*0020##", Who.fromValue(4), new WhereThermo("1"), "1", "4.1", "1"), + bus_thermo_zone_via_cu("*#4*#1*0*0020##", Who.fromValue(4), new WhereThermo("#1"), "1", "4.1", "1"), + bus_thermo_cu_99("*#4*#0##", Who.fromValue(4), new WhereThermo("#0") ,"0", "4.0", "0"), + bus_thermo_cu_4("*#4*#0#1##", Who.fromValue(4), new WhereThermo("#0#1") ,"0h1", "4.0h1", "0h1"), bus_thermo_act("*#4*1#2*20*0##", Who.fromValue(4), new WhereThermo("1#2") ,"1", "4.1", "1"), bus_tempSensor("*#4*500*15*1*0020*0001##",Who.fromValue(4), new WhereThermo("500"), "500", "4.500", "500"), bus_energy("*#18*51*113##", Who.fromValue(18), new WhereEnergyManagement("51"), "51", "18.51", "51"),