Guest User

Untitled

a guest
Mar 29th, 2024
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. esphome:
  2. name: garage-door
  3. friendly_name: Garage Door
  4. on_boot:
  5. priority: -10
  6. then:
  7. - lambda: |-
  8. id(breakbeam_sensor).publish_state(false);
  9.  
  10. esp32:
  11. board: esp32dev
  12. framework:
  13. type: arduino
  14.  
  15. # Enable logging
  16. logger:
  17.  
  18. # Enable Home Assistant API
  19. api:
  20. encryption:
  21. key: "replace with your info"
  22.  
  23. ota:
  24. password: "replace with your info"
  25.  
  26. wifi:
  27. ssid: !secret wifi_ssid
  28. password: !secret wifi_password
  29.  
  30. # Enable fallback hotspot (captive portal) in case wifi connection fails
  31. ap:
  32. ssid: "Garage-Door Fallback Hotspot"
  33. password: "replace with your info"
  34.  
  35. ##
  36. ## The virutal break beam sensor.
  37. ## The state of this will be controlled
  38. ## by breakbeam_sensor_dist's lambda as necessary.
  39. ##
  40. binary_sensor:
  41. - name: "Garage Door Sensor"
  42. id: breakbeam_sensor
  43. platform: template
  44. device_class: motion
  45.  
  46.  
  47. ##
  48. ## The actual sensor.
  49. ## This sensor's lambda will control the state of our
  50. ## virtual break beam sensor, breakbeam_sensor.
  51. ##
  52. sensor:
  53. - name: "Breakbeam Sensor Dist"
  54. id: breakbeam_sensor_dist
  55. platform: vl53l0x
  56. address: 0x29
  57. update_interval: 3s
  58. internal: true
  59. #
  60. # Only send a value back if breakbeam_sensor changes.
  61. #
  62. filters:
  63. - filter_out: 0
  64. - lambda: !lambda |-
  65. /**
  66. * YOU MIGHT WANT TO CONFIGURE THIS.
  67. * Distance below which to trip the virtual break beam sensor.
  68. * '0.5' meters is about 20 inches.
  69. */
  70. static double minTripDistance = 0.3;
  71. if (x >= .16 && x <= minTripDistance) {
  72. if (id(breakbeam_sensor).state == true) {
  73. // Beam was already broken
  74. return {};
  75. }
  76. // Beam was just broken
  77. id(breakbeam_sensor).publish_state(true);
  78. ESP_LOGI("breakbeam_sensor_dist", "Set breakbeam_sensor to Detected");
  79. return {};
  80. }
  81. else {
  82. if (id(breakbeam_sensor).state == false) {
  83. // Beam was already un-broken
  84. return {};
  85. }
  86. // Beam was just un-broken
  87. id(breakbeam_sensor).publish_state(false);
  88. ESP_LOGI("breakbeam_sensor_dist", "Set breakbeam_sensor to Cleared");
  89. return {};
  90. }
  91.  
  92.  
  93.  
  94. # Configure the I2C bus
  95. i2c:
  96. sda: GPIO21
  97. scl: GPIO22
  98. scan: True
  99.  
  100. switch:
  101. - platform: gpio
  102. id: relay1
  103. pin:
  104. number: GPIO25
  105. inverted: False
  106. restore_mode: ALWAYS_OFF
  107.  
  108. - platform: restart
  109. name: 'ESPHome Garage Door REBOOT'
  110.  
  111.  
  112. cover:
  113. - platform: template
  114. name: Garage Door
  115. device_class: garage
  116. lambda: |-
  117. if (id(breakbeam_sensor).state) {
  118. return COVER_OPEN;
  119. } else {
  120. return COVER_CLOSED;
  121. }
  122. open_action:
  123. - switch.turn_on: relay1
  124. - delay: 1s
  125. - switch.turn_off: relay1
  126. close_action:
  127. - switch.turn_on: relay1
  128. - delay: 1s
  129. - switch.turn_off: relay1
Tags: ESPhome
Advertisement
Add Comment
Please, Sign In to add comment