Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- esphome:
- name: garage-door
- friendly_name: Garage Door
- on_boot:
- priority: -10
- then:
- - lambda: |-
- id(breakbeam_sensor).publish_state(false);
- esp32:
- board: esp32dev
- framework:
- type: arduino
- # Enable logging
- logger:
- # Enable Home Assistant API
- api:
- encryption:
- key: "replace with your info"
- ota:
- password: "replace with your info"
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- # Enable fallback hotspot (captive portal) in case wifi connection fails
- ap:
- ssid: "Garage-Door Fallback Hotspot"
- password: "replace with your info"
- ##
- ## The virutal break beam sensor.
- ## The state of this will be controlled
- ## by breakbeam_sensor_dist's lambda as necessary.
- ##
- binary_sensor:
- - name: "Garage Door Sensor"
- id: breakbeam_sensor
- platform: template
- device_class: motion
- ##
- ## The actual sensor.
- ## This sensor's lambda will control the state of our
- ## virtual break beam sensor, breakbeam_sensor.
- ##
- sensor:
- - name: "Breakbeam Sensor Dist"
- id: breakbeam_sensor_dist
- platform: vl53l0x
- address: 0x29
- update_interval: 3s
- internal: true
- #
- # Only send a value back if breakbeam_sensor changes.
- #
- filters:
- - filter_out: 0
- - lambda: !lambda |-
- /**
- * YOU MIGHT WANT TO CONFIGURE THIS.
- * Distance below which to trip the virtual break beam sensor.
- * '0.5' meters is about 20 inches.
- */
- static double minTripDistance = 0.3;
- if (x >= .16 && x <= minTripDistance) {
- if (id(breakbeam_sensor).state == true) {
- // Beam was already broken
- return {};
- }
- // Beam was just broken
- id(breakbeam_sensor).publish_state(true);
- ESP_LOGI("breakbeam_sensor_dist", "Set breakbeam_sensor to Detected");
- return {};
- }
- else {
- if (id(breakbeam_sensor).state == false) {
- // Beam was already un-broken
- return {};
- }
- // Beam was just un-broken
- id(breakbeam_sensor).publish_state(false);
- ESP_LOGI("breakbeam_sensor_dist", "Set breakbeam_sensor to Cleared");
- return {};
- }
- # Configure the I2C bus
- i2c:
- sda: GPIO21
- scl: GPIO22
- scan: True
- switch:
- - platform: gpio
- id: relay1
- pin:
- number: GPIO25
- inverted: False
- restore_mode: ALWAYS_OFF
- - platform: restart
- name: 'ESPHome Garage Door REBOOT'
- cover:
- - platform: template
- name: Garage Door
- device_class: garage
- lambda: |-
- if (id(breakbeam_sensor).state) {
- return COVER_OPEN;
- } else {
- return COVER_CLOSED;
- }
- open_action:
- - switch.turn_on: relay1
- - delay: 1s
- - switch.turn_off: relay1
- close_action:
- - switch.turn_on: relay1
- - delay: 1s
- - switch.turn_off: relay1
Advertisement
Add Comment
Please, Sign In to add comment