sihui

rollershutter rule for openhab

Jun 22nd, 2016
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import org.openhab.core.library.types.*
  2. import org.openhab.core.persistence.*
  3. import org.openhab.model.script.actions.*
  4. import org.java.math.*
  5. import org.joda.time.*
  6. import org.openhab.core.types.*
  7. import org.openhab.core.items.*
  8. import org.openhab.core.library.items.*
  9. import java.util.Set
  10.  
  11. var Timer ShutterDelayTimerKitchen_East = null
  12. var Timer ShutterOverrideTimerKitchen_East = null
  13.  
  14. //shading positions
  15. var Number ShadingKitchenEastPosition = 65
  16. var Number ShadingKitchenSouth_L_Position = 70
  17. var Number ShadingKitchenSouth_R_Position = 65
  18.  
  19. //closing positions
  20. var Number ClosedKitchenEastPosition = 85
  21. var Number ClosedKitchen_South_L_Position = 85
  22. var Number ClosedKitchen_South_R_Position = 85
  23.  
  24. //two click positions
  25. var Number TwoClickKitchenEastPosition = 60
  26. var Number TwoClickKitchen_South_L_Position = 65
  27. var Number TwoClickKitchen_South_R_Position = 60
  28.  
  29. var boolean ShutterOverrideEast = false
  30.  
  31. //shading
  32. rule "calculate temperature difference between sun and shadow temp"
  33. when
  34. Item TemperatureSun changed or
  35. Item TemperatureShadow changed
  36. then
  37. val Number tempSun = TemperatureSun.state as DecimalType
  38. val Number tempShadow = TemperatureShadow.state as DecimalType
  39. var Number tempDiff = 0
  40. tempDiff = (tempSun-tempShadow)
  41. Shading_tempDiff_Proxy.postUpdate(tempDiff)
  42. end
  43.  
  44. rule "shading kitchen east"
  45. when
  46. Item Shading_tempDiff_Proxy received update
  47. then
  48. if (Night_Proxy.state==OFF && ((Sun_Az.state > 80 && Sun_Az.state < 140) && (Sun_El.state > 10 && Sun_El.state < 40)) ) {
  49. if (Shading_Shutter_Proxy.state==ON) {
  50. if (!ShutterOverrideEast) {
  51. if (Shading_tempDiff_Proxy.state >= 15) {
  52. if (ShutterDelayTimerKitchen_East!=null) {
  53. ShutterDelayTimerKitchen_East.cancel
  54. ShutterDelayTimerKitchen_East = null
  55. logInfo("FILE", "Shutter Delay Timer East reset because sunshine was detected, but timer was active")
  56. }
  57. FibFGR222_Kitchen_East.sendCommand(ShadingKitchenEastPosition)
  58. logInfo("FILE", "shading kitchen east active, shutters are down")
  59. }
  60. if (Shading_tempDiff_Proxy.state <= 14) {
  61. logInfo("FILE", "shading kitchen east temporary terminated, starting 30 min timer")
  62. ShutterDelayTimerKitchen_East = createTimer(now.plusMinutes(30)) [|
  63. if (FibFGR222_Kitchen_East.state != UP) {
  64. FibFGR222_Kitchen_East.sendCommand(UP)
  65. logInfo("FILE", "ShutterDelayTimer_East has expired, shutters are up")
  66. }
  67. ]
  68. }
  69. }
  70. else if (ShutterOverrideEast) {
  71. logInfo("FILE", "shading kitchen east overridden, starting 3 hour timer")
  72. ShutterOverrideTimerKitchen_East = createTimer(now.plusMinutes(180)) [|
  73. logInfo("FILE", "ShutterOverrideTimer_East has expired, override set to false")
  74. ShutterOverrideEast=false
  75. ]
  76. }
  77. }
  78. }
  79. else
  80. logInfo("FILE", "shading kitchen east permanently deactivated, it's night or activation conditions not met")
  81. end
  82.  
  83. rule "shading off"
  84. when
  85. Item Shading_Shutter_Proxy changed from ON to OFF
  86. then
  87. if (ShutterOverrideTimerKitchen_East!=null) {
  88. ShutterOverrideTimerKitchen_East.cancel
  89. ShutterOverrideTimerKitchen_East = null
  90. logInfo("FILE", "manual Shutter Override Timer East reset while switching OFF")
  91. }
  92. FibFGR222_Kitchen_East.sendCommand(UP)
  93. FibFGR222_Kitchen_South_L.sendCommand(UP)
  94. FibFGR222_Kitchen_South_R.sendCommand(UP)
  95. logInfo("FILE", "shading switched to off, timers cancelled")
  96. end
  97.  
  98. rule "shading on"
  99. when
  100. Item Shading_Shutter_Proxy changed from OFF to ON
  101. then
  102. if (ShutterDelayTimerKitchen_East!=null) {
  103. ShutterDelayTimerKitchen_East.cancel
  104. ShutterDelayTimerKitchen_East = null
  105. logInfo("FILE", "manual Shutter Delay Timer East reset while switching ON")
  106. }
  107. ShutterOverrideEast=false
  108. logInfo("FILE", "shading switched to on, timers cancelled")
  109. end
  110.  
  111. rule "shutter kitchen auto close"
  112. when Item Twilight_Proxy changed to ON or
  113. Time cron "0 0 20 * * ?"
  114. then
  115. if (now.getHourOfDay() <= 20 && !ShutterOverrideEast) {
  116. FibFGR222_Kitchen_East.sendCommand(ClosedKitchenEastPosition)
  117. FibFGR222_Kitchen_South_L.sendCommand(ClosedKitchen_South_L_Position)
  118. FibFGR222_Kitchen_South_R.sendCommand(ClosedKitchen_South_R_Position)
  119. logInfo("FILE", "shutters kitchen auto closed")
  120. }
  121. end
  122.  
  123. rule "shutter kitchen auto open"
  124. when Item Day_Proxy changed to ON or
  125. Time cron "0 0 9 * * ?"
  126. then
  127. if (now.getHourOfDay() >= 9 && !ShutterOverrideEast) {
  128. FibFGR222_Kitchen_East.sendCommand(UP)
  129. FibFGR222_Kitchen_South_L.sendCommand(UP)
  130. FibFGR222_Kitchen_South_R.sendCommand(UP)
  131. logInfo("FILE", "shutters kitchen auto opened")
  132. }
  133. end
  134.  
  135. rule "set override flag"
  136. when
  137. Item FibFGR222_Kitchen_East_Manual_UP_1x received update ON or
  138. Item FibFGR222_Kitchen_East_Manual_DOWN_1x received update ON or
  139. then
  140. ShutterOverrideEast = true
  141. logInfo("FILE", "shading kitchen override flag set")
  142. end
  143.  
  144. rule "override flag reset"
  145. when
  146. Time cron "0 0 0 ? * *"
  147. then
  148. ShutterOverrideEast=false
  149. logInfo("FILE", "shading kitchen override flag reset")
  150. end
  151.  
  152. //scenes east
  153. rule "scene kitchen all shutters up"
  154. when
  155. Item FibFGR222_Kitchen_East_Manual_UP_2x received update ON or
  156. Item FibFGR222_Kitchen_South_L_Manual_UP_2x received update ON or
  157. Item FibFGR222_Kitchen_South_R_Manual_UP_2x received update ON
  158. then {
  159. FibFGR222_Kitchen_East.sendCommand(UP)
  160. FibFGR222_Kitchen_South_L.sendCommand(UP)
  161. FibFGR222_Kitchen_South_R.sendCommand(UP)
  162. }
  163. end
  164.  
  165. rule "scene kitchen all shutters to two click positions"
  166. when
  167. Item FibFGR222_Kitchen_East_Manual_DOWN_2x received update ON or
  168. Item FibFGR222_Kitchen_South_L_Manual_DOWN_2x received update ON or
  169. Item FibFGR222_Kitchen_South_R_Manual_DOWN_2x received update ON
  170. then {
  171. FibFGR222_Kitchen_East.sendCommand(TwoClickKitchenEastPosition)
  172. FibFGR222_Kitchen_South_L.sendCommand(TwoClickKitchen_South_L_Position)
  173. FibFGR222_Kitchen_South_R.sendCommand(TwoClickKitchen_South_R_Position)
  174. }
  175. end
RAW Paste Data Copied