Repository navigation
Expand file tree
/
Copy pathcommon.yaml
More file actions
158 lines (140 loc) · 4.6 KB
/
Copy pathcommon.yaml
File metadata and controls
158 lines (140 loc) · 4.6 KB
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
# =============================================================================
# ESP32 Base Configuration
# Cấu hình cơ bản cho tất cả các thiết bị ESP32 trong hệ thống
# =============================================================================
# ───────────────────────── ESP32 Platform ─────────────────────────
esp32:
# board: ${board} # Sẽ được override bởi file con
framework:
type: esp-idf
# ───────────────────────── Core Services ─────────────────────────
logger:
baud_rate: 115200
level: DEBUG
api:
reboot_timeout: 0s
ota:
- platform: esphome
password: !secret ota_password
web_server:
port: 80
time:
- platform: sntp
# ───────────────────────── WiFi Configuration ─────────────────────────
wifi:
# Cấu hình networks sẽ được override bởi file con
fast_connect: true
power_save_mode: none
reboot_timeout: 10min
captive_portal:
# ───────────────────────── System Monitoring Sensors ─────────────────────────
sensor:
# System Uptime
- platform: uptime
name: "Uptime Seconds"
id: uptime_sec
update_interval: 10s
# Memory monitoring
- platform: template
name: "Heap Free"
id: heap_free_kb
unit_of_measurement: "kB"
accuracy_decimals: 0
update_interval: 30s
entity_category: diagnostic
lambda: |-
#ifdef ESP_IDF_VERSION
size_t free_bytes = heap_caps_get_free_size(MALLOC_CAP_8BIT);
#else
size_t free_bytes = ESP.getFreeHeap();
#endif
return (float) free_bytes / 1024.0f;
- platform: template
name: "PSRAM Free"
id: psram_free_kb
unit_of_measurement: "kB"
accuracy_decimals: 0
update_interval: 30s
entity_category: diagnostic
lambda: |-
#if CONFIG_SPIRAM
size_t free_bytes = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
return (float) free_bytes / 1024.0f;
#else
return NAN; // Không có PSRAM thì trả NAN (ẩn biểu đồ)
#endif
# WiFi Signal Monitoring
- platform: wifi_signal
id: rssi_dbm
name: "WiFi RSSI"
update_interval: 30s
entity_category: diagnostic
filters:
- sliding_window_moving_average:
window_size: 5
send_every: 1
# WiFi Quality Percentage (0-100%)
- platform: template
id: wifi_quality_pct
name: "WiFi Quality"
unit_of_measurement: "%"
accuracy_decimals: 0
update_interval: 30s
entity_category: diagnostic
lambda: |-
float rssi = id(rssi_dbm).state;
if (isnan(rssi)) return NAN;
if (rssi <= -100) return 0;
if (rssi >= -50) return 100;
return (rssi + 100.0f) * 2.0f;
text_sensor:
- platform: template
name: "Uptime"
icon: mdi:clock-outline
entity_category: diagnostic
lambda: |-
uint32_t t = (uint32_t) id(uptime_sec).state;
uint32_t d = t / 86400;
uint32_t h = (t % 86400) / 3600;
uint32_t m = (t % 3600) / 60;
uint32_t s = t % 60;
char buf[40];
if (d) snprintf(buf, sizeof(buf), "%ud %uh %um %us", d, h, m, s);
else if (h) snprintf(buf, sizeof(buf), "%uh %um %us", h, m, s);
else if (m) snprintf(buf, sizeof(buf), "%um %us", m, s);
else snprintf(buf, sizeof(buf), "%us", s);
return std::string(buf);
update_interval: 10s
- platform: wifi_info
ip_address:
name: "WiFi IP"
ssid:
name: "WiFi SSID"
bssid:
name: "WiFi BSSID"
mac_address:
name: "WiFi MAC"
# 3) Quy đổi dBm -> số vạch "x/5"
- platform: template
id: wifi_bars
name: "WiFi Bars"
update_interval: 30s
entity_category: diagnostic
lambda: |-
float rssi = id(rssi_dbm).state;
if (isnan(rssi)) return {"N/A"};
int bars = 0;
if (rssi >= -55) bars = 5;
else if (rssi >= -65) bars = 4;
else if (rssi >= -72) bars = 3;
else if (rssi >= -80) bars = 2;
else if (rssi >= -90) bars = 1;
else bars = 0;
char buffer[5];
sprintf(buffer, "%d/5", bars);
return {buffer};
# ── Nút restart thủ công ─────────────────────────────────────────────
button:
- platform: restart
id: restart_button
name: "Restart thiết bị"