-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightswitch_gang.yaml
208 lines (192 loc) · 6.05 KB
/
lightswitch_gang.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
esphome:
name: lightswitch_gang
platform: ESP8266
board: d1_mini
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Lightswitch Gang"
password: "VbudZoqZp5ua"
captive_portal:
status_led:
pin:
number: D4
inverted: True
# Enable logging
logger:
# Enable Home Assistant API
api:
services:
- service: control_gang_on
variables:
level: float
then:
- servo.write:
id: gang_on
level: !lambda 'return level / 100.0;'
- service: control_gang_off
variables:
level: float
then:
- servo.write:
id: gang_off
level: !lambda 'return level / 100.0;'
- service: control_soverom_on
variables:
level: float
then:
- servo.write:
id: soverom_on
level: !lambda 'return level / 100.0;'
- service: control_soverom_off
variables:
level: float
then:
- servo.write:
id: soverom_off
level: !lambda 'return level / 100.0;'
ota:
web_server:
port: 80
globals: #Global variable, see on_turn_on in lights for further explaination
- id: is_last_gang_lys_state_on
type: bool
restore_value: "yes"
initial_value: "false"
- id: is_last_soverom_lys_state_on
type: bool
restore_value: "yes"
initial_value: "false"
light:
- platform: binary
name: "Gang taklys"
id: gang_taklys
output: mock #Output is required, this output is not used
on_turn_on:
then:
- if: #Ensures that the lights havent been turned off already. Prevents scenes/automations from triggering servo when lights are already turned on
condition: #Need to use global variable since on_turn_on changes the state before this code will run
lambda: |-
if(!id(is_last_gang_lys_state_on)) {
id(is_last_gang_lys_state_on) = true;
return true;
}
return false;
then:
- script.stop: turn_on_power_supply_pin_for_short_duration #Stop is used to cancel any possible running scripts, which could cause the power pin to shut of prematurely
- script.execute: turn_on_power_supply_pin_for_short_duration
- logger.log: "Light is being turned on"
- servo.write:
id: gang_on
level: 45%
- delay: 500ms
- servo.write:
id: gang_on
level: -100%
on_turn_off:
then:
- if:
condition: #See turn on for explaination
lambda: |-
if(id(is_last_gang_lys_state_on)) {
id(is_last_gang_lys_state_on) = false;
return true;
}
return false;
then:
- script.stop: turn_on_power_supply_pin_for_short_duration
- script.execute: turn_on_power_supply_pin_for_short_duration
- logger.log: "Light is being turned off"
- servo.write:
id: gang_off
level: -44%
- delay: 500ms
- servo.write:
id: gang_off
level: 100%
- platform: binary
name: "Soverom taklys"
id: soverom_taklys
output: mock #Output is required, this output is not used
on_turn_on:
then:
- if: #Ensures that the lights havent been turned off already. Prevents scenes/automations from triggering servo when lights are already turned on
condition: #Need to use global variable since on_turn_on changes the state before this code will run
lambda: |-
if(!id(is_last_soverom_lys_state_on)) {
id(is_last_soverom_lys_state_on) = true;
return true;
}
return false;
then:
- script.stop: turn_on_power_supply_pin_for_short_duration
- script.execute: turn_on_power_supply_pin_for_short_duration
- logger.log: "Light is being turned on"
- servo.write:
id: soverom_on
level: -44%
- delay: 500ms
- servo.write:
id: soverom_on
level: 100%
on_turn_off:
then:
- if:
condition: #See turn on for explaination
lambda: |-
if(id(is_last_soverom_lys_state_on)) {
id(is_last_soverom_lys_state_on) = false;
return true;
}
return false;
then:
- script.stop: turn_on_power_supply_pin_for_short_duration
- script.execute: turn_on_power_supply_pin_for_short_duration
- logger.log: "Light is being turned off"
- servo.write:
id: soverom_off
level: 45%
- delay: 500ms
- servo.write:
id: soverom_off
level: -100%
script:
- id: turn_on_power_supply_pin_for_short_duration
then:
- output.turn_on: power_supply_pin
- delay: 1200ms
- output.turn_off: power_supply_pin
servo:
- id: gang_on
output: pwm_gang_on
- id: gang_off
output: pwm_gang_off
- id: soverom_on
output: pwm_soverom_on
- id: soverom_off
output: pwm_soverom_off
output:
- platform: esp8266_pwm
id: pwm_gang_on
pin: D5 #Be careful when using other pins, some will make the ESP fail to boot.
frequency: 50 Hz
- platform: esp8266_pwm
id: pwm_gang_off
pin: D6
frequency: 50 Hz
- platform: esp8266_pwm
id: pwm_soverom_on
pin: D7
frequency: 50 Hz
- platform: esp8266_pwm
id: pwm_soverom_off
pin: D2
frequency: 50 Hz
- platform: gpio
id: mock
pin: D3
- platform: gpio
id: power_supply_pin
pin: D1 #Not all pins work for this, using D3 causes the pin to turn on during boot. D2 should also work