-
Notifications
You must be signed in to change notification settings - Fork 0
/
.led_mirror_base.yaml
181 lines (171 loc) · 5.37 KB
/
.led_mirror_base.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
esphome:
name: ${device_name}
platform: ESP8266
board: esp8285
platformio_options:
board_build.flash_size: 2M
# libraries:
# - https://github.com/JoDaNl/esp8266_ws2812_i2s
# includes:
# - includes/ws2812_custom_light.h
globals:
- id: led_increasing_brightness
type: bool
restore_value: no
initial_value: 'false'
- id: led_brightness
type: float
restore_value: no
initial_value: '0.3'
- id: maximum_brightness
type: float
restore_value: no
initial_value: '1.0'
- id: stop
type: bool
restore_value: no
initial_value: 'false'
packages:
device_common: !include .device_common.yaml
logger:
level: DEBUG
baud_rate: 0
status_led:
pin:
number: GPIO2
inverted: yes
script:
- id: set_maximum_brightness
then:
- if:
condition:
sun.is_above_horizon
then:
- globals.set:
id: maximum_brightness
value: '1.0'
else:
- globals.set:
id: maximum_brightness
value: '0.6'
time:
- id: !extend sntp_time
on_time_sync:
- script.execute: set_maximum_brightness
sun:
id: sun_id
latitude: !secret gps_latitude
longitude: !secret gps_longitude
on_sunrise:
then:
- script.execute: set_maximum_brightness
on_sunset:
then:
- script.execute: set_maximum_brightness
output:
- platform: esp8266_pwm
id: pwm_led_output
pin: GPIO4
light:
- platform: monochromatic
id: ${device_name_underscore}_led
name: "${device_name} Led"
output: pwm_led_output
default_transition_length: 300ms
on_turn_off:
- light.turn_on:
id: button_led
red: 100%
green: 100%
blue: 100%
brightness: 100%
transition_length: 200ms
on_turn_on:
- light.turn_on:
id: button_led
red: 0%
green: 0%
blue: 100%
brightness: 100%
transition_length: 200ms
- platform: neopixelbus
id: button_led
num_leds: 1
pin: GPIO3
type: GRB
variant: ws2812
#internal: true
binary_sensor:
- platform: gpio
id: ttp223_button
pin: GPIO12
internal: true
filters:
- delayed_on: 50ms
- delayed_off: 50ms
on_click:
then:
- if:
condition:
light.is_off: "${device_name_underscore}_led"
then:
- lambda: |-
id(led_brightness) = id(maximum_brightness);
ESP_LOGD("main", "Global value brightness is: %f", id(led_brightness));
id(led_increasing_brightness) = (false);
- light.turn_on:
id: "${device_name_underscore}_led"
brightness: !lambda |-
return id(led_brightness);
else:
- light.turn_off: "${device_name_underscore}_led"
on_press:
then:
- delay: 700ms
- if:
condition:
# check if button is still pressed
binary_sensor.is_on: ttp223_button
then:
- while:
condition:
and:
# continue while the button is still pressed and not stop
- binary_sensor.is_on: ttp223_button
- lambda: return !id(stop);
then:
- if:
condition:
lambda: |-
return id(led_increasing_brightness);
then:
- light.dim_relative:
id: "${device_name_underscore}_led"
relative_brightness: 2%
transition_length: 100ms
- delay: 50ms
- lambda: |-
id(led_brightness) = id(${device_name_underscore}_led).current_values.get_brightness();
ESP_LOGD("main", "+Global value is: %f", id(led_brightness));
// invert dim direction if full on
if (id(${device_name_underscore}_led).current_values.get_brightness() >= 0.99) {
id(led_increasing_brightness) = false;
id(stop) = true;
}
else:
- light.dim_relative:
id: "${device_name_underscore}_led"
relative_brightness: -2%
transition_length: 100ms
- delay: 50ms
- lambda: |-
id(led_brightness) = id(${device_name_underscore}_led).current_values.get_brightness();
ESP_LOGD("main", "Global value brightness is: %f", id(led_brightness));
if (id(${device_name_underscore}_led).current_values.get_brightness() <= 0.04) {
id(led_increasing_brightness) = true;
id(stop) = true;
}
- lambda: |-
// invert bool at end of while
id(led_increasing_brightness) = !id(led_increasing_brightness);
id(stop) = false;