-
Notifications
You must be signed in to change notification settings - Fork 0
/
nora.yaml
217 lines (201 loc) · 5.3 KB
/
nora.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
substitutions:
devicename: noradesk
devicename_upper: NoraDesk
<<: !include ./.base.yaml
sensor:
## DHT22
- platform: dht
pin: D4
model: AM2302
temperature:
name: "${devicename_upper} Temperature"
humidity:
name: "${devicename_upper} Humidity"
update_interval: 30s
# Rotary Encoder
- platform: rotary_encoder
pin_a: D7
pin_b: D6
id: knob
restore_mode: ALWAYS_ZERO
min_value: 0
max_value: 255
resolution: 4
on_value:
then:
## Color
- if:
condition:
lambda: 'if (id(current_mode).state == "color") { return true; } else { return false; }'
then:
- script.execute: colored_light
## Brightness
- if:
condition:
lambda: 'if (id(current_mode).state == "brightness") { return true; } else { return false; }'
then:
- light.turn_on:
id: strip
white: 0%
brightness: !lambda "return x / 255.0;"
binary_sensor:
- platform: gpio
pin:
number: D5
inverted: true
id: button
filters:
- delayed_on: 10ms
- delayed_off: 10ms
on_click:
## Short press
- then:
- if:
condition:
light.is_off: strip
then:
- script.execute: colored_light
else:
## Check if effect is running
- if:
condition:
lambda: return id(strip).get_effect_name() != "None";
then:
- script.execute: colored_light
else:
- script.execute: next_mode
## Long press
- min_length: 1000ms
max_length: 3000ms
then:
- light.turn_off: strip
## Double click
on_double_click:
then:
- script.execute: next_effect
light:
- platform: neopixelbus
type: GRB
variant: WS2812
pin: D2
num_leds: 117
restore_mode: ALWAYS_OFF
id: strip
name: "Strip"
default_transition_length: 0.3s
effects:
- addressable_rainbow:
- addressable_color_wipe:
colors:
random: true
num_leds: 3
- addressable_scan:
move_interval: 50ms
scan_width: 5
- addressable_twinkle:
- pulse:
- addressable_fireworks:
- addressable_fireworks:
name: Random Fireworks
use_random_color: true
select:
## Current Mode
- platform: template
id: current_mode
internal: true
optimistic: true
options:
- color
- brightness
on_value:
- logger.log:
format: "CURRENT STATE IS: %s"
args: ["x.c_str()"]
globals:
- id: current_mode_int
type: int
restore_value: no
initial_value: "0"
- id: current_effect_int
type: int
restore_value: no
initial_value: "0"
script:
## Script for activating colored light
- id: colored_light
then:
- lambda: |-
float v = id(knob).state / 255;
if (v != v) { // Test for NaN, after boot knob is inited with NaN (weird!)
v = 0;
}
float a = (1 - v) / 0.2;
int X = floor(a);
float Y = (floor)(255 * (a - X));
float r = 0;
float g = 0;
float b = 0;
switch (X) {
case 0: r=255; g=Y; b=0; break;
case 1: r=255-Y; g=255; b=0; break;
case 2: r=0; g=255; b=Y; break;
case 3: r=0; g=255-Y; b=255; break;
case 4: r=Y; g=0; b=255; break;
case 5: r=255; g=0; b=255; break;
}
auto call = id(strip).turn_on();
call.set_brightness(0.6);
call.set_color_mode(ColorMode::RGB);
call.set_rgb(r / 255, g / 255, b / 255);
call.perform();
## Whenever this script is called the next mode is activated
- id: next_mode
then:
## Set next mode
- lambda: |-
if (id(current_mode_int) < 1) {
id(current_mode_int) += 1;
} else {
id(current_mode_int) = 0;
}
switch (id(current_mode_int)) {
case 1:
id(current_mode).publish_state("color");
break;
default:
id(current_mode).publish_state("brightness");
break;
}
- id: next_effect
then:
- lambda: |-
if (id(current_effect_int) < 6) {
id(current_effect_int) += 1;
} else {
id(current_effect_int) = 0;
}
auto call = id(strip).turn_on();
switch(id(current_effect_int)) {
case 1:
call.set_effect("Color Wipe");
break;
case 2:
call.set_effect("Scan");
break;
case 3:
call.set_effect("Twinkle");
break;
case 4:
call.set_effect("Fireworks");
break;
case 5:
call.set_effect("Random Fireworks");
break;
case 6:
call.set_effect("Pulse");
break;
default:
call.set_effect("Rainbow");
break;
}
call.perform();