-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathalarm-clock-gl5516.yaml
More file actions
113 lines (104 loc) · 3.19 KB
/
Copy pathalarm-clock-gl5516.yaml
File metadata and controls
113 lines (104 loc) · 3.19 KB
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
sensor:
- platform: template
id: contrast_force_percent
name: "Contrast Force Percent"
unit_of_measurement: "%"
icon: mdi:contrast
update_interval: 2s
filters:
- delta: 1%
lambda: |-
if (id(contrast_force) < 0.0f) {
return NAN;
} else {
return id(contrast_force) * 100.0f;
}
- platform: adc
id: light_sensor_raw
internal: true
pin: $ldr_pin
device_class: illuminance
update_interval: 2s
attenuation: auto
unit_of_measurement: lx
accuracy_decimals: 1
filters:
- lambda: |-
float lux = ((x / 10000.0) * 2000000.0 - 15) + id(illuminance_offset_ui).state;
if (lux < 0) lux = 0;
return lux;
- clamp:
min_value: 0
on_value:
then:
- lambda: |-
static float last_val = -1.0;
bool send = false;
// Initial publish, z.B. beim Boot oder wenn contrast_force < 0
if (last_val < 0 || id(contrast_force) < 0.0f) {
send = true;
}
// Delta >5% check
else if (fabs(x - last_val) / (last_val > 0.01 ? last_val : 0.01) * 100.0 > 5.0) {
send = true;
}
if (send) {
last_val = x;
id(light_sensor).publish_state(x); // publish to HA
ESP_LOGD("light_sensor", "x = : %.2f", x);
// handle contrast
if (id(switch_autobrightness).state) {
int n = (x / $aab_scale) + $aab_offset + $aab_add;
if (n > $aab_max) n = $aab_max;
if (n < $aab_min) n = $aab_min;
float new_contrast = n / 255.0f;
// initial set contrast_force (if not valid)
if (id(contrast_force) < 0.0f) {
id(contrast_force) = new_contrast;
id(smooth_contrast).execute();
} else {
float current = id(contrast_current);
float delta_c = new_contrast - current;
float diff_percent = (delta_c / (current > 0.01f ? current : 0.01f)) * 100.0f;
if (fabs(diff_percent) > 2.0f) {
id(contrast_force) = new_contrast;
id(smooth_contrast).execute();
}
}
}
}
- platform: template
name: "Illuminance"
id: light_sensor
unit_of_measurement: "lx"
device_class: illuminance
update_interval: never
lambda: |-
return id(light_sensor_raw).state;
switch:
- platform: template
name: "Auto-Adjust Brightness"
id: switch_autobrightness
icon: mdi:brightness-auto
restore_mode: RESTORE_DEFAULT_ON
optimistic: true
turn_off_action:
lambda: |-
id(contrast_force) = -1.0;
number:
- platform: template
name: "Illuminance Offset"
id: illuminance_offset_ui
unit_of_measurement: "lx"
min_value: -100
max_value: 100
step: 5
mode: slider
update_interval: never
optimistic: true
restore_value: true
initial_value: 0
icon: "mdi:brightness-5"
entity_category: config
on_value:
- lambda: 'id(light_sensor).update();'