diff --git a/bundles/org.openhab.binding.remoteopenhab/README.md b/bundles/org.openhab.binding.remoteopenhab/README.md
index 977f2daf0..07bef25df 100644
--- a/bundles/org.openhab.binding.remoteopenhab/README.md
+++ b/bundles/org.openhab.binding.remoteopenhab/README.md
@@ -36,14 +36,16 @@ The binding has no configuration options, all configuration is done at Thing lev
The `server` thing has the following configuration parameters:
-| Parameter | Required | Description |
-|--------------------|----------|-----------------------------------------------------------------------------------------------------------|
-| host | yes | The host name or IP address of the remote openHAB server. |
-| useHttps | no | Set to true if you want to use HTTPS to communicate with the remote openHAB server. Default is false. |
-| port | yes | The HTTP port to use to communicate with the remote openHAB server. Default is 8080. |
-| trustedCertificate | no | Set to true if you want to use HTTPS even without a valid SSL certificate provided by your remote server. |
-| restPath | yes | The subpath of the REST API on the remote openHAB server. Default is /rest |
-| token | no | The token to use when the remote openHAB server is setup to require authorization to run its REST API. |
+| Parameter | Required | Description |
+|-----------------------|----------|-----------------------------------------------------------------------------------------------------------|
+| host | yes | The host name or IP address of the remote openHAB server. |
+| useHttps | no | Set to true if you want to use HTTPS to communicate with the remote openHAB server. Default is false. |
+| port | yes | The HTTP port to use to communicate with the remote openHAB server. Default is 8080. |
+| trustedCertificate | no | Set to true if you want to use HTTPS even without a valid SSL certificate provided by your remote server. |
+| restPath | yes | The subpath of the REST API on the remote openHAB server. Default is /rest |
+| token | no | The token to use when the remote openHAB server is setup to require authorization to run its REST API. |
+| accessibilityInterval | no | Minutes between checking the remote server accessibility. 0 to disable the check. Default is 3. |
+| aliveInterval | no | Number of last minutes to take into account to determine whether the remote server is alive. 0 to disable this feature. Default is 5. |
The `thing` thing has the following configuration parameters:
diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabServerConfiguration.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabServerConfiguration.java
index cbb0c8242..edfefdd7a 100644
--- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabServerConfiguration.java
+++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/config/RemoteopenhabServerConfiguration.java
@@ -33,4 +33,6 @@ public class RemoteopenhabServerConfiguration {
public boolean trustedCertificate = false;
public String restPath = "/rest";
public String token = "";
+ public int accessibilityInterval = 3;
+ public int aliveInterval = 5;
}
diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabBridgeHandler.java b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabBridgeHandler.java
index bc3a199df..06040dfaf 100644
--- a/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabBridgeHandler.java
+++ b/bundles/org.openhab.binding.remoteopenhab/src/main/java/org/openhab/binding/remoteopenhab/internal/handler/RemoteopenhabBridgeHandler.java
@@ -98,7 +98,6 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
private static final String DATE_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
private static final DateTimeFormatter FORMATTER_DATE = DateTimeFormatter.ofPattern(DATE_FORMAT_PATTERN);
- private static final long CONNECTION_TIMEOUT_MILLIS = TimeUnit.MILLISECONDS.convert(5, TimeUnit.MINUTES);
private static final int MAX_STATE_SIZE_FOR_LOGGING = 50;
private final Logger logger = LoggerFactory.getLogger(RemoteopenhabBridgeHandler.class);
@@ -177,7 +176,10 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
updateStatus(ThingStatus.UNKNOWN);
- startCheckConnectionJob();
+ scheduler.submit(this::checkConnection);
+ if (config.accessibilityInterval > 0) {
+ startCheckConnectionJob(config.accessibilityInterval, config.aliveInterval);
+ }
}
@Override
@@ -354,19 +356,25 @@ public class RemoteopenhabBridgeHandler extends BaseBridgeHandler
}
}
- private void startCheckConnectionJob() {
+ private void startCheckConnectionJob(int accessibilityInterval, int aliveInterval) {
ScheduledFuture> localCheckConnectionJob = checkConnectionJob;
if (localCheckConnectionJob == null || localCheckConnectionJob.isCancelled()) {
checkConnectionJob = scheduler.scheduleWithFixedDelay(() -> {
long millisSinceLastEvent = System.currentTimeMillis() - restClient.getLastEventTimestamp();
- if (millisSinceLastEvent > CONNECTION_TIMEOUT_MILLIS) {
- logger.debug("Check: Maybe disconnected from streaming events, millisSinceLastEvent={}",
+ if (aliveInterval == 0 || restClient.getLastEventTimestamp() == 0) {
+ logger.debug("Time to check server accessibility");
+ checkConnection();
+ } else if (millisSinceLastEvent > (aliveInterval * 60000)) {
+ logger.debug(
+ "Time to check server accessibility (maybe disconnected from streaming events, millisSinceLastEvent={})",
millisSinceLastEvent);
checkConnection();
} else {
- logger.debug("Check: Receiving streaming events, millisSinceLastEvent={}", millisSinceLastEvent);
+ logger.debug(
+ "Bypass server accessibility check (receiving streaming events, millisSinceLastEvent={})",
+ millisSinceLastEvent);
}
- }, 0, CONNECTION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
+ }, accessibilityInterval, accessibilityInterval, TimeUnit.MINUTES);
}
}
diff --git a/bundles/org.openhab.binding.remoteopenhab/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.remoteopenhab/src/main/resources/OH-INF/thing/thing-types.xml
index 762bba8de..f992004b8 100644
--- a/bundles/org.openhab.binding.remoteopenhab/src/main/resources/OH-INF/thing/thing-types.xml
+++ b/bundles/org.openhab.binding.remoteopenhab/src/main/resources/OH-INF/thing/thing-types.xml
@@ -53,6 +53,21 @@
The token to use when the remote openHAB server is setup to require authorization to run its REST API.true
+
+
+
+ Minutes between checking the remote server accessibility. 0 to disable the check. Default is 3.
+ 3
+ true
+
+
+
+
+ Number of last minutes to take into account to determine whether the remote server is alive. 0 to
+ disable this feature. Default is 5.
+ 5
+ true
+