svinedyret

ESP32-Stepper-Rullegardin

Oct 21st, 2022
296
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 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.  
  80. cover:
  81. - platform: template
  82. id: "blind_cover"
  83. device_class: blind
  84. name: "Blinds"
  85. has_position: true
  86. optimistic: false
  87. open_action:
  88. - logger.log: "Opening"
  89. - cover.template.publish:
  90. id: blind_cover
  91. current_operation: OPENING
  92. - stepper.set_target:
  93. id: blind_stepper
  94. target: !lambda "return id(open_position);"
  95. - while:
  96. condition:
  97. lambda: 'return id(blind_stepper).current_position < id(open_position);'
  98. then:
  99. - script.execute: update_cover_position
  100. - delay: 1000 ms
  101. - script.execute: update_cover_position
  102. - script.execute: record_stepper_position
  103. - cover.template.publish:
  104. id: blind_cover
  105. current_operation: IDLE
  106. close_action:
  107. - logger.log: "Closing"
  108. - cover.template.publish:
  109. id: blind_cover
  110. current_operation: CLOSING
  111. - stepper.set_target:
  112. id: blind_stepper
  113. target: !lambda "return id(closed_position);"
  114. - while:
  115. condition:
  116. lambda: 'return id(blind_stepper).current_position > id(closed_position);'
  117. then:
  118. - script.execute: update_cover_position
  119. - delay: 1000 ms
  120. - script.execute: update_cover_position
  121. - script.execute: record_stepper_position
  122. - cover.template.publish:
  123. id: blind_cover
  124. current_operation: IDLE
  125. position_action:
  126. - logger.log: "Setting position"
  127. - stepper.set_target:
  128. id: blind_stepper
  129. target: !lambda 'return (float(pos) * float( float(id(open_position)) - float(id(closed_position)) )) + float(id(closed_position));'
  130. - while:
  131. condition:
  132. lambda: 'return id(blind_stepper).current_position != ((float(pos) * float( float(id(open_position)) - float(id(closed_position)) )) + float(id(closed_position)));'
  133. then:
  134. - script.execute: update_cover_position
  135. - delay: 1000 ms
  136. - script.execute: update_cover_position
  137. - script.execute: record_stepper_position
  138. - cover.template.publish:
  139. id: blind_cover
  140. current_operation: IDLE
  141. stop_action:
  142. - logger.log: "Stopping"
  143. - cover.template.publish:
  144. id: blind_cover
  145. current_operation: IDLE
  146. - stepper.set_target:
  147. id: blind_stepper
  148. target: !lambda 'return id(blind_stepper).current_position;'
  149. - script.execute: update_cover_position
  150. - script.execute: record_stepper_position
  151.  
  152. sensor:
  153. - platform: template
  154. name: "Current stepper position"
  155. lambda: return id(blind_stepper).current_position;
  156. update_interval: 5s
  157.  
  158. script:
  159. - id: update_cover_position
  160. then:
  161. - cover.template.publish:
  162. id: blind_cover
  163. position: !lambda 'return float( float(id(blind_stepper).current_position) - float(id(closed_position))) / float( float(id(open_position)) - float(id(closed_position)) );'
  164. - id: record_stepper_position
  165. then:
  166. - globals.set:
  167. id: saved_position
  168. value: !lambda 'return id(blind_stepper).current_position;'
  169.  
Advertisement
Comments
  • svinedyret
    4 years
    # text 0.16 KB | 0 0
    1. Koden er beregnet til en ESP32 som sidder i en Home Assistant installation. Man kan med få tilrettelser få den til at køre som en selvstændig enhed (Stand-Alone)
Add Comment
Please, Sign In to add comment