-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noahclock.yaml
176 lines (152 loc) · 3.91 KB
/
noahclock.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
substitutions:
name: noahclock
esphome:
name: ${name}
platform: ESP32
board: esp32dev
<<: !include ./includes/common.yaml
<<: !include ./includes/bluetooth_proxy.yaml
logger:
level: DEBUG
globals:
- id: progress
type: int
restore_value: no
initial_value: '100'
sensor:
- platform: uptime
name: Uptime
update_interval: 60s
- platform: template
name: Progress Percent
id: progress_percent
unit_of_measurement: "%"
state_class: measurement
icon: mdi:percent
lambda: |
return id(progress) < 0 ? 0 : id(progress);
- platform: bmp280
temperature:
name: "Temperature"
address: 0x76
i2c:
sda: 18
scl: 5
scan: true
time:
- platform: sntp
id: sntp_time
timezone: Europe/London
on_time_sync:
then:
- if:
condition:
- light.is_off: led_matrix_light
then:
- light.turn_on: led_matrix_light
on_time:
- seconds: "*"
then:
- lambda: |
float hour, alarm, remaining, total, evening, percent;
int day_of_week;
evening = (float)id(evening_time).state;
hour = id(sntp_time).now().hour + (0.0166666666667 * id(sntp_time).now().minute);
day_of_week = id(sntp_time).now().day_of_week;
// if its sunday-thursday & evening or if its mon-fri
// sun = 1
// mon = 2
// tue = 3
// wed = 4
// thu = 5
// fri = 6
// sat = 7
if ( (day_of_week <= 5 && hour >= evening) || (day_of_week >= 2 && day_of_week <= 6 )) {
alarm = id(weekday_alarm).state;
} else {
alarm = id(weekend_alarm).state;
}
total = 24.00 - evening + alarm;
if (hour >= evening) {
alarm += 24;
}
remaining = alarm-hour;
percent = (100/total) * remaining;
ESP_LOGD("remaining", "hour: %f total: %f alarm:%f remain: %f perecent: %f, evening: %f", hour, total, alarm, remaining, percent, evening);
id(progress) = percent;
font:
- id: tinyfont
file: "lexis.ttf"
size: 8
glyphs: \'!"%()+,-_.:*=°?~# 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
number:
- platform: template
name: "Weekday alarm"
optimistic: true
restore_value: true
initial_value: 7
id: weekday_alarm
min_value: 0
max_value: 23
step: 0.01
icon: mdi:alarm
- platform: template
name: "Weekend alarm"
optimistic: true
restore_value: true
initial_value: 7.25
id: weekend_alarm
min_value: 0
max_value: 23
step: 0.01
icon: mdi:alarm
- platform: template
name: "Evening Time"
optimistic: true
restore_value: true
initial_value: 18
id: evening_time
min_value: 0
max_value: 23
step: 0.01
icon: mdi:clock-start
light:
- platform: neopixelbus
type: GRB
variant: WS2812
pin: GPIO13
num_leds: 256
name: "Clock Led Matrix"
id: led_matrix_light
default_transition_length: 0s
restore_mode: ALWAYS_ON
icon: mdi:clock-digital
display:
- platform: addressable_light
id: led_matrix_display
addressable_light_id: led_matrix_light
width: 32
height: 8
rotation: 0°
pixel_mapper: |-
if (x % 2 == 0) {
return (x * 8) + y;
}
return (x * 8) + (7 - y);
lambda: |-
auto color = Color(0, 0, 0);
if (id(progress) > 0.0 ) {
color = Color(28, 0, 0);
it.line(0, 0, floor(0.32 * id(progress)), 0, color);
} else {
color = Color(0, 50, 0);
}
auto time_text = id(sntp_time).now().strftime("%I:%M");
it.print(
1,
1,
id(tinyfont),
color,
TextAlign::TOP_LEFT,
time_text.c_str()
);