The error is missing after a reboot, but the switch not working.
rule "MicroPc on/off"
when
Item PCONOFF received command
then
switch (receivedCommand){
case 1: {
mpcon.sendCommand(ON)
logInfo("check.rules", "switch case 1 triggered")
}
case 2: {
mpcoff.sendCommand(ON)
logInfo("check.rules", "switch case 2 triggered")
}
}
logInfo("check.rules", "finished rule")
end
what is in events.log if you switch mpcon and mpcoff via sitemap? the command sent then must be the same then sent via the rule.
events.log
2017-04-08 12:23:23.100 [ItemCommandEvent ] - Item ‘PCONOFF’ received command 2
2017-04-08 12:23:23.111 [ItemStateChangedEvent ] - PCONOFF changed from 1 to 2
2017-04-08 12:23:30.261 [ItemCommandEvent ] - Item ‘PCONOFF’ received command 1
2017-04-08 12:23:30.273 [ItemStateChangedEvent ] - PCONOFF changed from 2 to 1
openhab.log
nothing
odd. Designer should have spotted “item” instead of “Item”. try:
when
Item PCONOFF received command
then
with a capital I in “Item”…
It works!!!
Thank you very much!
Here is the full working code:
sitemap:
Switch item=MPCONOFF mappings=[1="ON",2="OFF"]
items:
Switch mpcon "MicroPc on" { wol="192.168.0.255#D0:50:99:35:6E:BB" }
Switch mpcoff "MicroPc off" { channel="exec:command:micropcofft:run" }
Number MPCONOFF "Micro Pc"
rules:
rule "MicroPc onoff"
when Item MPCONOFF received command
then switch (receivedCommand)
{
case 1: { mpcon.sendCommand(ON) }
case 2: { mpcoff.sendCommand(ON) }
}
end
things:
Thing exec:command:micropcofft [command="net rpc shutdown -I 192.168.0.2 -U user%%pass -f", interval=0, autorun=false]
Hi, got the some requirement for my Kodi Media Center. I resolved it with following
items :
String wz_Kodi_systemcommand "Systemcommand" { channel="kodi:kodi:bb8285a3-8aac-bcdd-9fe4-a16af591dbc8:systemcommand" }
Switch Fernseher_Wohnzimmer "Fernseher Wohnzimmer" (Status, Network) [ "Switchable" ] { wol="192.168.1.255#XX:XX:XX:XX:XX:XX", nh="192.168.1.xxx:8080" }
rules :
when
Item Fernseher_Wohnzimmer changed
then
if (Fernseher_Wohnzimmer.state == OFF) {
wz_Kodi_systemcommand.sendCommand("Shutdown")
}
end
Hello SzilagyiR,
I’m trying to use your approach. OpenHAB is sitting on the RPi 192.168.0.4 and I’m trying to ON/OFF computer 192.168.0.2
I did install exec binding and wol binding.
Copy and past your code to correct files.
I did change user%%pass to my windows 10 login and password.
Thing is pointing to 192.168.0.2 and wol="192.168.0.2#MAC of the computer.
Is it correct approach?
Hi!
Yes it is seems to be correct! In user%%pass you must keep double % between the user and the pass!
Hello, I tried it the same way as you did
added
Switch item=MPCONOFF mappings=[1="ON",2="OFF"]
to my sitemap
added this items in my .items file
Switch mpcon "MicroPc on" { wol="192.168.1.255#D4:BE:D9:A4:38:90" }
Switch mpcoff "MicroPc off" { channel="exec:command:micropcofft:run" }
Number MPCONOFF "Micro Pc"
created a .rules file with this:
rule “MicroPc onoff”
when Item MPCONOFF received command
then switch (receivedCommand)
{
case 1: { mpcon.sendCommand(ON) }
case 2: { mpcoff.sendCommand(OFF) }
}
end
and created an things file with this content:
Thing exec:command:micropcofft [command="net rpc shutdown -I 192.168.1.255 -U user%%pass -f", interval=0, autorun=false]
ofcourse i changed user and pass with my windows login details
Now the WOL is working fine but nothing happens when I try to use the OFF button.
Any suggestions on how I could fix this problem ?
Your rule is sending ON in both cases…
Thank you for your input Hans!
I tried to change it to OFF for the second case but it is still not working.
Wake on Lan is working perfectly, but shutdown is not, any suggestions, on what I could try next ?
try if your command is working by entering it in the shell
I just checked the logs in openhab2 and it shows me this
2017-12-16 18:57:06.868 [WARN ] [ome.core.thing.internal.ThingManager] - Cannot delegate update ‘OFF’ for item ‘mpcoff’ to handler for channel ‘exec:command:micropcofft:run’, because no thing with the UID ‘exec:command:micropcofft’ could be found.
What does this exactly mean? (Never coded before so I am not sure what to do now)
check PaperUI for your mpcofft Thing, does it exist ? Is it online?
The thing is not there… But there should be, right?
I mean I have a it in my .things file in /etc/openhab2/things folder (I am using openhabian)
Thing exec:command:micropcofft [command="net rpc shutdown -I 192.168.1.255 -U user%%pass -f", interval=0, autorun=false]
Any idea why it is not shwoing up in PaperUI ?
You should find it under config -> things in PaperUI
Are you sure You have Exec2.0 Binding installed?
Oh wow, thank you so much!
I was so sure I have installed it already but that must have been, before I resetted everything to have a clean install. Forgot to install it again.
I could have searched for days for the error. Thanks a lot!
kind regards,
salexes
I know I asked you already alot today but I would like to ask one more thing.
After Installing the exec binding again I also installed the regex binding in order for the exec command to work.
While doing so i received an error: Failed installing 'openhab-transformation-regex': Error restarting bundles
Could you maybe take a look, maybe you already know this kind of error and know an quick solution to it.
I think because of the error described above the shutdown command is still not working
Thanks it advance.
kind regards
Tried that, did not change anything. Sadly I am unable to install any transformation bindings. So that means I can not use the exec solution (Wol & exec binding -> power On and Off Pc), correct ?
What other options do I have? Or what else can I try to get it working?