Openhab2 exec bindig shotdown

Thanks for this inspiration, I adopted this to control my WIndows 10 PC, with Melissa’s idea for ON/OFF.

But I fould that something lacked, when power on or off PC by hand, Openhab did not update the status of it.

So to make it complete, I added a Switch checking presence of PC via Pingdevice, and a rule to check if the status changed “outside” of OH2. So the solution looks like this:

Thing:

Thing exec:command:holgerpcoff [command="net rpc shutdown -f -I 192.168.75.112 -U HOSTNAME/USER%%PASSWORD", interval=0, autorun=false]

Items:

Switch 			Presence_Holger_PC			"Holger PC" 				<network> 	{channel="network:pingdevice:192_168_75_112:online" }
Switch			Holger_PC_ON_OFF			"Holger PC"					<network>   ["Switchable"]
Switch 			Holger_PC_ON 				"Holger PC ON" 							{ wol="192.168.75.255#08:62:66:29:5A:F2" }
Switch 			Holger_PC_OFF 				"Holger PC OFF" 						{ channel="exec:command:holgerpcoff:run" }

Rules:

rule "Holger PC onoff"

when Item Holger_PC_ON_OFF received command
then switch (receivedCommand)
	{
	case ON: { Holger_PC_ON.sendCommand(ON) }
    case OFF: { Holger_PC_OFF.sendCommand(ON) }
	}
end

rule "Holger PC State"

when Item Presence_Holger_PC changed

then 
	
	if (Holger_PC_ON_OFF.state != Presence_Holger_PC.state) 
	 Holger_PC_ON_OFF.postUpdate(Presence_Holger_PC.state)
	end

Sitemap:

Switch item=Holger_PC_ON_OFF label="Holger PC"

With this solution, you can Power on/Shutdown PC with OH2, plus it shows correct state if you started it or shut down manually.

1 Like

Hi!

I tried your code, but the state not working.

Can you help me, what is wrong with my code?

Items:

Switch Presence_Micro_PC “MicroPc2” {channel=“network:pingdevice:192_168_0_xxx:online” }
Switch Micro_PC_ON_OFF “MicroPc2” [“Switchable”]
Switch Micro_PC_ON “MicroPc2 ON” { wol=“192.168.0.255#xx:xx:xx:xx:xx:xx” }
Switch Micro_PC_OFF “MicroPc2 OFF” { channel=“exec:command:micropcoff2:run” }

Rules:

rule "MicroPc on/off"

when Item Micro_PC_ON_OFF received command

then switch (receivedCommand)

{

case ON: { Micro_PC_ON.sendCommand(ON) }

case OFF: { Micro_PC_OFF.sendCommand(ON) }

}

end

rule "MicroPC State"

when Item Presence_Micro_PC changed

then

if (Micro_PC_ON_OFF.state != Presence_Micro_PC.state)

 Micro_PC_ON_OFF.postUpdate(Presence_Micro_PC.state)

end

Hi!

I found the error in items:
Switch Presence_Micro_PC “MicroPc2” {channel=“network:pingdevice:192_168_0_xxx:online” }

The working code is:
Switch Presence_Micro_PC “MicroPc2” {channel=“network:device:192_168_0_xxx:online” }

Thanks for working solution, I got this up and running, one thing you mist is Thing configuration of your 192_168_75_112…