Check if device is alive

Hi,
I started shortly with openhab and came to some problems. One of them is how to detect if device is alive? I use the denon and lg TV binding at them moment. How do I handle it if the devices have no power? So they are of, but how do I show that best in the app? And how to use it in the rules? For example I want to shut off the denon if the is is powered off?
Can is disabl the denon switches and inputs for example if the device is not alive? I have no power on TV and denon if I do not use them so openhab is not able to see them.

Sorry for that noon questions but I still get an overview and understanding how to work with that stuff. :wink:

From looking at the Deno and LG bindingā€™s wiki pages I see that they both have an IP address. So you can use the Network Health binding to detect whether or not the device is alive or not. This of course assumes that the TVs are off the network when they are powered off. If that assumption is false Iā€™ve no recommendations.

I use this approach to detect whether my Raspberry Pis are alive.

For example:

Switch N_C_GarageRaspi "Garage Door Server" <network> { nh="123.456.7.890" }
Switch N_C_SensorRaspi "Sensor Server" <network> { nh="098.7.654.321" }

I also see that the LG binding has a CONNECTION_STATUS which probably does the same thing.

When the Network Health binding detects these IP addresses are offline the switch will be OFF, otherwise it will be ON. If you put these switches on your sitemap like any other switch it will show whether the device is online or not. In fact, if you use the visibility attribute in your sitemap, you can have it only show up in your sitemap when it is offline (or online).

For example:

Text item=N_C_GarageRaspi label="Garage Door Controller Is Not Online!" visibility=[N_C_GarageRaspi!="ON"]

You can do something similar for all of your controls so they only appear when the Denon or LG online switches are ON.

Now that the status of the devices is in a switch you can use them in your rules like any other switch. For example, to turn off the LG when the Denon is off you would use a rule like:

rule "LG Off"
when
    LG_Online received command OFF
then
    Denon_Power.sendCommand(OFF)
end

To ā€œdisableā€ a rule simply put an if statement in your rule that checks the state of the Online switches.

rule "Some rule"
when
    Some_Command received command
then
    if(LG_Online.state == ON){ // rule only runs if LG is online
        // do stuff
    }
end

Rich

2 Likes

Sorry for the bump, but this was the top search result for ā€œchecking whether a device is onlineā€. Whether a device is ā€œonlineā€ can mean different things, but this will check whether a device has an active connection to OpenHAB:

if (getThingStatusInfo("thingUID").toString == "ONLINE") {
    // ONLINE
}
else {
  // OFFLINE
}
1 Like