-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcloudline-exhaust-3-led.yaml
195 lines (175 loc) · 4.98 KB
/
cloudline-exhaust-3-led.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
# This configuration allows a Shelly-RGBW2 to contol an AC Infinity Cloudline
# exhaust fan.
#
# This version of the config supports a pushbutton to cycle through fan speeds,
# and expects you to use 3 separate LEDs as a status indicator, which will light
# individually 1-2-3 based on the fan speed.
#
# For the most up to date version of this config, see:
# https://github.com/ex-nerd/esphome-shelly-cloudline
#
# For details about Shelly, see: https://devices.esphome.io/devices/Shelly-RGBW2
esphome:
name: cloudline-exhaust
friendly_name: Cloudline Exhaust
esp8266:
board: esp01_1m
restore_from_flash: true
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: !secret api_encryption_key
ota:
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${name} ESPHome"
password: !secret fallback_hotspot_password
captive_portal:
script:
- id: set_led
then:
lambda: |-
float set_brightness = id(brightness).state / 100.0;
if (std::isnan(set_brightness) || set_brightness > 1.0) {
set_brightness = 1.0;
}
// If fan is off or brightness is zero, then just ensure the LED is off
if (!id(fan_speed).state || set_brightness < 0.1) {
auto call = id(led1).turn_off();
call.set_transition_length(0);
call.perform();
call = id(led2).turn_off();
call.set_transition_length(0);
call.perform();
call = id(led3).turn_off();
call.set_transition_length(0);
call.perform();
return;
}
// Otherwise, set the appropriate brightness for each segment
auto speed = id(fan_speed).speed;
if (speed <= 2) {
auto call1 = id(led1).turn_on();
call1.set_brightness(speed == 2 ? set_brightness : set_brightness * .5);
call1.set_transition_length(0);
call1.perform();
auto call2 = id(led2).turn_off();
call2.set_transition_length(0);
call2.perform();
auto call3 = id(led3).turn_off();
call3.set_transition_length(0);
call3.perform();
} else if (speed <= 4) {
auto call1 = id(led1).turn_on();
call1.set_brightness(set_brightness);
call1.set_transition_length(0);
call1.perform();
auto call2 = id(led2).turn_on();
call2.set_brightness(speed == 4 ? set_brightness : set_brightness * .5);
call2.set_transition_length(0);
call2.perform();
auto call3 = id(led3).turn_off();
call3.set_transition_length(0);
call3.perform();
} else {
auto call1 = id(led1).turn_on();
call1.set_brightness(set_brightness);
call1.set_transition_length(0);
call1.perform();
auto call2 = id(led2).turn_on();
call2.set_brightness(set_brightness);
call2.set_transition_length(0);
call2.perform();
auto call3 = id(led3).turn_on();
call3.set_brightness(speed == 6 ? set_brightness : set_brightness * .5);
call3.set_transition_length(0);
call3.perform();
}
number:
- platform: template
name: "Brightness"
id: "brightness"
unit_of_measurement: "%"
initial_value: 90
optimistic: true
step: 1
min_value: 0
max_value: 100
mode: slider
icon: mdi:power-settings
restore_value: true
on_value:
then:
- script.execute: set_led
fan:
- platform: speed
name: "Fan"
id: fan_speed
output: pwm_fan
speed_count: 6
restore_mode: ALWAYS_OFF
on_turn_off:
# - logger.log: "Fan turned OFF"
- script.execute: set_led
on_turn_on:
# - logger.log: "Fan turned ON"
- script.execute: set_led
on_speed_set:
# - logger.log:
# format: "Fan Speed was changed to %d!"
# args: [ x ]
- script.execute: set_led
light:
- platform: monochromatic
name: LED1
id: led1
output: pwm_r
restore_mode: ALWAYS_OFF
internal: true
- platform: monochromatic
name: LED2
id: led2
output: pwm_g
restore_mode: ALWAYS_OFF
internal: true
- platform: monochromatic
name: LED3
id: led3
output: pwm_b
restore_mode: ALWAYS_OFF
internal: true
binary_sensor:
# Switch input
- platform: gpio
pin: GPIO5
id: button
on_press:
- fan.cycle_speed: fan_speed
output:
# W connection goes to the fan
- platform: esp8266_pwm
pin: GPIO4
frequency: 5000 Hz
id: pwm_fan
inverted: true
# R for LED 1
- platform: esp8266_pwm
pin: GPIO12
frequency: 1000 Hz
id: pwm_r
# G for LED 2
- platform: esp8266_pwm
pin: GPIO15
frequency: 1000 Hz
id: pwm_g
# B for LED 3
- platform: esp8266_pwm
pin: GPIO14
frequency: 1000 Hz
id: pwm_b