How long until a Thing remains Offline forever?

Hello,
what is the behaviour of a thing going permanently offline?
What I am trying to solve is, if a binding has a weak connection to his physical device, like a weak wifi signal, how often is the scheduler trying to reconnect to the thing before it remains offline forever?
I see that my binding goes sometimes offline after several days, assuming network issue. If I then just disable and enable it again it comes online again.
How do I increase the reconnection timeout?

My code is at the moment like this:

private void startAutomaticRefresh() {
        ScheduledFuture<?> job = refreshJob;
        if (job == null || job.isCancelled()) {
            int period = config.refreshRate;
            refreshJob = scheduler.scheduleWithFixedDelay(this::run, 0, period, TimeUnit.SECONDS);
        }
    }

    private void run() {
        if (updateOvenData(null)) {
            for (Channel channel : getThing().getChannels()) {
                updateChannel(channel.getUID().getId());
            }
        }
    }

 public void dispose() {
        stopScheduler();
        linkedChannels.clear();
        automaticRefreshing = false;
    }

    private void stopScheduler() {
        ScheduledFuture<?> job = refreshJob;
        if (job == null || job.isCancelled()) {
            refreshJob = scheduler.scheduleWithFixedDelay(this::refreshChannels, 0, config.refreshRate,
                    TimeUnit.SECONDS);
        }
    }

    private void refreshChannels() {
        if (updateOvenData(null)) {
            for (Channel channel : getThing().getChannels()) {
                updateChannel(channel.getUID().getId());
            }
        }
    }

You could also use a rule and the API to disable and enable Item after some offline time for a reconnect. But thats a dirty hack. Better would be to get a more stable wifi connection…

Yes I know that I could that, however I am interested what is the standard behaviour of the OH Framework to set things permanently offline?

Which kind of thing via which binding?

In this case more information is needed, as there are a lot of bindings could have different behavior

This is going to be handled and controlled on a binding by binding basis. The amount of time to wait and what conditions indicate a service is offline is going to suffer from one technology to the next so it doesn’t make sense for OH to define and enforce a standard.

For example, MQTT with a LWT and QOS 2 might time out in a second whereas a battery powered Zwave device may take weeks if it ever times out.

But OH does not have a concept of “permanently offline” . Either it’s offline or it’s not and if it’s offline that’s no indication that it will never become online later.

1 Like

When the Thing goes offline I set it with:

updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, error);

However, when I am able to see the connection again I was trying to set it back online like this:

updateStatus(ThingStatus.UNKNOWN);
updateStatus(ThingStatus.ONLINE);

The problem is, that in the OH UI it does not come online anymore. It remains Offline. Only if I disable and enable it again it works again.
What do I do wrong here?

Thanks, thats what I thought as well. But why is then the thing not going online again if I put it online with:

updateStatus(ThingStatus.ONLINE);

in the log it states that the Thing is back online. However I cant see it in the UI then.

I don’t do binding development so I can’t say. I usually see Things cycle through INITIALIZING before it goes online for a lot of bindings. Maybe you can’t jump straight to ONLINE?

1 Like

Thx. You go normaly to Unknown and then Online. Initializing is forbidden to call. It will be called by the UI by first initializing.
I will figure it out.

Just had a look in other code. In your code I don’t see where the Thing is set to offline nor to online.

Here like done in other bindings with a clear logic: Success means online, otherwise offline.

 try {
        if (command instanceof RefreshType) {
            refreshChannels(channelUID);
        } else {
            sendCommand(channelUID, command);
        }
        updateStatus(ThingStatus.ONLINE);
    } catch (RobonectCommunicationException rce) {
        logger.debug("Failed to communicate. Taking it offline.", rce);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, rce.getMessage());
    }
}
1 Like

It looked like a caching issue or build issue coming from the actual problems of OH5.0 mentioned here .
It works now as expected. My code was indeed correct. Thanks for helping.