Advertisement
svinedyret

Stepper-Rullegardin-Yaml

Oct 26th, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | Source Code | 0 0
  1. esphome:
  2. name: motor-persienner-2
  3.  
  4. esp32:
  5. board: esp32dev
  6. framework:
  7. type: arduino
  8.  
  9. # Enable logging
  10. logger:
  11.  
  12. ota:
  13. password: "aa6d2ef6d6bb0a1f1364b035a68d8686"
  14.  
  15. wifi:
  16. ssid: !secret wifi_ssid
  17. password: !secret wifi_password
  18.  
  19. # Enable fallback hotspot (captive portal) in case wifi connection fails
  20. ap:
  21. ssid: "Motor-Persienner-2"
  22. password: "GB2nclOIrGeg"
  23.  
  24. captive_portal:
  25.  
  26. # Enable Home Assistant API
  27. api:
  28. encryption:
  29. key: "GAgvGvd1vA2swDSvspxIzSJcObRqh1+JrWTobR8lmzY="
  30. services:
  31. - service: set_stepper_target
  32. variables:
  33. target: int
  34. then:
  35. - stepper.set_target:
  36. id: blind_stepper
  37. target: !lambda 'return target;'
  38. - script.execute: record_stepper_position
  39. - service: set_stepper_speed
  40. variables:
  41. speed: int
  42. then:
  43. - stepper.set_speed:
  44. id: blind_stepper
  45. speed: !lambda 'return speed;'
  46. - service: set_stepper_position
  47. variables:
  48. stepper_position: int
  49. then:
  50. - stepper.report_position:
  51. id: blind_stepper
  52. position: !lambda "return stepper_position;"
  53. - stepper.set_target:
  54. id: blind_stepper
  55. target: !lambda "return stepper_position;"
  56.  
  57. globals:
  58. - id: open_position
  59. type: int
  60. initial_value: '8000'
  61. - id: closed_position
  62. type: int
  63. initial_value: '1000'
  64. - id: saved_position
  65. type: int
  66. initial_value: '1000'
  67. restore_value: true
  68.  
  69. stepper:
  70. - platform: uln2003
  71. id: blind_stepper
  72. pin_a: GPIO16
  73. pin_b: GPIO17
  74. pin_c: GPIO18
  75. pin_d: GPIO19
  76. max_speed: 50 steps/s
  77. acceleration: 200
  78. deceleration: 200
  79. sleep_when_done: true
  80.  
  81. cover:
  82. - platform: template
  83. id: "blind_cover"
  84. device_class: blind
  85. name: "Blinds"
  86. has_position: true
  87. optimistic: false
  88. open_action:
  89. - logger.log: "Opening"
  90. - cover.template.publish:
  91. id: blind_cover
  92. current_operation: OPENING
  93. - stepper.set_target:
  94. id: blind_stepper
  95. target: !lambda "return id(open_position);"
  96. - while:
  97. condition:
  98. lambda: 'return id(blind_stepper).current_position < id(open_position);'
  99. then:
  100. - script.execute: update_cover_position
  101. - delay: 1000 ms
  102. - script.execute: update_cover_position
  103. - script.execute: record_stepper_position
  104. - cover.template.publish:
  105. id: blind_cover
  106. current_operation: IDLE
  107. close_action:
  108. - logger.log: "Closing"
  109. - cover.template.publish:
  110. id: blind_cover
  111. current_operation: CLOSING
  112. - stepper.set_target:
  113. id: blind_stepper
  114. target: !lambda "return id(closed_position);"
  115. - while:
  116. condition:
  117. lambda: 'return id(blind_stepper).current_position > id(closed_position);'
  118. then:
  119. - script.execute: update_cover_position
  120. - delay: 1000 ms
  121. - script.execute: update_cover_position
  122. - script.execute: record_stepper_position
  123. - cover.template.publish:
  124. id: blind_cover
  125. current_operation: IDLE
  126. position_action:
  127. - logger.log: "Setting position"
  128. - stepper.set_target:
  129. id: blind_stepper
  130. target: !lambda 'return (float(pos) * float( float(id(open_position)) - float(id(closed_position)) )) + float(id(closed_position));'
  131. - while:
  132. condition:
  133. lambda: 'return id(blind_stepper).current_position != ((float(pos) * float( float(id(open_position)) - float(id(closed_position)) )) + float(id(closed_position)));'
  134. then:
  135. - script.execute: update_cover_position
  136. - delay: 1000 ms
  137. - script.execute: update_cover_position
  138. - script.execute: record_stepper_position
  139. - cover.template.publish:
  140. id: blind_cover
  141. current_operation: IDLE
  142. stop_action:
  143. - logger.log: "Stopping"
  144. - cover.template.publish:
  145. id: blind_cover
  146. current_operation: IDLE
  147. - stepper.set_target:
  148. id: blind_stepper
  149. target: !lambda 'return id(blind_stepper).current_position;'
  150. - script.execute: update_cover_position
  151. - script.execute: record_stepper_position
  152.  
  153. sensor:
  154. - platform: template
  155. name: "Current stepper position"
  156. lambda: return id(blind_stepper).current_position;
  157. update_interval: 5s
  158.  
  159. script:
  160. - id: update_cover_position
  161. then:
  162. - cover.template.publish:
  163. id: blind_cover
  164. position: !lambda 'return float( float(id(blind_stepper).current_position) - float(id(closed_position))) / float( float(id(open_position)) - float(id(closed_position)) );'
  165. - id: record_stepper_position
  166. then:
  167. - globals.set:
  168. id: saved_position
  169. value: !lambda 'return id(blind_stepper).current_position;'
  170.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement