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
|
esphome:
name: office-pc-control
area: Office
on_boot:
priority: -100
then:
- output.turn_off: pc_reset
- output.turn_off: pc_power_onoff
- light.control:
id: pc_rgb_led
brightness: 100%
red: 100%
green: 0%
blue: 0%
white: 0%
esp8266:
board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: !secret api_encryption_key
# OTA
ota:
- platform: esphome
password: !secret ota_password
# WiFi Credentials
wifi:
domain: .lan
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Couchlight Fallback Hotspot"
password: !secret wifi_ap_password
captive_portal:
output:
- platform: gpio
id: pc_reset
pin:
number: D2
inverted: true # pc power/reset pins are GND activated
- platform: gpio
id: pc_power_onoff
pin:
number: D3
inverted: true # pc power/reset pins are GND activated
button:
- platform: output
name: "Reset"
icon: "mdi:restore-alert"
output: pc_power_onoff
duration: 150ms
device_class: restart
- platform: output
name: "Power On/Off"
icon: "mdi:power"
output: pc_power_onoff
duration: 150ms
- platform: output
name: "Force Off"
icon: "mdi:power"
output: pc_power_onoff
duration: 5000ms
light:
- platform: neopixelbus
name: "RGB LED"
id: pc_rgb_led
type: GRBW
variant: WS2813 #800KBPS
num_leds: 16
pin: D4 # GPIO2
method:
type: esp8266_uart
bus: 1
default_transition_length: 300ms
effects:
- pulse
- addressable_rainbow
- addressable_color_wipe
- addressable_scan
- addressable_fireworks
- addressable_random_twinkle
binary_sensor:
- platform: gpio
name: "Touch button"
id: touch_button
pin:
number: D8
mode: INPUT
internal: true
filters:
- delayed_on: 50ms
on_state:
then:
- lambda: id(pc_power_onoff).set_state(x);
- platform: gpio
name: "Power button"
id: power_button
pin:
number: D5
mode: INPUT_PULLUP
inverted: true
internal: true
#on_state:
# then:
# - lambda: id(pc_power_onoff).set_state(x);
on_click:
- max_length: 1s
then:
- lambda: |-
auto light = id(pc_rgb_led);
int hue, new_hue;
float saturation, value, r, g, b;
light->current_values_as_rgb(&r, &g, &b);
rgb_to_hsv(r, g, b, hue, saturation, value);
do {
new_hue = static_cast<int>(random_float() * 360.0f);
} while (abs(new_hue - hue) < 42);
hsv_to_rgb(new_hue, 1.0, 1.0, r, g, b);
light->turn_on().set_rgb(r, g, b).set_white(0).perform();
- platform: gpio
name: "Reset button"
id: reset_button
pin:
number: D6
mode: INPUT_PULLUP
inverted: true
internal: true
#on_state:
# then:
# - lambda: id(pc_reset).set_state(x);
on_click:
- max_length: 500ms
then:
- lambda: |-
auto light = id(pc_rgb_led);
auto nexteffect = light->get_effect_by_index(light->get_current_effect_index() + 1);
if (!light->current_values.is_on())
nexteffect = nullptr;
auto name = (nexteffect != nullptr) ? nexteffect->get_name() : "none";
light->turn_on().set_effect(name).perform();
- platform: template
name: "Power/Reset button delayed"
internal: true
lambda: !lambda return id(power_button).state || id(reset_button).state;
filters:
- delayed_on: 1s
on_press:
then:
- light.turn_off: pc_rgb_led
- platform: gpio
name: "Powered"
icon: "mdi:desktop-tower"
pin:
number: D1
mode: INPUT_PULLUP
filters:
- delayed_on: 100ms
- delayed_off: 500ms
on_release:
then:
- light.turn_off: pc_rgb_led
|