Combine Computer Power On (WOL), Monitoring (Ping) and Power Off (Exec)

  • Platform information:
    • Hardware: Raspberry Pi 3
    • OS: Openhabian
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: 2.5.4
  • Issue of the topic:

Hi, I’ve got 3 individual switch items configured. One that can turn a computer on via Wake-On LAN, one that can check if the computer is online via ping, and a third that can turn the computer off via an SSH exec (the target computer is running linux)

  • Please post configurations (if applicable):
Thing network:pingdevice:synology "Synology" @ "Lounge Room" [ hostname="" ]
Thing exec:command:synology [command="ssh stoz@ sudo shutdown -h now"]
Switch Synology_test "Test"   (Status, Network)   { wol="", channel="network:pingdevice:synology:online" }
Switch Synology_test2 "Test2"   (Status, Network)   { channel="network:pingdevice:synology:online" }
Switch Synology_testoff "Test3" (Status, Network) {channel="exec:command:synology:run"}
sitemap default label= "House"
    Switch item=Synology_test label= "Test"
    Switch item=Synology_test2 label= "Test2"
    Switch item=Synology_testoff label= "Test Off"

They all seem to work (and the first Wake On-LAN one also seems to monitor it via ping)

The Wake-On LAN binding seems to indicate that you can combine it with an Exec command however my understanding is the Wake-On LAN binding is a legacy (v1) binding and that the method to combine them is now different.

Do I need to create some kind of virtual switch or rule or something else?

I guess I’m having trouble getting my head around the “switch” concept. Does a switch have an action for both on and off? They feel more like buttons (press and it does X) rather than switches having an on and an off currently.

Any help is appreciated!

That’s it. It is an action.
in openHAB, Item commands and states are two different, um, things.
When you poke a UI graphic it issues a command to the Item.
Bindings like WOL listen for commands, and may do stuff with them. In WOL case, it sends a wakeup for command ON and ignores any other command.
Bindings like network process incoming information and issue state updates to an Item.

Switches happen to have states and available commands with the same name.
Items like Dimmers can be different, e.g. command ON but state is always numeric like 100%.

Have a review of your events.log and it may make more sense.

This is how i do it:

dummy switch item:

Switch PCswitch "PC ON/OFF" <computeronoff>

Then rule:

rule "DATA PC On Off"
	Item  PCswitch changed
	if(PCswitch.state == ON)
	{   // Bij aan, commando DataPCON aanzetten
		sendCommand(DataPCON, ON)
		logInfo("PC", "PC On")
	{   // Bij uit, commando shutdowndata aanzetten
		sendCommand(shutdowndata, ON)
		logInfo("PC", "PC Off")

Simple and easy solution for making 1 button switch in sitemap.

Using the ping in sitemap to confirm pc is actually on.

Thanks to both of you. I’ve got it working now. I’m sure there are multiple ways to achieve this with openhab but here is what is working now for me (things config is the same as original post):

Switch Synology_on "Synology On" (Status, Network) { wol="", channel="network:pingdevice:synology:online" }
String Synology_off "Synology Off" {channel="exec:command:synology:run"}


sitemap default label="House"
    Switch item=Synology_on label="Server"
    Switch item=Study_on label="Study PC"


rule "Synology"
  Item Synology_on received command OFF

Power on, power off, and monitoring all on a single switch.

1 Like