penright

Code example showing priority

Feb 4th, 2022 (edited)
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.45 KB | None | 0 0
  1. esphome:
  2.   name: esphome-shop-garage-door
  3.   platform: ESP32
  4.   board: esp32doit-devkit-v1
  5. #On reboot the cover's current_operation is lost
  6. #   we can check the reed switchs and know the door is
  7. #   is in some unknow state but we don't know if it was
  8. #   opening or closing. So we will just pick one
  9.   on_boot:
  10.     priority: 300
  11.     then:
  12.       lambda: |-
  13.         ESP_LOGD("On Boot","Start (300)1");
  14.         ESP_LOGD("On Boot","  Contact Sensor Open   %s",id(contact_sensor_open_postion).state ? "true" : "false");
  15.         ESP_LOGD("On Boot","  Contact Sensor Closed %s",id(contact_sensor_closed_postion).state ? "true" : "false");
  16.         if ((id(contact_sensor_open_postion).state) == true) {
  17.           id(template_cov).position = COVER_OPEN;
  18.           id(template_cov).current_operation = COVER_OPERATION_IDLE;
  19.           id(template_cov).publish_state();
  20.           ESP_LOGD("On Boot","Open");
  21.         } else if (id(contact_sensor_closed_postion).state == true) {
  22.           id(template_cov).position = COVER_CLOSED;
  23.           id(template_cov).current_operation = COVER_OPERATION_IDLE;
  24.           id(template_cov).publish_state();
  25.           ESP_LOGD("On Boot","Closed");
  26.         } else {
  27.           id(template_cov).position = 0.5;
  28.           id(template_cov).current_operation = COVER_OPERATION_OPENING;
  29.           id(template_cov).publish_state();
  30.           ESP_LOGD("On Boot","Not Known");
  31.         }
  32.         ESP_LOGD("On Boot","End");
  33.  
  34. wifi:
  35.   ssid: !secret wifi_ssid_work
  36.   password: !secret wifi_password_work
  37. #  use_address: !secret ESPHome_IP_Shop_Garage_Door
  38.   use_address: "172.25.92.115"
  39.  
  40.  
  41.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  42.   ap:
  43.     ssid: !secret wifi_esphome_fallback_ssid
  44.     password: !secret wifi_esphome_fallback_password
  45.  
  46. captive_portal:
  47.  
  48. # Enable logging
  49. logger:
  50.   level: DEBUG
  51.  
  52. # Enable Home Assistant API
  53. api:
  54.   password: !secret esphome_api_password
  55.  
  56. ota:
  57.   password: !secret esphome_ota_password
  58.  
  59.  
  60.  
  61. status_led:
  62.   pin:
  63.     number: GPIO02
  64.     inverted: True
  65.  
  66.  
  67. #===================================================================================
  68. #When holding the board with USB down
  69. #   GND         RST         |       -GPIO  1   GND
  70. #   NC          GPIO 36     |       -GPIO  3  *GPIO 27
  71. #   GPIO 39    *GPIO 26     |        GPIO 22   GPIO 25
  72. #   GPIO 35     GPIO 18     |        GPIO 21  *GPIO 32
  73. #  *GPIO 33     GPIO 19     |        GPIO 17  *GPIO 12
  74. #   GPIO 34     GPIO 23     |       *GPIO 16   GPIO  4
  75. #  *GPIO 14     GPIO  5     |        GND       GPIO  0
  76. #   NC          3.3V        |        5V        GPIO  2
  77. #   GPIO  9    *GPIO 13     |       *GPIO 15  -GPIO  8
  78. #  -GPIO 11     GPIO 10     |       -GPIO  7  -GPIO  6
  79. #Notes
  80. #  * Pins are best to use
  81. #  - Pins that should never be use
  82. #  Unmark pins could be used as input only but ESPHome won't allow it
  83. #===================================================================================
  84.  
  85.  
  86.  
  87. binary_sensor:
  88.   - platform: gpio
  89.     pin:
  90.       number: GPIO27
  91.       mode: INPUT_PULLUP
  92.       inverted: true
  93.     name: "Shop North Overhead Door Closed Postion"
  94.     device_class: garage_door
  95.     id: contact_sensor_closed_postion
  96.     on_release:
  97.       - cover.template.publish:
  98.           id: template_cov
  99.           current_operation: OPENING
  100.     on_press:
  101.       - cover.template.publish:
  102.           id: template_cov
  103.           current_operation: IDLE
  104.     internal: true
  105.     filters:
  106.     - delayed_on: 100ms
  107.  
  108.   - platform: gpio
  109.     pin:
  110.       number: GPIO12
  111.       mode: INPUT_PULLUP
  112.       inverted: true
  113.     name: "Shop North Overhead Door Open Postion"
  114.     device_class: garage_door
  115.     id: contact_sensor_open_postion
  116.     on_release:
  117.       - cover.template.publish:
  118.           id: template_cov
  119.           current_operation: CLOSING
  120.     on_press:
  121.       - cover.template.publish:
  122.           id: template_cov
  123.           current_operation: IDLE
  124.     internal: true
  125.     filters:
  126.     - delayed_on: 100ms
  127.   - platform: gpio
  128.     pin:
  129.       number: GPIO32
  130.       mode: INPUT_PULLUP
  131.       inverted: False
  132.     name: "Shop Door"
  133.     device_class: door
  134.     filters:
  135.     - delayed_on: 100ms
  136.    
  137. switch:
  138.   - platform: gpio
  139.     pin:
  140.       number: GPIO13
  141.       inverted: true
  142.     name: "Shop North Overhead Door Relay"
  143.     id: relay
  144.     internal: true
  145.    
  146.    
  147.   - platform: restart
  148.     name: "Reset Shop garage Door ESPHome"
  149.  
  150.  
  151. # This creates the actual garage door in HA. The state is based
  152. # on the contact sensor. Opening/closing the garage door simply
  153. # turns the relay on/off with a 0.5s delay in between.
  154.         #return COVER_CLOSED;
  155. cover:
  156.   - platform: template
  157.     device_class: garage
  158.     name: "Shop North Overhead Door"
  159.     id: template_cov
  160.     lambda: |-
  161.       if ((id(contact_sensor_open_postion).state) == true) {
  162.         return COVER_OPEN;
  163.       } else if (id(contact_sensor_closed_postion).state == true) {
  164.         return COVER_CLOSED;
  165.       } else {
  166.         return 0.5;
  167.       }
  168.     open_action:
  169.       - switch.turn_on: relay
  170.       - delay: 0.5s
  171.       - switch.turn_off: relay
  172.     close_action:
  173.       - switch.turn_on: relay
  174.       - delay: 0.5s
  175.       - switch.turn_off: relay
  176.     stop_action:
  177.       - if:
  178.           condition:
  179.             lambda: 'return !(id(contact_sensor_closed_postion).state == true || id(contact_sensor_open_postion).state == true) ;'
  180.           then:
  181.             - switch.turn_on: relay
  182.             - delay: 0.5s
  183.             - switch.turn_off: relay
  184.    
  185.    
  186.  
Add Comment
Please, Sign In to add comment