Network Binding Force Ping Rule possible?

Hello,

can I somehow force a ping from a rule with the Openhab network binding?

I would like to bring this topic up again as I am currently looking for this feature for my alarm system.
What I want is an action to use in rules that force a ping to be performed. What I am wanting to do is forcing a ping to my phone as soon as there is a motion detected inside so that the system knows whether that was me or not , ideally before any alarm is being triggered.

Does anyone have a suggestion as to how to trigger a manual ping from a rule and get a ONLINE or OFFLINE status back?

I do not know how to do that using the Network Binding.
You did not write which OS you OH installation is based on.
Assumed it is a linux derivate or windows you should be able to e.g. use the ping command ( as long as you have a fixed IP address for your phone resp. the naming resolution always works ).
From within the execute binding or executeComandLine you can run a shell/bat/powershell script that uses ping, arping, nmap or whatever command.
Assumed it would be enough to use a ping command you can evalute the return value and act according to it.
Assumed you use DHCP listen in your network binding installation I would assume that as soon as your phone is reachable by your WIFI it should be ONLINE already and an additional forced ping would not be required.

1 Like

There is apparently an Action that isn’t covered in the docs at all:

https://www.openhab.org/javadoc/latest/org/openhab/core/model/script/actions/ping

I’ve never used it and only came upon it by chance one day while looking for something else. But it should work for this.

Hello, thank you both for your help! I would probably never have thought of that. And also such a simple solution, I am speechless xd
I’m attaching the code of one of my rules in case anyone else is looking for it.

import java.time.format.DateTimeFormatter;
import org.openhab.core.model.script.actions.Ping;

rule "Alarm_Eingang"
when
   Item eingang_alarm changed from CLOSED to OPEN
then
if(alarmanlage.state != OFF && presence.state != ON){


if(!Ping.checkVitality("192.168.1.8", 0, 1000)){

   val telegramAction = getActions("telegram","telegram:telegramBot:Telegram_Bot")
   telegramAction.sendTelegram("\uD83D\uDEA8\tEingang Alarm!\t\uD83D\uDEA8"+"\n\n"+"Am:\t"+now.toLocalDateTime.format(DateTimeFormatter.ofPattern("dd/MM/yyyy '\tum:\t' HH:mm:ss '\tUhr'")))

}
}
end

3 Likes