-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathn1-fan.yml
172 lines (153 loc) · 3.74 KB
/
n1-fan.yml
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
substitutions:
device_name: "N1 Fan"
device_name_low: "n1-fan"
comment: "N1 Fan"
version: "1.0.0"
speed_low: "50"
speed_med: "75"
speed_full: "100"
esphome:
name: "${device_name_low}"
project:
name: "n1.fan_controller"
version: "${version}"
on_boot:
then:
- delay: 10s
- fan.turn_on:
id: fan_speed
speed: "${speed_low}"
- delay: 5s
- fan.turn_on:
id: fan_speed
speed: "${speed_full}"
esp8266:
board: nodemcuv2
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
password: "12345678"
wifi:
ssid: !secret wifi_ssid #WiFi SSID
password: !secret wifi_password #WiFi密码
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${device_name_low}"
password: "12345678"
captive_portal:
web_server:
port: 80
#定义i2c pin口
i2c:
sda: D6
scl: D5
scan: True
output:
- platform: esp8266_pwm
pin: D4
frequency: 15000 Hz
id: pwm_output
fan:
- platform: speed
id: fan_speed
output: pwm_output
speed_count: 100
name: "${device_name} 开关"
number:
- platform: template
icon: "mdi:fan"
id: speed_input
name: "${device_name} 风速"
lambda: |-
return id(fan_speed).speed;
step: 1
min_value: 1
max_value: 100
unit_of_measurement: "%"
update_interval: 1s
set_action:
then:
- fan.turn_on:
id: fan_speed
speed: !lambda "return x;"
- component.update: fanmode
- component.update: sensor_fanspeed
select:
- platform: template
icon: "mdi:fan"
name: "${device_name} 模式"
id: fanmode
update_interval: 1s
lambda: |-
if(id(fan_speed).speed <= ${speed_low})
return std::string("Low");
else if(id(fan_speed).speed == ${speed_med})
return std::string("Medium");
else if(id(fan_speed).speed >= ${speed_full})
return std::string("Full");
else
return std::string("Custom");
set_action:
then:
- lambda: |-
auto call = id(fan_speed).turn_on();
if(x == "Low")
call.set_speed(${speed_low});
else if(x == "Medium")
call.set_speed(${speed_med});
else if(x == "Full")
call.set_speed(${speed_full});
else
call.set_speed(id(speed_input).state);
call.perform();
- component.update: speed_input
- component.update: sensor_fanspeed
options:
- Low
- Medium
- Full
- Custom
button:
- platform: template
icon: "mdi:fan-speed-1"
name: "${device_name} Low"
id: fanlow
on_press:
- fan.turn_on:
id: fan_speed
speed: "${speed_low}"
- platform: template
icon: "mdi:fan-speed-2"
name: "${device_name} Med"
on_press:
- fan.turn_on:
id: fan_speed
speed: "${speed_med}"
- platform: template
icon: "mdi:fan-speed-3"
name: "${device_name} Full"
on_press:
- fan.turn_on:
id: fan_speed
speed: "${speed_full}"
- platform: restart
name: "${device_name} 初始化"
sensor:
- platform: template
id: sensor_fanspeed
icon: "mdi:fan"
name: "风扇速度"
lambda: |-
return id(fan_speed).speed;
update_interval: 1s
accuracy_decimals: 0
unit_of_measurement: "%"
- platform: shtcx
temperature:
name: "${device_name} Temperature"
humidity:
name: "${device_name} Humidity"
address: 0x70
update_interval: 5s #获取频率