I want to fire an event (logError(), playSound()) when my system goes online and offline. The problem is that there are many false alarms: the system detects offline state, when there is in fact no offline state (internet is working fine). This implies false announcements, not only when the system goes offline, but as result also when it goes online (even if it was online all the time). But when there is a real offline state, then the logic is correct: there is a trigger for going offline, and a trigger for going online.
In particular, when I do apt-get update the system load increases, and this can results false alarm with higher probability. openhab.log contains:
2026-07-09 19:07:09.197 [WARN ] [.network.internal.utils.NetworkUtils] - Timed out while waiting for the ping process to execute
2026-07-09 19:07:59.278 [WARN ] [.network.internal.utils.NetworkUtils] - Timed out while waiting for the ping process to execute
2026-07-09 19:07:59.295 [ERROR] [org.openhab.core.model.script.rele1 ] - internet item changed OFF
2026-07-09 19:08:49.304 [ERROR] [org.openhab.core.model.script.rele1 ] - internet item changed ON
I am using openHAB 5.2.0.
- What should I change, so that the events are triggered reliably: the internet/ping item in openHAB goes offline, when there is indeed no internet connection.
Moreover this does not have to happen instantly, as apparently it cannot be instant: one minute delay for going online and offline is OK.
I have a Thing, where 1.2.3.4 is the IP address of my internet provider, as reported by tcptrace:
Thing network:pingdevice:internet "Internet" [hostname="1.2.3.4", refreshInterval=50000, retry=4, timeout=7, useArpPing="false", useIOSWakeUp="false"]
two items
Switch internet "Internet [MAP(internet.map):%s]" <network> [Status, OpenState] {channel="network:pingdevice:internet:online"}
DateTime internet_last_change "No Internet since [%1$tY-%1$tm-%1$td %tRh]" <none>
and a rule
val play = [String s|
playSound("webaudio", s + '.mp3')
playSound("enhancedjavasound", s + '.mp3')
executeCommandLine('/usr/local/bin/announce', s + '.mp3') // this is the same as the next line
// /usr/bin/ffmpeg -re -i /etc/openhab/sounds/$1 -filter_complex 'aresample=8000,asetnsamples=n=160' -acodec pcm_mulaw -ac 1 -f rtp udp://239.239.239.239:4444
]
rule "Internet"
when
Item internet changed
then
internet_last_change.postUpdate(new DateTimeType)
if (previousState == NULL) return;
logError('rele1', 'internet item changed ' + internet.state)
play.apply(switch newState {
case OFF: "internet-off"
case ON: "internet-on"
})
end