-
Notifications
You must be signed in to change notification settings - Fork 0
/
hub.yaml
321 lines (292 loc) · 8.11 KB
/
hub.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
substitutions:
devicename: hub
comment: ""
light_address_1: "{0x50,0x02,0x92,0x3F,0xF7,0x2F}"
light_address_2: "{0x70,0x03,0x9F,0xD0,0x49,0xE6}"
esphome:
name: $devicename
comment: $comment
platform: ESP8266
board: d1_mini
includes:
- lib/MeshRC.h
- lib/esp_now_light.h
# Enable logging
logger:
# Enable Home Assistant API
api:
password: ""
ota:
password: ""
web_server:
port: 80
wifi:
ssid: !wifi_ssid
password: !wifi_password
# Enable fallback hotspot in case wifi connection fails
ap:
power_save_mode: none
globals:
- id: my_global_int
type: int
restore_value: no
initial_value: '0'
sensor:
- platform: wifi_signal
name: $devicename Wifi Signal Strength
update_interval: 60s
- platform: uptime
name: $devicename Uptime
# Individual text sensors
text_sensor:
# Reports the ESPHome Version with compile date
- platform: version
name: $devicename ESPHome Version
##Device Specific Config
binary_sensor:
- platform: gpio
pin:
number: D8
mode: INPUT_PULLUP
inverted: True
name: "Ceiling Lights"
on_multi_click:
#single click
- timing:
- ON for at most 1s
- OFF for at least 0.3s
then:
- if:
condition:
- wifi.connected:
- api.connected:
- switch.is_on: relay_1
then:
- logger.log: "Single Click"
- homeassistant.service:
service: light.toggle
data:
entity_id: light.living_room_lights_prime
# - homeassistant.event: esphome.button_pressed # action when api is connected
else:
# - logger.log: "No api connection - let's solve things locally"
- switch.toggle: "relay_1"
#double click
- timing:
- ON for at most 1s
- OFF for at most 1s
- ON for at most 1s
- OFF for at least 0.2s
then:
- if:
condition:
and:
- wifi.connected:
- api.connected:
# send double click event in case wifi and api are conncected
then:
- logger.log: "Double Click"
- homeassistant.event:
event: esphome.button_pressed
data:
title: 4g button 1 double click
# toggle relay in case either wifi or api are not connected
else:
- switch.toggle: "relay_1"
# long click
- timing:
- ON for at least 1s
then:
- if:
condition:
and:
- wifi.connected:
- api.connected:
# send long click event in case wifi and api are conncected
then:
- logger.log: "Long Click"
- homeassistant.event:
event: esphome.button_pressed
data:
title: 4g button 1 long click
# toggle relay in case either wifi or api are not connected
else:
- switch.toggle: "relay_1"
# release
- timing:
- ON for at least 1s
- OFF for at least 0.1s
then:
- if:
condition:
and:
- wifi.connected:
- api.connected:
# send long click event in case wifi and api are conncected
then:
- logger.log: "Release"
- homeassistant.event:
event: esphome.button_pressed
data:
title: 4g button 1 release
# toggle relay in case either wifi or api are not connected
else:
- switch.toggle: "relay_1"
- platform: gpio
pin:
number: D10
mode: INPUT_PULLUP
inverted: True
name: "Night Lamp"
on_click:
- switch.toggle: "relay_2"
- platform: gpio
pin:
number: D12
mode: INPUT_PULLUP
inverted: True
name: "Living Room Fan"
on_click:
- switch.toggle: "relay_3"
- platform: gpio
pin:
number: D14
mode: INPUT_PULLUP
inverted: True
name: "Tuya Button 4"
on_click:
- switch.toggle: "relay_4"
switch:
- platform: gpio
name: "Relay 1"
pin: D4
id: "relay_1"
- platform: gpio
name: "Relay 2"
pin: D3
id: "relay_2"
- platform: gpio
name: "Relay 3"
pin: D2
id: "relay_3"
- platform: gpio
name: "Relay 4"
pin: D17
id: "relay_4"
light:
- platform: status_led
id: led_red
name: LED Backlight
restore_mode: ALWAYS_ON
entity_category: config
pin:
number: D16
light:
- platform: custom
lambda: |-
uint8_t light_address_1[6] = ${light_address_1};
uint8_t light_address_2[6] = ${light_address_2};
auto light_out_1 = new esp_now_light_RGB(light_address_1,1);
auto light_out_2 = new esp_now_light_RGB(light_address_2,1);
light_out_1->set_power_supply(id(power_supply1));
light_out_2->set_power_supply(id(power_supply1));
App.register_component(light_out_1);
App.register_component(light_out_2);
return {light_out_1, light_out_2};
lights:
- name: "Custom Light 1"
effects:
- automation:
name: "My Slow Random Effect"
sequence:
lambda: ;
- automation:
name: "My Fast Random Effect"
sequence:
lambda: ;
- name: "Custom Light 2"
effects:
- automation:
name: "My Slow Random Effect"
sequence:
lambda: ;
- automation:
name: "My Fast Random Effect"
sequence:
lambda: ;
sensor:
- platform: wifi_signal
name: ${devicename} WiFi Signal Sensor
unit_of_measurement: "%"
filters:
- lambda: |-
if(x <= -100){
return 0;
} else if (x >= -50) {
return 100;
} else {
return 2 * (x + 100);
}
script:
- id: light_status_script_1
mode: restart
then:
- binary_sensor.template.publish:
id: status_1
state: ON
- delay: 30s
- binary_sensor.template.publish:
id: status_1
state: OFF
- id: light_status_script_2
mode: restart
then:
- binary_sensor.template.publish:
id: status_2
state: ON
- delay: 30s
- binary_sensor.template.publish:
id: status_2
state: OFF
binary_sensor:
- platform: template
name: "${devicename} Light 1 Status"
id: status_1
device_class: connectivity
- platform: template
name: "${devicename} Light 2 Status"
id: status_2
device_class: connectivity
custom_component:
- lambda: |-
MeshRC::begin();
ESP_LOGD("custom", "Initialising MeshRC");
MeshRC::on("", [](uint8_t* data, uint8_t size) {
// Process an incomming message, if it is directed to us, then we handle it.
ESP_LOGD("custom", "Receiving any MeshRC message");
uint8_t dest_1[6] = ${light_address_1};
uint8_t dest_2[6] = ${light_address_2};
if (size > 6 && MeshRC::equals(data, dest_1, 6) && (data[6] == '<')) {
// Message on the communication channel with light_address_1
uint8_t* newData = &data[5];
ESP_LOGD("custom", "Receiving meshRC message");
newData[0] = '1';
MeshRC::recvHandler(MeshRC::sender, newData, size - 5);
}
else if (size > 6 && MeshRC::equals(data, dest_2, 6) && (data[6] == '<')) {
// Message on the communication channel with light_address_2
uint8_t* newData = &data[5];
ESP_LOGD("custom", "Receiving meshRC message");
newData[0] = '2';
MeshRC::recvHandler(MeshRC::sender, newData, size - 5);
}
});
MeshRC::on("1<PING", [](uint8_t* data, uint8_t size) {
ESP_LOGD("custom", "Receiving meshRC message PING on 1");
id(light_status_script_2).execute();
});
MeshRC::on("2<PING", [](uint8_t* data, uint8_t size) {
ESP_LOGD("custom", "Receiving meshRC message PING on 2");
id(light_status_script_2).execute();
});
return {};