-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlamp.yaml
102 lines (92 loc) · 3.09 KB
/
lamp.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
esphome:
name: midesklamppro
comment: Mi Smart LED Desk Lamp Pro using ESPHome
esp32:
board: esp32doit-devkit-v1
framework:
type: esp-idf
sdkconfig_options:
CONFIG_FREERTOS_UNICORE: y
advanced:
ignore_efuse_mac_crc: true
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
fast_connect: true
# Enable logging
logger:
api:
reboot_timeout: 0s
ota:
password: "ota-desk-lamp-prop"
sensor:
- platform: rotary_encoder
id: rotation
pin_a: GPIO26
pin_b: GPIO27
resolution: 2
on_value:
then:
- if:
condition:
# Check if Button is pressed while rotating
lambda: "return id(button).state;"
then:
# If Button is pressed, change CW/WW
- lambda: |-
auto min_temp = id(light1).get_traits().get_min_mireds();
auto max_temp = id(light1).get_traits().get_max_mireds();
auto cur_temp = id(light1).current_values.get_color_temperature();
auto new_temp = max(min_temp, min(max_temp, cur_temp + (x*10)));
auto call = id(light1).turn_on();
call.set_color_temperature(new_temp);
call.perform();
else:
# If Button is not pressed, change brightness
- light.dim_relative:
id: light1
transition_length: 0s
relative_brightness: !lambda |-
return x / 25.0;
# Reset Rotation to 0
- sensor.rotary_encoder.set_value:
id: rotation
value: 0
binary_sensor:
- platform: gpio
id: button
pin:
number: GPIO33
inverted: True
mode: INPUT_PULLDOWN
on_click:
then:
- light.toggle: light1
output:
- platform: ledc
pin: GPIO2
id: output_cw
frequency: 40000Hz
power_supply: power
- platform: ledc
pin: GPIO4
id: output_ww
power_supply: power
frequency: 40000Hz
power_supply:
- id: power
pin: GPIO12
enable_time: 0s
keep_on_time: 0s
light:
- platform: cwww
id: light1
default_transition_length: 400ms
constant_brightness: true
name: "Lights"
cold_white: output_cw
warm_white: output_ww
cold_white_color_temperature: 4800 K
warm_white_color_temperature: 2650 K #2500k is the original value of the lamp. To correct binning for 2700k to look more like 2700k use 2650k instead
restore_mode: RESTORE_DEFAULT_OFF
gamma_correct: 0