For anyone who is reading this thread and got the same problem. I found a solution with a rule workaround.
I also optimized my whole HABPanel experience. I want to share this with you.
Inside the HABPanel the Switch shows me if the computer is on, off, shutting down or starting.
Required:
- Wake-on-LAN Binding
- Network Binding
First you need to configure a pingable-device.thing using Network binding.
.things
network:pingdevice:192_168_XXX_XXX "Computer" [ hostname="192.168.XXX.XXX", refreshInterval=6000 ]
Now you need three items. One items needs to store the status of you computer. e.g. on, off, starting, shutting down. And the other item needs to be a Wake on LAN Switch. And the last item stores the real on/off state, using Network Binding.
.items
String Computer_Status "Computer Status"
Switch Computer_WOL "Computer Wake on LAN" { wol="<broadcastIP>#<MAC-ADDRESS>" }
Switch Computer_Online "Computer Online" { channel="network:pingdevice:192_168_XXX_XXX:online" }
Now you need a rule, which:
- remotely shutdown your computer
- abort shutdowns, if you want to
- starts the computer, if its turned off
- saves the status of the computer into “Computer_Status”
.rules
rule "Shutdown Computer"
when Item Computer_Status received command OFF
then if (Computer_Online.state == ON) {
executeCommandLine('net rpc shutdown -f -I 192.168.XXX.XXX -U USER%PASSWORD -t 30')
Computer_Status.postUpdate("SHUTDOWN")
}
end
rule "Abort/Start Computer"
when Item Computer_Status received command ON
then executeCommandLine("net rpc abortshutdown -f -I 192.168.XXX.XXX -U USER%PASSWORD")
if (Computer_Online.state == OFF) {
Computer_Status.postUpdate("STARTING")
Computer_WOL.sendCommand(ON)
}
end
rule "Computer on"
when Item Computer_Online changed from OFF to ON
then Computer_Status.postUpdate("ON")
end
rule "Computer off"
when Item Computer_Online changed from ON to OFF
then Computer_Status.postUpdate("OFF")
end
You can add this easily to your .sitemaps, if you want to
.sitemaps
Switch item=Computer_Status label="Computer [%s]" icon=computer
In HABPanel you need to add a button.
Name: Computer
Action: Switch between two states
openHAB item: Computer_Status
command value: ON
alternative: OFF
userdefined symbol: computer
Then you need to use a own symbol, to display all states. I added some for you.
You need to rename these icons to:
- computer-off.svg
- computer-on.svg
- computer-shutdown.svg
- computer-starting.svg
and then store them easily in: /etc/openhab2/icons/classic if youre running openhab on a raspberry pi
Now have fun with your working Start/Shutdown Button in HABPanel.