-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathESPHome.yml
173 lines (162 loc) · 5.94 KB
/
ESPHome.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
esphome:
name: garage_door
platform: ESP8266
board: d1_mini
wifi:
ssid: "XXXXXXXXX"
password: "XXXXXXXXX"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Garage Door Fallback Hotspot"
password: "XXXXXXXXX"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
globals:
- id: performing_last_movement
type: boolean
restore_value: no
initial_value: 'false'
switch:
# The switch that turns the UP direction on
- platform: gpio
pin: D1
id: garage_switch
# If ESP reboots, do not attempt to restore switch state
restore_mode: ALWAYS_OFF
on_turn_on:
- delay: 500ms
- switch.turn_off: garage_switch
binary_sensor:
- platform: gpio
pin:
number: D5
mode: INPUT_PULLUP
inverted: true
name: "Garage Closed Reed Switch"
id: closed_endstop
filters:
- delayed_on: 1000ms #Wait to stop moving (1000ms for mechanical, higher for magnetic - depending on magnet strength)
- delayed_off: 1000ms #Wait to start moving (1000ms for mechanical, higher for magnetic - depending on magnet strength)
- platform: gpio
pin:
number: D6
mode: INPUT_PULLUP
inverted: true
name: "Garage Open Reed Switch"
id: open_endstop
filters:
- delayed_on: 1000ms #Wait to stop moving (1000ms for mechanical, higher for magnetic - depending on magnet strength)
- delayed_off: 1000ms #Wait to start moving (1000ms for mechanical, higher for magnetic - depending on magnet strength)
cover:
- platform: template
name: "Garage Door"
id: garage_door
device_class: garage
assumed_state: true
lambda: !lambda |-
if (id(closed_endstop).state) //Door at closed endstop
{
if (id(garage_door).current_operation == esphome::cover::COVER_OPERATION_OPENING) //We should be opening
{
if (!id(performing_last_movement)) //Make sure we don't trigger this logic twice otherwise it will do unwanted things
{
delay(1000); //Wait for door to stop in case reed is triggered too early
id(garage_switch).turn_on(); //Press button again
id(performing_last_movement) = true; //Set flag to indicate we madeknow where the door is
}
}
else if (id(garage_door).current_operation == esphome::cover::COVER_OPERATION_CLOSING)
{
//We should be closing, so all is good
id(performing_last_movement) = false;
id(garage_door).current_operation = esphome::cover::COVER_OPERATION_IDLE;
id(garage_door).position = COVER_CLOSED;
id(garage_door).publish_state();
return COVER_CLOSED;
}
else
{
//No operation in progress, just send state
id(performing_last_movement) = false;
if (!id(garage_door).position == esphome::cover::COVER_CLOSED)
{
id(garage_door).position = COVER_CLOSED;
id(garage_door).publish_state();
return COVER_CLOSED;
}
}
}
else if (id(open_endstop).state) //Door at open endstop
{
if (id(garage_door).current_operation == esphome::cover::COVER_OPERATION_CLOSING) //We should be closing
{
if (!id(performing_last_movement)) //Make sure we don't trigger this logic twice otherwise it will do unwanted things
{
delay(1000); //Wait for door to stop in case reed is triggered too early
id(garage_switch).turn_on(); //Press button again
id(performing_last_movement) = true; //Set flag to indicate we madeknow where the door is
}
}
else if (id(garage_door).current_operation == esphome::cover::COVER_OPERATION_OPENING)
{
//We should be opening, so all is good
id(performing_last_movement) = false;
id(garage_door).current_operation = esphome::cover::COVER_OPERATION_IDLE;
id(garage_door).position = COVER_OPEN;
id(garage_door).publish_state();
return COVER_OPEN;
}
else //Door not at any endstop
{
//No operation in progress, just send state
id(performing_last_movement) = false;
if (id(garage_door).position != esphome::cover::COVER_OPEN)
{
id(garage_door).position = COVER_OPEN;
id(garage_door).publish_state();
return COVER_OPEN;
}
}
}
else
{
//The door is halfway open, so set it to OPEN
if (id(garage_door).position != esphome::cover::COVER_OPEN)
{
id(garage_door).position = COVER_OPEN;
id(garage_door).publish_state();
return COVER_OPEN;
}
}
return {};
open_action:
- lambda: !lambda |-
id(garage_door).current_operation = esphome::cover::COVER_OPERATION_OPENING;
if (!id(open_endstop).state) {
id(garage_switch).turn_on();
if (id(closed_endstop).state) {
id(performing_last_movement) = true; //Set flag to indicate we know where the door is
}
}
close_action:
- lambda: !lambda |-
id(garage_door).current_operation = esphome::cover::COVER_OPERATION_CLOSING;
if (!id(closed_endstop).state) {
id(garage_switch).turn_on();
if (id(open_endstop).state) {
id(performing_last_movement) = true; //Set flag to indicate we know where the door is
}
}
stop_action:
- lambda: !lambda |-
if (id(garage_door).current_operation == esphome::cover::COVER_OPERATION_CLOSING || id(garage_door).current_operation == esphome::cover::COVER_OPERATION_OPENING )
{
id(garage_door).current_operation = esphome::cover::COVER_OPERATION_IDLE;
//Stop the door if it is moving
id(performing_last_movement) = false;
id(garage_switch).turn_on();
}