Advertisement
Guest User

entertainment.rules

a guest
Aug 21st, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. var int amp_power_slot=100
  2. var int radio_slot=200
  3. var int amp_select_slot=300
  4. var int tvset_slot=500
  5. var int projector_slot=700
  6. var int screen_slot=900
  7.  
  8.  
  9. rule "amplifier on"
  10. when
  11. Item amp_power received command
  12. then
  13. if (receivedCommand == ON) {
  14. createTimer(now.plusMillies(amp_power_slot), [ | amplifier.sendCommand("on") ])
  15. createTimer(now.plusMillis(radio_slot), [ | cubiepower.sendCommand(ON) ])
  16. if(amp_source.state.toString == "") {
  17. sendCommand(amp_source, "tv")
  18. }
  19. }
  20. if (receivedCommand == OFF) {
  21. createTimer(now.plusMillies(amp_power_slot), [ | amplifier.sendCommand("off") ])
  22. createTimer(now.plusMillis(radio_slot), [ | cubiepower.sendCommand(OFF) ])
  23. sendCommand(amp_source, "")
  24. sendCommand(proj_power, OFF)
  25. if(tv_power.state == ON) {
  26. sendCommand(tv_power, OFF)
  27. }
  28. }
  29. end
  30.  
  31. rule "volume changed"
  32. when
  33. Item amp_vol received command
  34. then
  35. sendCommand(amplifier, receivedCommand.toString)
  36. postUpdate(triggeringItem, "")
  37. end
  38.  
  39. rule "source changed"
  40. when
  41. Item amp_source received command
  42. then
  43. if (receivedCommand.toString != "") {
  44. if(amp_power.state != ON) {
  45. sendCommand(amp_power, ON)
  46. }
  47. createTimer(now.plusMillis(amp_select_slot), [ | amplifier.sendCommand(amp_source.state.toString) ])
  48. }
  49. end
  50.  
  51. rule "transmitter changed"
  52. when
  53. Item tv_power received command
  54. then
  55. createTimer(now.plusMillis(tvset_slot), [ | tvtransmit.sendCommand("BOX_POWER") ])
  56. if(receivedCommand != tv_power.state) {
  57. postUpdate(triggeringItem, receivedCommand.toString)
  58. }
  59. if(receivedCommand == OFF && amp_source.state.toString == "dvd") {
  60. sendCommand(amp_source, "tv")
  61. }
  62. if(receivedCommand == ON && amp_source.state.toString != "dvd") {
  63. sendCommand(amp_source, "dvd")
  64. }
  65. end
  66.  
  67.  
  68. rule "projector changed"
  69. when
  70. Item proj_power received command
  71. then
  72. sendCommand(screen_proj, receivedCommand)
  73. if (receivedCommand==ON) {
  74. createTimer(now.plusMillis(projector_slot), [ | projector.sendCommand("KEY_POWER")])
  75. if(tv_power.state!=ON) {
  76. sendCommand(tv_power, ON)
  77. postUpdate(tv_power, ON)
  78. }
  79. if(amp_source.state.toString != "dvd") {
  80. sendCommand(amp_source, "dvd")
  81. }
  82. }
  83. if (receivedCommand==OFF) {
  84. createTimer(now.plusMillis(projector_slot), [ | projector.sendCommand("KEY_SUSPEND")])
  85. }
  86. end
  87.  
  88. rule "screen moves"
  89. when
  90. Item screen_proj received command
  91. then
  92. if (receivedCommand==ON) {
  93. createTimer(now.plusMillis(screen_slot), [ |screen_command.sendCommand("down")])
  94. }
  95. if (receivedCommand==OFF) {
  96. createTimer(now.plusMillis(screen_slot), [ |screen_command.sendCommand("up")])
  97. }
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement