|
| 1 | +--- |
| 2 | +# settings |
| 3 | +esphome: |
| 4 | + name: carport-door-opener |
| 5 | + friendly_name: "Carport Door Opener" |
| 6 | + |
| 7 | +esp8266: |
| 8 | + board: nodemcuv2 |
| 9 | + restore_from_flash: true |
| 10 | + |
| 11 | +wifi: |
| 12 | + ssid: !secret wifi_ssid |
| 13 | + password: !secret wifi_password |
| 14 | + use_address: "192.168.2.77" |
| 15 | + domain: ".iot" |
| 16 | + |
| 17 | +logger: |
| 18 | + |
| 19 | +api: |
| 20 | + encryption: |
| 21 | + key: !secret api_key |
| 22 | + |
| 23 | +ota: |
| 24 | + - platform: esphome |
| 25 | + password: !secret ota_password |
| 26 | + |
| 27 | +sensor: |
| 28 | + - platform: wifi_signal |
| 29 | + name: "WiFi Signal dB" |
| 30 | + id: wifi_signal_db |
| 31 | + update_interval: 60s |
| 32 | + entity_category: "diagnostic" |
| 33 | + |
| 34 | +# configuration |
| 35 | +globals: |
| 36 | + - id: performing_last_movement |
| 37 | + type: boolean |
| 38 | + restore_value: no |
| 39 | + initial_value: "false" |
| 40 | + |
| 41 | +switch: |
| 42 | + - platform: gpio |
| 43 | + id: garage_door_relay |
| 44 | + pin: D1 |
| 45 | + inverted: true |
| 46 | + restore_mode: ALWAYS_OFF |
| 47 | + internal: true |
| 48 | + on_turn_on: |
| 49 | + - delay: 500ms |
| 50 | + - switch.turn_off: garage_door_relay |
| 51 | + |
| 52 | +binary_sensor: |
| 53 | + - platform: gpio |
| 54 | + id: open_endstop |
| 55 | + name: "Open Endstop" |
| 56 | + device_class: garage_door |
| 57 | + internal: true |
| 58 | + pin: |
| 59 | + number: D3 |
| 60 | + mode: INPUT_PULLUP |
| 61 | + filters: |
| 62 | + - invert: |
| 63 | + - delayed_on: 1000ms # Wait to stop moving (1000ms for mechanical, higher for magnetic - depending on magnet strength) |
| 64 | + - delayed_off: 1000ms # Wait to start moving (1000ms for mechanical, higher for magnetic - depending on magnet strength) |
| 65 | + |
| 66 | + - platform: gpio |
| 67 | + id: closed_endstop |
| 68 | + name: "Closed Endstop" |
| 69 | + device_class: garage_door |
| 70 | + internal: true |
| 71 | + pin: |
| 72 | + number: D2 |
| 73 | + mode: INPUT_PULLUP |
| 74 | + filters: |
| 75 | + - invert: |
| 76 | + - delayed_on: 1000ms # Wait to stop moving (1000ms for mechanical, higher for magnetic - depending on magnet strength) |
| 77 | + - delayed_off: 1000ms # Wait to start moving (1000ms for mechanical, higher for magnetic - depending on magnet strength) |
| 78 | + |
| 79 | +cover: |
| 80 | + - platform: template |
| 81 | + name: "Carport Door" |
| 82 | + id: carport_door |
| 83 | + device_class: garage |
| 84 | + assumed_state: true |
| 85 | + lambda: !lambda |- |
| 86 | + if (id(closed_endstop).state) // Door at closed endstop |
| 87 | + { |
| 88 | + if (id(carport_door).current_operation == esphome::cover::COVER_OPERATION_OPENING) // We should be opening |
| 89 | + { |
| 90 | + if (!id(performing_last_movement)) // Make sure we don't trigger this logic twice otherwise it will do unwanted things |
| 91 | + { |
| 92 | + delay(1000); // Wait for door to stop in case reed is triggered too early |
| 93 | + id(garage_door_relay).turn_on(); // Press button again |
| 94 | + id(performing_last_movement) = true; // Set flag to indicate we madeknow where the door is |
| 95 | + } |
| 96 | + } |
| 97 | + else if (id(carport_door).current_operation == esphome::cover::COVER_OPERATION_CLOSING) |
| 98 | + { |
| 99 | + // We should be closing, so all is good |
| 100 | + id(performing_last_movement) = false; |
| 101 | + id(carport_door).current_operation = esphome::cover::COVER_OPERATION_IDLE; |
| 102 | + id(carport_door).position = COVER_CLOSED; |
| 103 | + id(carport_door).publish_state(); |
| 104 | + return COVER_CLOSED; |
| 105 | + } |
| 106 | + else |
| 107 | + { |
| 108 | + // No operation in progress, just send state |
| 109 | + id(performing_last_movement) = false; |
| 110 | + if ((!id(carport_door).position) == esphome::cover::COVER_CLOSED) |
| 111 | + { |
| 112 | + id(carport_door).position = COVER_CLOSED; |
| 113 | + id(carport_door).publish_state(); |
| 114 | + return COVER_CLOSED; |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + else if (id(open_endstop).state) // Door at open endstop |
| 119 | + { |
| 120 | + if (id(carport_door).current_operation == esphome::cover::COVER_OPERATION_CLOSING) // We should be closing |
| 121 | + { |
| 122 | + if (!id(performing_last_movement)) // Make sure we don't trigger this logic twice otherwise it will do unwanted things |
| 123 | + { |
| 124 | + delay(1000); // Wait for door to stop in case reed is triggered too early |
| 125 | + id(garage_door_relay).turn_on(); // Press button again |
| 126 | + id(performing_last_movement) = true; // Set flag to indicate we madeknow where the door is |
| 127 | + } |
| 128 | + } |
| 129 | + else if (id(carport_door).current_operation == esphome::cover::COVER_OPERATION_OPENING) |
| 130 | + { |
| 131 | + // We should be opening, so all is good |
| 132 | + id(performing_last_movement) = false; |
| 133 | + id(carport_door).current_operation = esphome::cover::COVER_OPERATION_IDLE; |
| 134 | + id(carport_door).position = COVER_OPEN; |
| 135 | + id(carport_door).publish_state(); |
| 136 | + return COVER_OPEN; |
| 137 | + } |
| 138 | + else // Door not at any endstop |
| 139 | + { |
| 140 | + // No operation in progress, just send state |
| 141 | + id(performing_last_movement) = false; |
| 142 | + if (id(carport_door).position != esphome::cover::COVER_OPEN) |
| 143 | + { |
| 144 | + id(carport_door).position = COVER_OPEN; |
| 145 | + id(carport_door).publish_state(); |
| 146 | + return COVER_OPEN; |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | + else |
| 151 | + { |
| 152 | + // The door is halfway open, so set it to OPEN |
| 153 | + if (id(carport_door).position != esphome::cover::COVER_OPEN) |
| 154 | + { |
| 155 | + id(carport_door).position = COVER_OPEN; |
| 156 | + id(carport_door).publish_state(); |
| 157 | + return COVER_OPEN; |
| 158 | + } |
| 159 | + } |
| 160 | + return {}; |
| 161 | + open_action: |
| 162 | + - lambda: !lambda |- |
| 163 | + id(carport_door).current_operation = esphome::cover::COVER_OPERATION_OPENING; |
| 164 | + if (!id(open_endstop).state) { |
| 165 | + id(garage_door_relay).turn_on(); |
| 166 | + if (id(closed_endstop).state) { |
| 167 | + id(performing_last_movement) = true; // Set flag to indicate we know where the door is |
| 168 | + } |
| 169 | + } |
| 170 | + close_action: |
| 171 | + - lambda: !lambda |- |
| 172 | + id(carport_door).current_operation = esphome::cover::COVER_OPERATION_CLOSING; |
| 173 | + if (!id(closed_endstop).state) { |
| 174 | + id(garage_door_relay).turn_on(); |
| 175 | + if (id(open_endstop).state) { |
| 176 | + id(performing_last_movement) = true; // Set flag to indicate we know where the door is |
| 177 | + } |
| 178 | + } |
| 179 | + stop_action: |
| 180 | + - lambda: !lambda |- |
| 181 | + if (id(carport_door).current_operation == esphome::cover::COVER_OPERATION_CLOSING || |
| 182 | + id(carport_door).current_operation == esphome::cover::COVER_OPERATION_OPENING) |
| 183 | + { |
| 184 | + id(carport_door).current_operation = esphome::cover::COVER_OPERATION_IDLE; |
| 185 | + // Stop the door if it is moving |
| 186 | + id(performing_last_movement) = false; |
| 187 | + id(garage_door_relay).turn_on(); |
| 188 | + } |
0 commit comments