forked from mjoshd/esphome_martin-jerry-mj-sd01-dimmer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
martin_jerry_mj_sd01_dimmer.yaml
245 lines (209 loc) · 6.44 KB
/
martin_jerry_mj_sd01_dimmer.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
234
235
236
237
238
239
240
241
242
243
244
245
# ##################################
# Martin Jerry Dimmer MJ-SD01
# ##################################
# D3 GPIO0: up button (inverted, input_pullup)
# TX GPIO1: down button (inverted, input_pullup)
# RX GPIO3: led5 (inverted)
# D2 GPIO4: red led (inverted)
# D1 GPIO5: led4 (inverted)
# D6 GPIO12: led3 (inverted)
# D7 GPIO13: pwm
# D5 GPIO14: led2 (inverted)
# D8 GPIO15: main button (input_pullup)
# D0 GPIO16: blue led + relay + led1 (inverted)
# ##################################
substitutions:
# https://esphome.io/guides/configuration-types.html#substitutions
device_name: martin_jerry_mj_sd01 # hostname & entity_id
friendly_name: Martin Jerry MJ-SD01 # Displayed in HA frontend
pwm_min_power: 15% # keep dimming functional at lowest levels
no_delay: 0s # transition when changing dimmer_lvl & relay delay
transition_length: .5s # transition when turning on/off
long_press_min: .4s # minimum time to activate long-press action
long_press_max: 3s # maximum time to activate long-press action
long_press_up: 100% # long press brightness
long_press_down: 58% # long press brightness
long_press_main: 30% # long press brightness
ip_address: !secret martin_jerry_mj_sd01_ip # use /config/esphome/secrets.yaml
esphome:
# https://esphome.io/components/esphome
name: ${device_name}
platform: ESP8266
board: esp01_1m
wifi:
# https://esphome.io/components/wifi
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: ${ip_address}
gateway: !secret wifi_gateway
subnet: !secret wifi_subnet
dns1: !secret wifi_dns1
# web_server:
# port: 80
# # https://esphome.io/components/web_server.html
logger:
# https://esphome.io/components/logger
api:
password: !secret esphome_api_password
# https://esphome.io/components/api
ota:
password: !secret esphome_ota_password
# https://esphome.io/components/ota
status_led:
# https://esphome.io/components/status_led
pin:
number: GPIO4 # Red LED
inverted: True
output:
- platform: gpio
# https://esphome.io/components/output/gpio.html
pin: GPIO3
inverted: true
id: led5
- platform: gpio
# https://esphome.io/components/output/gpio.html
pin: GPIO5
inverted: true
id: led4
- platform: gpio
# https://esphome.io/components/output/gpio.html
pin: GPIO12
inverted: true
id: led3
- platform: gpio
# https://esphome.io/components/output/gpio.html
pin: GPIO14
inverted: true
id: led2
- platform: esp8266_pwm
# https://esphome.io/components/output/index.html#config-output
pin: GPIO13
id: pwm
power_supply: relay
min_power: ${pwm_min_power}
light:
- platform: monochromatic
# https://esphome.io/components/light/monochromatic.html
name: ${friendly_name}
output: pwm
default_transition_length: ${no_delay}
id: dimmer
power_supply:
- id: relay
# https://esphome.io/components/power_supply.html
pin:
number: GPIO16
inverted: True
enable_time: ${no_delay}
keep_on_time: ${no_delay}
binary_sensor:
- platform: gpio
# https://esphome.io/components/binary_sensor/gpio.html
pin:
number: GPIO0
inverted: True
mode: INPUT_PULLUP
name: ${friendly_name} Up Button
id: up_button
internal: True
on_release:
then:
- lambda: |-
if (id(dimmer_lvl) > .91) {
id(dimmer_lvl) = 1.0;
}
else if (id(dimmer_lvl) <= .91) {
id(dimmer_lvl) += .083;
};
id(apply_dimming).execute();
on_click:
# https://esphome.io/components/binary_sensor/index.html#on-click
min_length: ${long_press_min}
max_length: ${long_press_max}
then:
- light.turn_on:
id: dimmer
brightness: ${long_press_up}
- platform: gpio
# https://esphome.io/components/binary_sensor/gpio.html
pin:
number: GPIO1
inverted: True
mode: INPUT_PULLUP
name: ${friendly_name} Down Button
internal: True
on_release:
then:
- lambda: !lambda |-
if (id(dimmer_lvl) < .10) {
id(dimmer_lvl) = .01;
}
else if (id(dimmer_lvl) >= .10) {
id(dimmer_lvl) -= .083;
};
id(apply_dimming).execute();
on_click:
# https://esphome.io/components/binary_sensor/index.html#on-click
min_length: ${long_press_min}
max_length: ${long_press_max}
then:
- light.turn_on:
id: dimmer
brightness: ${long_press_down}
- platform: gpio
# https://esphome.io/components/binary_sensor/gpio.html
pin:
number: GPIO15
mode: INPUT_PULLUP
name: ${friendly_name} Main Button
internal: True
on_release:
- light.toggle: dimmer
on_click:
# https://esphome.io/components/binary_sensor/index.html#on-click
min_length: ${long_press_min}
max_length: ${long_press_max}
then:
- light.turn_on:
id: dimmer
brightness: ${long_press_main}
globals:
- id: dimmer_lvl
# https://esphome.io/guides/automations.html#bonus-2-global-variables
type: float
restore_value: no
initial_value: '1.0'
script:
- id: apply_dimming
# https://esphome.io/guides/automations.html#script-execute-action
then:
- lambda: |-
auto call = id(dimmer).turn_on();
call.set_brightness(id(dimmer_lvl));
call.perform();
- logger.log:
format: "dimmer_lvl = %.2f"
args: ['id(dimmer_lvl)']
interval:
- interval: 250ms
# https://esphome.io/guides/automations.html#interval
then:
- lambda: |-
auto dimmer_vals = id(dimmer).current_values;
if (dimmer_vals.is_on()) {
id(dimmer_lvl) = dimmer_vals.get_brightness();
if (id(dimmer_lvl) > .19) { id(led2).turn_on(); }
if (id(dimmer_lvl) < .20) { id(led2).turn_off(); }
if (id(dimmer_lvl) > .39) { id(led3).turn_on(); }
if (id(dimmer_lvl) < .40) { id(led3).turn_off(); }
if (id(dimmer_lvl) > .59) { id(led4).turn_on(); }
if (id(dimmer_lvl) < .60) { id(led4).turn_off(); }
if (id(dimmer_lvl) > .79) { id(led5).turn_on(); }
if (id(dimmer_lvl) < .80) { id(led5).turn_off(); }
} else {
id(led2).turn_off();
id(led3).turn_off();
id(led4).turn_off();
id(led5).turn_off();
}