From 7f8db869de3e924f3084c34f38ca160bbfa48d05 Mon Sep 17 00:00:00 2001 From: Conte Andrea Date: Fri, 18 Mar 2022 19:00:48 +0100 Subject: [PATCH] [openwebnet] handle Thermo Central Unit monitoring messages (#12485) * - handled what=30 (failure discovered ), what=22 (at least 1 probe in off), what=23 (at least 1 probe in protection), what=24 (at least 1 probe in manual) - related channels added * - update README - ignore messages from probes and central unit and keep track only of messages from a real thermostat * add example of failureDiscovered channel * Update bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/channels.xml * changed capital letters (atLeastOneProbeOFF -> atLeatOneProbeOff) as suggested Signed-off-by: Conte Andrea --- .../org.openhab.binding.openwebnet/README.md | 20 +++-- .../internal/OpenWebNetBindingConstants.java | 4 + .../OpenWebNetThermoregulationHandler.java | 88 +++++++++++++++++-- .../OH-INF/thing/BusThermoCentralUnit.xml | 4 + .../main/resources/OH-INF/thing/channels.xml | 28 ++++++ 5 files changed, 130 insertions(+), 14 deletions(-) diff --git a/bundles/org.openhab.binding.openwebnet/README.md b/bundles/org.openhab.binding.openwebnet/README.md index 0124e26b0efc1..043cfdb30f8a1 100644 --- a/bundles/org.openhab.binding.openwebnet/README.md +++ b/bundles/org.openhab.binding.openwebnet/README.md @@ -188,7 +188,10 @@ The (optional) Central Unit can be configured defining a `bus_themo_cu` Thing. | `batteryStatus` | `bus_thermo_cu` | String | The Central Unit Battery status: `OK`, `KO` | R | Y | | `weeklyProgram` | `bus_thermo_cu` | Number | The program number (`1`, `2`, `3`) when Central Unit mode is `WEEKLY` | R/W | N | | `scenarioProgram` | `bus_thermo_cu` | Number | The program number (`1`, `2`, .. , `16`) when Central Unit mode is `SCENARIO` | R/W | N | - +| `failureDiscovered` | `bus_thermo_cu` | Switch | Indicates if a Failure was discovered by the Central Unit: `ON`, `OFF` | R | Y | +| `atLeastOneProbeOff` | `bus_thermo_cu` | Switch | Indicates if at least one probe is in OFF mode: `ON`, `OFF` | R | Y | +| `atLeastOneProbeProtection` | `bus_thermo_cu` | Switch | Indicates if at least one probe is in PROTECTION mode: `ON`, `OFF` | R | Y | +| `atLeastOneProbeManual` | `bus_thermo_cu` | Switch | Indicates if at least one probe is in MANUAL mode: `ON`, `OFF` | R | Y | ### Notes on channels @@ -291,11 +294,16 @@ Number:Power iCENTRAL_Tb "Power [%.0f %unit%]" { channel="openw // 99 zones central unit Group gCentralUnit "Central Unit" Number:Temperature iCU_3550_manualset "Temperature" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:setpointTemperature", ga="thermostatTemperatureSetpoint" } -String iCU_3550_remote "Remote Control" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:remoteControl" } -String iCU_3550_battery "Battery Status" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:batteryStatus" } -String iCU_3550_mode "Mode" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:mode" } -Number iCU_3550_wpn "Weekly Program" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:weeklyProgram" } -Number iCU_3550_spn "Scenario Program" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:scenarioProgram" } +String iCU_3550_remote "Remote Control" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:remoteControl" } +String iCU_3550_battery "Battery Status" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:batteryStatus" } +String iCU_3550_mode "Mode" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:mode" } +Number iCU_3550_wpn "Weekly Program" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:weeklyProgram" } +Number iCU_3550_spn "Scenario Program" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:scenarioProgram" } +String iCU_3550_func "Function" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:function" } +Switch iCU_3550_at1off "At least one probe in OFF" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:atLeastOneProbeOff" } +Switch iCU_3550_at1pro "At least one probe in PROTECTION" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:atLeastOneProbeProtection" } +Switch iCU_3550_at1man "At least one probe in MANUAL" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:atLeastOneProbeManual" } +Switch iCU_3550_failure "Failure discovered" (gCentralUnit) { channel="openwebnet:bus_thermo_cu:mybridge:CU_3550:failureDiscovered" } Group gLivingRoomZone "Living Room Zone" { ga="Thermostat" [ modes="auto=GENERIC,heat=HEATING,cool=COOLING", thermostatTemperatureRange="7,35", useFahrenheit=false ] } Number:Temperature iLR_zone_temp "Temperature [%.1f %unit%]" (gLivingRoomZone) { channel="openwebnet:bus_thermo_zone:mybridge:LR_zone:temperature", ga="thermostatTemperatureAmbient" } diff --git a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/OpenWebNetBindingConstants.java b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/OpenWebNetBindingConstants.java index 806a2c404ff51..b5a436cd9e3ab 100644 --- a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/OpenWebNetBindingConstants.java +++ b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/OpenWebNetBindingConstants.java @@ -133,6 +133,10 @@ public class OpenWebNetBindingConstants { public static final String CHANNEL_CU_BATTERY_STATUS = "batteryStatus"; public static final String CHANNEL_CU_WEEKLY_PROGRAM_NUMBER = "weeklyProgram"; public static final String CHANNEL_CU_SCENARIO_PROGRAM_NUMBER = "scenarioProgram"; + public static final String CHANNEL_CU_FAILURE_DISCOVERED = "failureDiscovered"; + public static final String CHANNEL_CU_AT_LEAST_ONE_PROBE_OFF = "atLeastOneProbeOff"; + public static final String CHANNEL_CU_AT_LEAST_ONE_PROBE_PROTECTION = "atLeastOneProbeProtection"; + public static final String CHANNEL_CU_AT_LEAST_ONE_PROBE_MANUAL = "atLeastOneProbeManual"; // energy management public static final String CHANNEL_POWER = "power"; 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 f9af4e14a3986..c839a98f152e5 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 @@ -14,7 +14,11 @@ import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_ACTUATORS; import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_CONDITIONING_VALVES; +import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_CU_AT_LEAST_ONE_PROBE_MANUAL; +import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_CU_AT_LEAST_ONE_PROBE_OFF; +import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_CU_AT_LEAST_ONE_PROBE_PROTECTION; import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_CU_BATTERY_STATUS; +import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_CU_FAILURE_DISCOVERED; import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_CU_REMOTE_CONTROL; import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_CU_SCENARIO_PROGRAM_NUMBER; import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_CU_WEEKLY_PROGRAM_NUMBER; @@ -26,11 +30,13 @@ import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_TEMPERATURE; import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.CHANNEL_TEMP_SETPOINT; +import java.util.HashSet; import java.util.Set; import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants; import org.openhab.core.library.types.DecimalType; +import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.StringType; import org.openhab.core.library.unit.SIUnits; @@ -79,6 +85,10 @@ public class OpenWebNetThermoregulationHandler extends OpenWebNetThingHandler { private String programNumber = ""; + private static Set probesInProtection = new HashSet(); + private static Set probesInOFF = new HashSet(); + private static Set probesInManual = new HashSet(); + private static final String CU_REMOTE_CONTROL_ENABLED = "ENABLED"; private static final String CU_REMOTE_CONTROL_DISABLED = "DISABLED"; private static final String CU_BATTERY_OK = "OK"; @@ -284,22 +294,25 @@ protected void handleMessage(BaseOpenMessage msg) { // it's OK and then change to KO if according message is received updateCUBatteryStatus(CU_BATTERY_OK); + // same in case of Failure Discovered + updateCUFailureDiscovered(OnOffType.OFF); + if (msg.getWhat() == Thermoregulation.WhatThermo.REMOTE_CONTROL_DISABLED) { updateCURemoteControlStatus(CU_REMOTE_CONTROL_DISABLED); } else if (msg.getWhat() == Thermoregulation.WhatThermo.REMOTE_CONTROL_ENABLED) { updateCURemoteControlStatus(CU_REMOTE_CONTROL_ENABLED); } else if (msg.getWhat() == Thermoregulation.WhatThermo.BATTERY_KO) { updateCUBatteryStatus(CU_BATTERY_KO); - } // must intercept all possibile WHATs (will be implemented soon) - else if (msg.getWhat() == Thermoregulation.WhatThermo.AT_LEAST_ONE_PROBE_OFF) { - logger.debug("handleMessage() Ignoring unsupported WHAT {}. Frame={}", msg.getWhat(), msg); + } else if (msg.getWhat() == Thermoregulation.WhatThermo.AT_LEAST_ONE_PROBE_OFF) { + updateCUAtLeastOneProbeOff(OnOffType.ON); } else if (msg.getWhat() == Thermoregulation.WhatThermo.AT_LEAST_ONE_PROBE_ANTIFREEZE) { - logger.debug("handleMessage() Ignoring unsupported WHAT {}. Frame={}", msg.getWhat(), msg); + updateCUAtLeastOneProbeProtection(OnOffType.ON); } else if (msg.getWhat() == Thermoregulation.WhatThermo.AT_LEAST_ONE_PROBE_MANUAL) { - logger.debug("handleMessage() Ignoring unsupported WHAT {}. Frame={}", msg.getWhat(), msg); + updateCUAtLeastOneProbeManual(OnOffType.ON); } else if (msg.getWhat() == Thermoregulation.WhatThermo.FAILURE_DISCOVERED) { - logger.debug("handleMessage() Ignoring unsupported WHAT {}. Frame={}", msg.getWhat(), msg); - } else if (msg.getWhat() == Thermoregulation.WhatThermo.RELEASE_SENSOR_LOCAL_ADJUST) { + updateCUFailureDiscovered(OnOffType.ON); + } // must intercept all possibile WHATs (will be implemented soon) + else if (msg.getWhat() == Thermoregulation.WhatThermo.RELEASE_SENSOR_LOCAL_ADJUST) { logger.debug("handleMessage() Ignoring unsupported WHAT {}. Frame={}", msg.getWhat(), msg); } else { // check and eventually parse mode and function @@ -355,6 +368,39 @@ private void updateModeAndFunction(Thermoregulation tmsg) { Thermoregulation.OperationMode mode = w.getMode(); Thermoregulation.Function function = w.getFunction(); + // keep track of thermostats (zones) status + if (!isCentralUnit && (!((WhereThermo) deviceWhere).isProbe())) { + if (mode == Thermoregulation.OperationMode.OFF) { + probesInManual.remove(tmsg.getWhere().value()); + probesInProtection.remove(tmsg.getWhere().value()); + if (probesInOFF.add(tmsg.getWhere().value())) { + logger.debug("atLeastOneProbeInOFF: added WHERE ---> {}", tmsg.getWhere()); + } + } else if (mode == Thermoregulation.OperationMode.PROTECTION) { + probesInManual.remove(tmsg.getWhere().value()); + probesInOFF.remove(tmsg.getWhere().value()); + if (probesInProtection.add(tmsg.getWhere().value())) { + logger.debug("atLeastOneProbeInProtection: added WHERE ---> {}", tmsg.getWhere()); + } + } else if (mode == Thermoregulation.OperationMode.MANUAL) { + probesInProtection.remove(tmsg.getWhere().value()); + probesInOFF.remove(tmsg.getWhere().value()); + if (probesInManual.add(tmsg.getWhere().value())) { + logger.debug("atLeastOneProbeInManual: added WHERE ---> {}", tmsg.getWhere()); + } + } + + if (probesInOFF.isEmpty()) { + updateCUAtLeastOneProbeOff(OnOffType.OFF); + } + if (probesInProtection.isEmpty()) { + updateCUAtLeastOneProbeProtection(OnOffType.OFF); + } + if (probesInManual.isEmpty()) { + updateCUAtLeastOneProbeManual(OnOffType.OFF); + } + } + updateState(CHANNEL_FUNCTION, new StringType(function.toString())); updateState(CHANNEL_MODE, new StringType(mode.toString())); @@ -438,7 +484,33 @@ private void updateCURemoteControlStatus(String status) { private void updateCUBatteryStatus(String status) { updateState(CHANNEL_CU_BATTERY_STATUS, new StringType(status)); - logger.debug("updateCUBatteryStatus(): {}", status); + + if (status == CU_BATTERY_KO) { // do not log default value (which is automatically setted) + logger.debug("updateCUBatteryStatus(): {}", status); + } + } + + private void updateCUFailureDiscovered(OnOffType status) { + updateState(CHANNEL_CU_FAILURE_DISCOVERED, status); + + if (status == OnOffType.ON) { // do not log default value (which is automatically setted) + logger.debug("updateCUFailureDiscovered(): {}", status); + } + } + + private void updateCUAtLeastOneProbeOff(OnOffType status) { + updateState(CHANNEL_CU_AT_LEAST_ONE_PROBE_OFF, status); + logger.debug("updateCUAtLeastOneProbeOff(): {}", status); + } + + private void updateCUAtLeastOneProbeProtection(OnOffType status) { + updateState(CHANNEL_CU_AT_LEAST_ONE_PROBE_PROTECTION, status); + logger.debug("updateCUAtLeastOneProbeProtection(): {}", status); + } + + private void updateCUAtLeastOneProbeManual(OnOffType status) { + updateState(CHANNEL_CU_AT_LEAST_ONE_PROBE_MANUAL, status); + logger.debug("updateCUAtLeastOneProbeManual(): {}", status); } private Boolean channelExists(String channelID) { 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 e893e628470f7..792bb64bacec3 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 @@ -18,6 +18,10 @@ + + + + diff --git a/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/channels.xml index fafa4086ed2b1..c8b91b615cfc0 100644 --- a/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/channels.xml @@ -281,6 +281,34 @@ + + Switch + + Central Unit Failure Discovered (read only) + + + + + Switch + + At least one probe OFF indicator in Central Unit (read only) + + + + + Switch + + At least one probe in PROTECTION (Anti Freeze/Thermal Protection) indicator in Central Unit (read only) + + + + + Switch + + At least one probe in MANUAL indicator in Central Unit (read only) + + + Number:Power