-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesphome_blinds.yaml
233 lines (215 loc) · 7.16 KB
/
esphome_blinds.yaml
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
esphome:
name: newblinds
platform: ESP32
board: esp32dev
on_boot:
then:
- script.execute: consider_deep_sleep
# - priority: -200.0
# then:
# - stepper.report_position: # Set stepper to global variable
# id: stepper_motor
# position: !lambda return id(stepper_motor_global);
# - stepper.set_target: # Set stepper to global variable
# id: stepper_motor
# target: !lambda return id(stepper_motor_global);
# - if: # If blind is Closed
# condition:
# - lambda: 'return id(stepper_motor_global) == 0;'
# then: # Publish state etc.
# - cover.template.publish:
# id: office_tilt
# state: CLOSED
# current_operation: IDLE
# - if: # If blind is Open
# condition:
# - lambda: 'return id(stepper_motor_global) == id(endstop);'
# then: # Publish state etc.
# - cover.template.publish:
# id: office_tilt
# state: OPEN
# current_operation: IDLE
# - if: # If blind is Neither
# condition:
# - lambda: 'return (id(stepper_motor_global) != 0) && (id(stepper_motor_global) != id(endstop));'
# then: # # Publish state etc.
# - cover.template.publish:
# id: office_tilt
# position: !lambda 'return (float(float(id(stepper_motor).current_position) / float(id(endstop))));'
# current_operation: IDLE
# Enable logging
logger:
# Enable Home Assistant API
api:
password: !secret password
ota:
password: !secret ota
wifi:
ssid: !secret ssid
password: !secret password
fast_connect: true
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Office-Room-Blinds"
password: !secret password
captive_portal:
web_server:
port: 80
globals:
- id: stepper_motor_global # Integer for storing the stepper position in case of reboot
type: int
restore_value: True
initial_value: '0'
- id: openclosed # Boolean to store OPEN/CLOSED state
type: bool
restore_value: True
initial_value: '0'
- id: endstop # Variable for storing ENDSTOP (how far to move stepper)
type: int
restore_value: True
initial_value: '1800' # this is the max value
binary_sensor:
- platform: homeassistant
id: prevent_deep_sleep
entity_id: input_boolean.prevent_deep_sleep
on_state:
then:
if:
condition:
binary_sensor.is_off: prevent_deep_sleep
then:
deep_sleep.enter: deep_sleep_control
switch:
- platform: restart
name: "Kids Blinds Restart"
- platform: gpio
name: "blind relay"
id: relay
restore_mode: ALWAYS_OFF
pin:
number: 5
deep_sleep:
id: deep_sleep_control
sleep_duration: 10min
script:
- id: consider_deep_sleep
mode: queued
then:
- delay: 15s
- if:
condition:
binary_sensor.is_on: prevent_deep_sleep
then:
- deep_sleep.prevent: deep_sleep_control
- logger.log: 'Skipping sleep, per prevent_deep_sleep'
- delay: 1440min
else:
- deep_sleep.enter: deep_sleep_control
- script.execute: consider_deep_sleep
stepper:
- platform: a4988
id: stepper_motor
step_pin: 16
dir_pin:
number: 17
inverted: true
sleep_pin:
number: 19
max_speed: 700 steps/s
acceleration: inf
deceleration: inf
cover:
- platform: template
name: Office Room Blinds
id: office_tilt
open_action:
then:
- switch.turn_on: relay
- logger.log: "Opening"
- stepper.set_target:
id: stepper_motor
target: 800
- while:
condition:
lambda: 'return id(stepper_motor).current_position > 800;'
then:
- cover.template.publish:
id: office_tilt
position: !lambda 'return (float(float(id(stepper_motor).current_position) / float(id(endstop))));'
current_operation: OPENING
- delay: 1500 ms
- globals.set: # Set global to current position
id: stepper_motor_global
value: !lambda return id(stepper_motor).current_position;
- globals.set: # Set toggle to OPEN (No need for 'optimistic mode')
id: openclosed
value: '1'
- cover.template.publish:
id: office_tilt
state: OPEN
current_operation: IDLE
- switch.turn_off: relay
close_action:
then:
- switch.turn_on: relay
- logger.log: "Closing"
- stepper.set_target: # Send stepper to 0
id: stepper_motor
target: '1800'
- while:
condition:
lambda: 'return id(stepper_motor).current_position < 1800;'
then:
- cover.template.publish:
id: office_tilt
position: !lambda 'return (float(float(id(stepper_motor).current_position) / float(id(endstop))));'
current_operation: CLOSING
- delay: 1500 ms
- globals.set: # Set global to current position
id: stepper_motor_global
value: !lambda return id(stepper_motor).current_position;
- globals.set: # Set toggle to CLOSED (No need for 'optimistic mode')
id: openclosed
value: '0'
- cover.template.publish:
id: office_tilt
state: CLOSED
current_operation: IDLE
- switch.turn_off: relay
position_action:
then:
- switch.turn_on: relay
- stepper.set_target:
id: stepper_motor
target: !lambda return int(id(endstop) * pos);
- while:
condition:
lambda: 'return id(stepper_motor).current_position != int(id(endstop) * pos);'
then:
- cover.template.publish:
id: office_tilt
position: !lambda 'return (float(float(id(stepper_motor).current_position) / float(id(endstop))));'
- delay: 1500 ms
- globals.set: # Set global to current position
id: stepper_motor_global
value: !lambda return id(stepper_motor).current_position;
- cover.template.publish:
id: office_tilt
position: !lambda 'return (float(float(id(stepper_motor).current_position) / float(id(endstop))));'
current_operation: IDLE
- switch.turn_off: relay
stop_action:
then:
- switch.turn_off: relay
- stepper.set_target:
id: stepper_motor
target: !lambda return id(stepper_motor).current_position;
- globals.set: # Set global to current position
id: stepper_motor_global
value: !lambda return id(stepper_motor).current_position;
- cover.template.publish:
id: office_tilt
position: !lambda 'return (float(float(id(stepper_motor).current_position) / float(id(endstop))));'
current_operation: IDLE
has_position: true
device_class: blind