Advertisement
boelle11

Untitled

Jan 25th, 2021
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.54 KB | None | 0 0
  1.  
  2. # 1) Press button for > 1 second to enter setup mode
  3. # 2) Press button again to start the blind closing
  4. # 3) Press button again when closed and blind starts to open (actually resets the stepper position to 0)
  5. # 4) Press button again when blind is fully open
  6. # 5) Job Done
  7.  
  8. # Button is also used to open/close the blind (must be fully open/closed first)
  9.  
  10. esphome:
  11. name: gardin_kontor
  12. platform: ESP8266
  13. board: nodemcuv2
  14. esp8266_restore_from_flash: True
  15. on_boot:
  16. - priority: -200.0
  17. then:
  18. - stepper.report_position: # Set stepper to global variable
  19. id: my_stepper
  20. position: !lambda return id(my_stepper_global);
  21. - stepper.set_target: # Set stepper to global variable
  22. id: my_stepper
  23. target: !lambda return id(my_stepper_global);
  24. - if: # If blind is Closed
  25. condition:
  26. - lambda: 'return id(my_stepper_global) == 0;'
  27. then: # Publish state etc.
  28. - cover.template.publish:
  29. id: blinded
  30. state: CLOSED
  31. current_operation: IDLE
  32. - if: # If blind is Open
  33. condition:
  34. - lambda: 'return id(my_stepper_global) == id(endstop);'
  35. then: # Publish state etc.
  36. - cover.template.publish:
  37. id: blinded
  38. state: OPEN
  39. current_operation: IDLE
  40. - if: # If blind is Neither
  41. condition:
  42. - lambda: 'return (id(my_stepper_global) != 0) && (id(my_stepper_global) != id(endstop));'
  43. then: # # Publish state etc.
  44. - cover.template.publish:
  45. id: blinded
  46. position: !lambda 'return (float(float(id(my_stepper).current_position) / float(id(endstop))));'
  47. current_operation: IDLE
  48.  
  49. wifi:
  50. ssid: !secret wifi_ssid
  51. password: !secret wifi_password
  52. ap:
  53. ssid: Roller Blind
  54. password: !secret ap_password
  55.  
  56. web_server:
  57. port: 80
  58.  
  59. logger:
  60.  
  61. api:
  62.  
  63.  
  64. ota:
  65.  
  66.  
  67. captive_portal:
  68.  
  69. stepper:
  70. - platform: a4988
  71. id: my_stepper
  72. dir_pin:
  73. number: D3
  74. inverted: True
  75. step_pin: D2
  76. sleep_pin: D1
  77. max_speed: 500 steps/s # Set the speed of the motor
  78. acceleration: 300
  79. deceleration: 300
  80.  
  81. globals:
  82. - id: my_stepper_global # Integer for storing the stepper position in case of reboot
  83. type: int
  84. restore_value: True
  85. initial_value: '0'
  86.  
  87. - id: openclosed # Boolean to store OPEN/CLOSED state
  88. type: bool
  89. restore_value: True
  90. initial_value: '0'
  91.  
  92. - id: endstop # Variable for storing ENDSTOP (how far to move stepper)
  93. type: int
  94. restore_value: True
  95. initial_value: '1000'
  96.  
  97. - id: settingmode # Integer for Setup Mode
  98. type: int
  99. restore_value: no
  100. initial_value: '0'
  101.  
  102. binary_sensor:
  103. - platform: gpio
  104. pin:
  105. number: D6 # Connect Button to D6 and GND
  106. mode: INPUT_PULLUP
  107. inverted: True
  108. name: Button
  109. internal: True
  110. on_click:
  111. - min_length: 50ms
  112. max_length: 500ms
  113. then: # Short press to OPEN/CLOSE blinds and also for setting up
  114. - if: # If settings variable is on
  115. condition:
  116. - lambda: 'return id(settingmode) != 0;'
  117. then: # Enter Setting Mode
  118. - script.execute: setupbutton
  119. else:
  120. - if: # If blind is closed
  121. condition:
  122. - lambda: 'return id(openclosed) == 0;'
  123. then: # Open blind
  124. - cover.open: blinded
  125. else: # Close blind
  126. - cover.close: blinded
  127. - min_length: 1000ms
  128. max_length: 3000ms
  129. then: # Long press to Enter Setting Mode
  130. - logger.log: "Entered Settings Mode"
  131. - globals.set:
  132. id: settingmode
  133. value: '1'
  134.  
  135. switch:
  136. - platform: template
  137. name: Roller Blind Setup Switch # Switch to enter Setup Mode
  138. id: setupswitch
  139. lambda: |-
  140. if (id(settingmode) != 0) {
  141. return true;
  142. } else {
  143. return false;
  144. }
  145. turn_on_action:
  146. then:
  147. - logger.log: "Entered Settings Mode"
  148. - globals.set:
  149. id: settingmode
  150. value: '1'
  151. turn_off_action:
  152. then:
  153. - logger.log: "Exiting Settings Mode"
  154. - globals.set:
  155. id: settingmode
  156. value: '0'
  157. - platform: template
  158. name: Roller Blind Setup Button # Switch to replicate the Physical Button
  159. id: hasetup
  160. turn_on_action:
  161. - if: # If settings variable is on
  162. condition:
  163. - lambda: 'return id(settingmode) != 0;'
  164. then: # Enter Setting Mode
  165. - script.execute: setupbutton
  166. - switch.turn_off: hasetup
  167.  
  168. cover:
  169. - platform: template
  170. name: "Gardin Kontor"
  171. id: blinded
  172. open_action:
  173. then:
  174. - logger.log: "Opening"
  175. - stepper.set_target: # Send stepper to endstop
  176. id: my_stepper
  177. target: !lambda return id(endstop);
  178. - while:
  179. condition:
  180. lambda: 'return id(my_stepper).current_position != id(endstop);'
  181. then:
  182. - cover.template.publish:
  183. id: blinded
  184. position: !lambda 'return (float(float(id(my_stepper).current_position) / float(id(endstop))));'
  185. current_operation: OPENING
  186. - delay: 1000 ms
  187. - globals.set: # Set global to current position
  188. id: my_stepper_global
  189. value: !lambda return id(my_stepper).current_position;
  190. - globals.set: # Set toggle to OPEN (No need for 'optimistic mode')
  191. id: openclosed
  192. value: '1'
  193. - cover.template.publish:
  194. id: blinded
  195. state: OPEN
  196. current_operation: IDLE
  197. close_action:
  198. then:
  199. - logger.log: "Closing"
  200. - stepper.set_target: # Send stepper to 0
  201. id: my_stepper
  202. target: '0'
  203. - while:
  204. condition:
  205. lambda: 'return id(my_stepper).current_position != 0;'
  206. then:
  207. - cover.template.publish:
  208. id: blinded
  209. position: !lambda 'return (float(float(id(my_stepper).current_position) / float(id(endstop))));'
  210. current_operation: CLOSING
  211. - delay: 1000 ms
  212. - globals.set: # Set global to current position
  213. id: my_stepper_global
  214. value: !lambda return id(my_stepper).current_position;
  215. - globals.set: # Set toggle to CLOSED (No need for 'optimistic mode')
  216. id: openclosed
  217. value: '0'
  218. - cover.template.publish:
  219. id: blinded
  220. state: CLOSED
  221. current_operation: IDLE
  222. position_action:
  223. then:
  224. - stepper.set_target:
  225. id: my_stepper
  226. target: !lambda return int(id(endstop) * pos);
  227. - while:
  228. condition:
  229. lambda: 'return id(my_stepper).current_position != int(id(endstop) * pos);'
  230. then:
  231. - cover.template.publish:
  232. id: blinded
  233. position: !lambda 'return (float(float(id(my_stepper).current_position) / float(id(endstop))));'
  234. - delay: 1000 ms
  235. - globals.set: # Set global to current position
  236. id: my_stepper_global
  237. value: !lambda return id(my_stepper).current_position;
  238. - cover.template.publish:
  239. id: blinded
  240. position: !lambda 'return (float(float(id(my_stepper).current_position) / float(id(endstop))));'
  241. current_operation: IDLE
  242. stop_action:
  243. then:
  244. - stepper.set_target:
  245. id: my_stepper
  246. target: !lambda return id(my_stepper).current_position;
  247. - globals.set: # Set global to current position
  248. id: my_stepper_global
  249. value: !lambda return id(my_stepper).current_position;
  250. - cover.template.publish:
  251. id: blinded
  252. position: !lambda 'return (float(float(id(my_stepper).current_position) / float(id(endstop))));'
  253. current_operation: IDLE
  254. has_position: true
  255. device_class: blind
  256.  
  257. script:
  258. - id: setupbutton
  259. then:
  260. - if:
  261. condition:
  262. - lambda: 'return (id(settingmode) == 3);'
  263. then:
  264. - logger.log: "Pressed Setup Button: Mode 3"
  265. - stepper.set_target: # Set Stepper position
  266. id: my_stepper
  267. target: !lambda return id(my_stepper).current_position;
  268. - globals.set: # Set Endstop Variable
  269. id: endstop
  270. value: !lambda return id(my_stepper).current_position;
  271. - globals.set: # Set Global stepper position
  272. id: my_stepper_global
  273. value: !lambda return id(my_stepper).current_position;
  274. - globals.set: # Reset Setting Mode
  275. id: settingmode
  276. value: '0'
  277. - globals.set: # Set toggle to Open
  278. id: openclosed
  279. value: '1'
  280. - cover.template.publish:
  281. id: blinded
  282. state: OPEN
  283. current_operation: IDLE
  284. - logger.log: "Exiting Setting Mode"
  285. - if:
  286. condition:
  287. - lambda: 'return (id(settingmode) == 2);'
  288. then:
  289. - logger.log: "Pressed Setup Button: Mode 2"
  290. - stepper.report_position: # Reset Stepper position to 0
  291. id: my_stepper
  292. position: '0'
  293. - stepper.set_target: # Reset Stepper position to 0
  294. id: my_stepper
  295. target: '0'
  296. - globals.set: # Move stepper to 0 (doesn't move it's already there!)
  297. id: my_stepper_global
  298. value: '0'
  299. - stepper.set_target: # Reset Stepper position to 72000
  300. id: my_stepper
  301. target: '72000'
  302. - globals.set: # Advance setup to next mode
  303. id: settingmode
  304. value: '3'
  305. - if:
  306. condition:
  307. - lambda: 'return (id(settingmode) == 1);'
  308. then:
  309. - logger.log: "Pressed Setup Button: Mode 1"
  310. - stepper.report_position: # Set Stepper position to 72000, makes it move to 0 (Closed)
  311. id: my_stepper
  312. position: '72000'
  313. - globals.set: # Advance setup to next mode
  314. id: settingmode
  315. value: '2'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement