Advertisement
Yordan1976

OpenHAB ZAP

Jan 4th, 2020
3,139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XBasic 1.57 KB | None | 0 0
  1. rule "Single ZAP Plug"
  2.   when
  3.     Member of FunksteckdosenZAP received command
  4.   then
  5.  
  6.     logInfo("Power_Plug_ZAP", "Member " + triggeringItem.name + " to " + receivedCommand)
  7.    
  8.     try {
  9.       // Lock transmitter so other executed rules dont't use it at the same time.
  10.       // Concurrent calls of the rule will wait till the resource is free again.
  11.       transmitter.lock()
  12.  
  13.       // Get the item which triggered the rule
  14.       // Split the name and get the second part, the number to set as command.
  15.       var num = (Integer.parseInt(triggeringItem.name.toString.split("PowerOutletZap_").get(1)) as Number)
  16.       num = num - 1
  17.       val codes_on = "123,234,345,456"
  18.       val codes_off = "321,432,543,654"
  19.  
  20.       // Set the command which should be executed to the output channel
  21.       // Auto trigger will then execute the Thing.
  22.       if(receivedCommand == ON){
  23.         Remote_CodeSend_Args.sendCommand(codes_on.split(",").get(num) + " 1 150")
  24.  
  25.       }else{
  26.         Remote_CodeSend_Args.sendCommand(codes_off.split(",").get(num) + " 1 150")
  27.       }
  28.  
  29.       // Wait for the command to complete
  30.       while(Remote_CodeSend.state != OFF){
  31.         Thread::sleep(200)
  32.       }
  33.  
  34.       // Mulltiple trigger do not work if there is no break here
  35.       // maybe external skript needs some time to properly free resources.
  36.       Thread::sleep(400)
  37.       logInfo("Power_Plug_ZAP", Remote_CodeSend_Out.state.toString.replaceAll("\r|\n"," ") )
  38.     }catch(Throwable t) {}
  39.     finally {
  40.         // Free the resource for the next call.
  41.         transmitter.unlock()
  42.     }
  43.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement