Advertisement
Guest User

Untitled

a guest
Jan 28th, 2021
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.17 KB | None | 0 0
  1. on Rules#Timer=5 do
  2. event,ControlZ3=[VAR#7]
  3. endon
  4.  
  5. on Rules#Timer=6 do
  6. TaskValueSet,4,4,0
  7. endon
  8.  
  9. on ControlZ3 do
  10. //control?cmd=event,ControlZ3=0
  11. // both shutters of the room controlled at the same time, value in percent; [Z3#S] = room state (in percent), [Z3#SL] = State of left shutter, [Z3#SR] = right shutter
  12. // each shutter is controlled by 2 relays, the first relay to give the second one power (by closing NO), the second one NC to close, NO to open. need this to avoid giving the shutter drive on both directions power at the same time.
  13. // additionally in front of the first relay there is a power relay which first needs to be closed, to have power on the cabled relays. GPIO = 2
  14. // delay of 250 milliseconds is needed because of the shutter drive (they do not like to drive instantly into the other direction)
  15.  
  16. // VAR#6 is used to decide, what needs to be done. driving a shutter in percent (if value is between 1 and 99), opening a shutter (value = 0), closing a shutter (value = 100); some special states like -1 (drive both shutters to the same position first, afterwards drive both to the requested position), 101, 102 and 103 are not done yet.
  17.  
  18. // used temporary for calculations: VAR#10, VAR#11, VAR#12, VAR#13, VAR#14, VAR#15
  19. // used temporary to preserve the requested position: VAR#7
  20. // used timers: TimerSet,6 for locking ([Z3#M]), TimerSet,5 for driving after syncing both shutters to the in VAR#7 preserved position.
  21.  
  22. if [Z3#SL] != [Z3#SR]
  23. logentry,"Z3SL=[Z3#SL] and Z3SR=[Z3#SR] not in same state. Sync first."
  24. Let,6,-1
  25. Let,7,%eventvalue%
  26. else
  27. Let,6,%eventvalue%
  28. endif
  29. if [VAR#6] > 0 and [VAR#6] < 100 and [Z3#M] = 0
  30. //open/close both in percent; 20 = seconds for a complete close or open. as I use LongPulse I need to calculate always seconds out of the percent.
  31. Let,10,(20/100)*[VAR#6]
  32. Let,11,(20/100)*[Z3#S]
  33. if [VAR#11] > [VAR#10]
  34. // open a bit
  35. Let,12,[VAR#11]-[VAR#10]
  36. logentry,Z3_o_secs=[VAR#12]
  37. gpio,2,0
  38. TimerSet,8,[VAR#12]+2
  39. delay,250
  40. LongPulse,17,0,[VAR#12]
  41. LongPulse,21,0,[VAR#12]
  42. LongPulse,18,0,[VAR#12]
  43. LongPulse,19,0,[VAR#12]
  44. TimerSet,6,[VAR#12]
  45. TaskValueSet,4,4,1
  46. endif
  47. if [VAR#11] < [VAR#10]
  48. //close a bit
  49. Let,12,[VAR#10]-[VAR#11]
  50. logentry,Z3_c_secs=[VAR#12]
  51. gpio,2,0
  52. TimerSet,8,[VAR#12]+2
  53. delay,250
  54. LongPulse,17,0,[VAR#12]
  55. gpio,21,1
  56. LongPulse,18,0,[VAR#12]
  57. gpio,19,1
  58. TimerSet,6,[VAR#12]
  59. TaskValueSet,4,4,1
  60. endif
  61. TaskValueSet,4,1,[VAR#6]
  62. TaskValueSet,4,2,[VAR#6]
  63. TaskValueSet,4,3,[VAR#6]
  64. else
  65. if [VAR#6] = 0 and [Z3#M] = 0
  66. // open complete. always 20 seconds, as it is a kind of "now I am very sure it is opened" status.
  67. logentry,Z3_o_comp
  68. gpio,2,0
  69. TimerSet,8,20+2
  70. delay,250
  71. LongPulse,17,0,20
  72. LongPulse,21,0,20
  73. LongPulse,18,0,20
  74. LongPulse,19,0,20
  75. TimerSet,6,20
  76. TaskValueSet,4,4,1
  77. TaskValueSet,4,1,[VAR#6]
  78. TaskValueSet,4,2,[VAR#6]
  79. TaskValueSet,4,3,[VAR#6]
  80. endif
  81. if [VAR#6] = 100 and [Z3#M] = 0
  82. // close complete. always 20 seconds, as it is a kind of "now I am very sure it is closed" status.
  83. logentry,Z3_c_comp
  84. gpio,2,0
  85. TimerSet,8,20+2
  86. delay,250
  87. LongPulse,17,0,20
  88. gpio,21,1
  89. LongPulse,18,0,20
  90. gpio,19,1
  91. TimerSet,6,20
  92. TaskValueSet,4,4,1
  93. TaskValueSet,4,1,[VAR#6]
  94. TaskValueSet,4,2,[VAR#6]
  95. TaskValueSet,4,3,[VAR#6]
  96. endif
  97. if [VAR#6] = 101
  98. //stop both
  99. logentry,Z3_stop
  100. LongPulse,17,0,0
  101. LongPulse,21,0,0
  102. LongPulse,18,0,0
  103. LongPulse,19,0,0
  104. TimerSet,6,1
  105. endif
  106. if [VAR#6] = 102
  107. //special state
  108. endif
  109. if [VAR#6] = 103
  110. //special state
  111. endif
  112. if [VAR#6] = -1 and [Z3#M] = 0
  113. //sync shutters; set timer for drive both to requested position afterwards
  114. Let,14,([Z3#SL]-[VAR#7]) // needed for compare below
  115. Let,15,([Z3#SR]-[VAR#7]) // needed for compare below
  116. if [VAR#15] > [VAR#14]
  117. logentry,"Sync R to L"
  118. // Left shutter is near to the requested position. so first drive right shutter to the position of the left
  119. Let,13,(20/100)*([Z3#SR]-[Z3#SL])
  120. event,ControlZ3R=[Z3#SL]
  121. Let,13,abs([VAR#13])+1
  122. TimerSet,5,[VAR#13]
  123. else
  124. logentry,"Sync L to R"
  125. // Right shutter is near to the requested position. so first drive left shutter to the position of the right
  126. Let,13,(20/100)*([Z3#SL]-[Z3#SR])
  127. event,ControlZ3L=[Z3#SR]
  128. Let,13,abs([VAR#13])+1
  129. TimerSet,5,[VAR#13]
  130. endif
  131. endif
  132. endif
  133. endif
  134. endon
  135.  
  136. on ControlZ3L do
  137. //control?cmd=event,ControlZ3L=0
  138. // control only left shutter, in percent.
  139. Let,6,%eventvalue%
  140. if [VAR#6] > 0 and [VAR#6] < 100 and [Z3#M] = 0
  141. //open/close percent
  142. Let,10,(20/100)*[VAR#6]
  143. Let,11,(20/100)*[Z3#SL]
  144. if [VAR#11] > [VAR#10]
  145. // open a bit
  146. Let,12,[VAR#11]-[VAR#10]
  147. logentry,Z3L_o_secs=[VAR#12]
  148. gpio,2,0
  149. TimerSet,8,[VAR#12]+2
  150. delay,250
  151. LongPulse,18,0,[VAR#12]
  152. LongPulse,19,0,[VAR#12]
  153. TimerSet,6,[VAR#12]
  154. TaskValueSet,4,4,1
  155. endif
  156. if [VAR#11] < [VAR#10] and [Z3#M] = 0
  157. //close a bit
  158. Let,12,[VAR#10]-[VAR#11]
  159. logentry,Z3L_c_secs=[VAR#12]
  160. gpio,2,0
  161. TimerSet,8,[VAR#12]+2
  162. delay,250
  163. LongPulse,18,0,[VAR#12]
  164. gpio,19,1
  165. TimerSet,6,[VAR#12]
  166. TaskValueSet,4,4,1
  167. endif
  168. TaskValueSet,4,2,[VAR#6]
  169. if [Z3#SL] = [Z3#SR]
  170. TaskValueSet,4,1,[VAR#6]
  171. else
  172. TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
  173. endif
  174. else
  175. if [VAR#6] = 0 and [Z3#M] = 0
  176. // open left shutter complete
  177. logentry,Z3L_o_comp
  178. gpio,2,0
  179. TimerSet,8,20+2
  180. delay,250
  181. LongPulse,18,0,20
  182. LongPulse,19,0,20
  183. TimerSet,6,20
  184. TaskValueSet,4,4,1
  185. TaskValueSet,4,2,[VAR#6]
  186. if [Z3#SL] = [Z3#SR]
  187. TaskValueSet,4,1,[VAR#6]
  188. else
  189. TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
  190. endif
  191. endif
  192. if [VAR#6] = 100 and [Z3#M] = 0
  193. // close left shutter complete
  194. logentry,Z3L_c_comp
  195. gpio,2,0
  196. TimerSet,8,[VAR#12]+2
  197. delay,250
  198. LongPulse,18,0,20
  199. gpio,19,1
  200. TimerSet,6,20
  201. TaskValueSet,4,4,1
  202. TaskValueSet,4,2,[VAR#6]
  203. if [Z3#SL] = [Z3#SR]
  204. TaskValueSet,4,1,[VAR#6]
  205. else
  206. TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
  207. endif
  208. endif
  209. if [VAR#6] = 101
  210. //stop Z3L
  211. logentry,Z3L_stop
  212. LongPulse,18,0,0
  213. LongPulse,19,0,0
  214. TimerSet,6,1
  215. endif
  216. if [VAR#6] = 102
  217. //special state
  218. endif
  219. if [VAR#6] = 103
  220. //special state
  221. endif
  222. endif
  223. endon
  224.  
  225. on ControlZ3R do
  226. //control?cmd=event,ControlZ3R=0
  227. // same as above for the left shutter now for the right shutter
  228. Let,6,%eventvalue%
  229. if [VAR#6] > 0 and [VAR#6] < 100 and [Z3#M] = 0
  230. //open/close percent
  231. Let,10,(20/100)*[VAR#6]
  232. Let,11,(20/100)*[Z3#SR]
  233. if [VAR#11] > [VAR#10]
  234. // open a bit
  235. Let,12,[VAR#11]-[VAR#10]
  236. logentry,Z3R_o_secs=[VAR#12]
  237. gpio,2,0
  238. TimerSet,8,[VAR#12]+2
  239. delay,250
  240. LongPulse,17,0,[VAR#12]
  241. LongPulse,21,0,[VAR#12]
  242. TimerSet,6,[VAR#12]
  243. TaskValueSet,4,4,1
  244. endif
  245. if [VAR#11] < [VAR#10]
  246. //close a bit
  247. Let,12,[VAR#10]-[VAR#11]
  248. logentry,Z3R_c_secs=[VAR#12]
  249. gpio,2,0
  250. TimerSet,8,[VAR#12]+2
  251. delay,250
  252. LongPulse,17,0,[VAR#12]
  253. gpio,21,1
  254. TimerSet,6,[VAR#12]
  255. TaskValueSet,4,4,1
  256. endif
  257. TaskValueSet,4,3,[VAR#6]
  258. if [Z3#SL] = [Z3#SR]
  259. TaskValueSet,4,1,[VAR#6]
  260. else
  261. TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
  262. endif
  263. else
  264. if [VAR#6] = 0 and [Z3#M] = 0
  265. logentry,Z3R_o_comp
  266. gpio,2,0
  267. TimerSet,8,20+2
  268. delay,250
  269. LongPulse,17,0,20
  270. LongPulse,21,0,20
  271. TimerSet,6,[VAR#12]
  272. TaskValueSet,4,4,1
  273. TaskValueSet,4,3,[VAR#6]
  274. if [Z3#SL] = [Z3#SR]
  275. TaskValueSet,4,1,[VAR#6]
  276. else
  277. TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
  278. endif
  279. endif
  280. if [VAR#6] = 100 and [Z3#M] = 0
  281. logentry,Z3R_c_comp
  282. gpio,2,0
  283. TimerSet,8,20+2
  284. delay,250
  285. LongPulse,17,0,20
  286. gpio,21,1
  287. TimerSet,6,[VAR#12]
  288. TaskValueSet,4,4,1
  289. TaskValueSet,4,4,1
  290. TaskValueSet,4,3,[VAR#6]
  291. if [Z3#SL] = [Z3#SR]
  292. TaskValueSet,4,1,[VAR#6]
  293. else
  294. TaskValueSet,4,1,(([Z3#SL]+[Z3#SR])/2)
  295. endif
  296. endif
  297. if [VAR#6] = 101
  298. //stop Z3R
  299. logentry,Z3R_stop
  300. LongPulse,17,0,0
  301. LongPulse,21,0,0
  302. TimerSet,6,1
  303. endif
  304. if [VAR#6] = 102
  305. //special state
  306. endif
  307. if [VAR#6] = 103
  308. //special state
  309. endif
  310. endif
  311. endon
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement