blumsky1985

Untitled

Jun 15th, 2020
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.80 KB | None | 0 0
  1. esphome:
  2.   name: garagedoor
  3.   platform: ESP8266
  4.   board: esp01_1m
  5.  
  6. wifi:
  7.   ssid: mywifi
  8.   password: "mywifipw"
  9.  
  10. # Enable logging
  11. logger:
  12.   esp8266_store_log_strings_in_flash: False
  13.  
  14. # Enable Home Assistant API
  15. api:
  16. ota:
  17. globals:
  18.   - id: door_state
  19.     type: int
  20.     initial_value: '0'
  21.     restore_value: no
  22.     # possible values are:
  23.     # open    = '5'
  24.     # opening = '4'
  25.     # closed  = '3'
  26.     # closing = '2'
  27.     # halfway = '1'
  28.     # unknown = '0'
  29.  
  30. binary_sensor:
  31.   - platform: gpio
  32.     pin:
  33.       number: GPIO04
  34.       mode: INPUT_PULLUP
  35.       # when switch is closed the door is closed
  36.       inverted: True
  37.     name: "Garage Door Closed Reed Switch"
  38.     device_class: garage_door    
  39.     id: closed_sensor
  40.  
  41. switch:
  42.   - platform: gpio
  43.     pin: GPIO12
  44.     id: door_switch
  45.   - platform: template
  46.     icon: "mdi:arrow-up-down-bold-outline"
  47.     name: "Blum Garage Control Relay"
  48.  
  49. cover:
  50.   - platform: template
  51.     name: "Garage Door"
  52.     id: garage_door
  53.     device_class: garage
  54.     assumed_state: true
  55.     close_action:
  56.       - lambda: !lambda |-
  57.           ESP_LOGD("custom", "Global value is: %d", id(door_state));
  58.           if (!id(closed_sensor).state) {
  59.             id(door_state) = 2;            // 2 = closing
  60.             //turn switch on
  61.             ESP_LOGD("custom", "Global value is: %d", id(door_state));
  62.           }
  63.           while (id(door_state) == 2) {
  64.             delay(1000);
  65.             ESP_LOGD("custom", "Inside the while loop %d", 1);
  66.             ESP_LOGD("custom", "Global value is: %d", id(door_state));
  67.             if (id(closed_sensor).state) {
  68.               id(door_state) = 3;          // 3 = closed
  69.               //turn switch off
  70.               ESP_LOGD("custom", "Global value is: %d", id(door_state));
  71.             }
  72.           }
Add Comment
Please, Sign In to add comment