-
Notifications
You must be signed in to change notification settings - Fork 14
/
mipurifier.yaml
167 lines (155 loc) · 4.06 KB
/
mipurifier.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
esphome:
name: mipurifier
comment: for Xiaomi Mi Air Purifier 3H (and similar models using the same protocol)
includes:
- mipurifier.h
# Required configuration for the weird single core ESP-WROOM-32D module
esp32:
board: esp32doit-devkit-v1
framework:
type: esp-idf
sdkconfig_options:
CONFIG_FREERTOS_UNICORE: y
advanced:
ignore_efuse_mac_crc: true
ignore_efuse_custom_mac: true
# Enable logging
logger:
# Enable Home Assistant API
api:
password: ""
# Enable OTA updates
ota:
password: ""
# Wi-Fi configuration
# EDIT CREDENTIALS OR PROVIDE YOUR OWN secrets.yaml
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Mipurifier Fallback Hotspot"
password: "PyCfsbmzuMbj"
# Initialize the serial connection to the STM32 microcontroller
uart:
id: uart_bus
tx_pin: GPIO17
rx_pin: GPIO16
baud_rate: 115200
# Initialize our custom component
custom_component:
- lambda: |-
auto mipurifier = new MiPurifier(id(uart_bus));
App.register_component(mipurifier);
return {mipurifier};
components:
- id: mipurifier
# Main component for controlling the purifier
fan:
- platform: template
name: "Power"
id: XiaomiPurifierFan
speed_count: 15
preset_modes:
- "auto"
- "night"
- "low"
- "medium"
- "high"
- "manual"
on_turn_on:
- lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
c->turn_on();
on_turn_off:
- lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
c->turn_off();
on_preset_set:
- lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
if (!id(XiaomiPurifierFan).state) {
c->set_mode(x);
c->turn_off();
} else {
c->set_mode(x);
}
on_speed_set:
- lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
c->set_manualspeed((int)x-1);
- delay: 1s
- lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
c->set_mode("manual");
# Config settings
switch:
- platform: template
name: "Beeper"
id: beeper_switch
icon: mdi:volume-high
entity_category: config
turn_on_action:
- lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
c->enable_beeper();
turn_off_action:
- lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
c->disable_beeper();
- platform: template
name: "Lock"
id: lock_switch
icon: mdi:lock
entity_category: config
turn_on_action:
- lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
c->lock();
turn_off_action:
- lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
c->unlock();
# Select components for mode & brightness
select:
- platform: template
name: "Display Brightness"
id: brightness_select
icon: mdi:brightness-6
entity_category: config
options:
- "off"
- "low"
- "high"
set_action:
- lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
c->set_brightness(x);
# Expose measured environmental values, and remaining filter life
sensor:
- platform: custom
lambda: |-
auto c = static_cast<MiPurifier *>(mipurifier);
return {
c->airquality_sensor,
c->humidity_sensor,
c->temperature_sensor,
c->filterlife_sensor,
};
sensors:
- name: "Air quality (PM2.5)"
unit_of_measurement: "µg/m³"
device_class: pm25
state_class: "measurement"
- name: "Humidity"
unit_of_measurement: "%"
device_class: humidity
state_class: "measurement"
- name: "Temperature"
unit_of_measurement: "°C"
device_class: temperature
accuracy_decimals: 1
state_class: "measurement"
- name: "Filter remaining"
unit_of_measurement: "%"
icon: mdi:air-filter