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.