diff --git a/esphome/energymonitor.yaml b/esphome/energymonitor.yaml index fd54ef9..db011c1 100644 --- a/esphome/energymonitor.yaml +++ b/esphome/energymonitor.yaml @@ -4,8 +4,6 @@ substitutions: friendly_name: "Energy Monitor" grid_power_gauge_max_w: "5000.0" balcony_solar_gauge_max_w: "800.0" - internet_download_gauge_max_mbps: "1000.0" - internet_upload_gauge_max_mbps: "1000.0" esphome: comment: ${device_description} @@ -729,10 +727,20 @@ display: if (id(internet_view) == 0) { it.print(12, 10, id(font_small), Color::WHITE, "Internet"); const int cx = 160, cy = 188; + // Round each live rate up to a 1/2/5 scale, with a 1 kbps minimum. + auto gauge_maximum = [](float rate) -> float { + const float peak = fmaxf(rate, 0.001f); + const float magnitude = powf(10.0f, floorf(log10f(peak))); + const float normalized = peak / magnitude; + return magnitude * (normalized <= 1 ? 1 : normalized <= 2 ? 2 + : normalized <= 5 ? 5 : 10); + }; + const float download_maximum = gauge_maximum(download_valid ? download : 0.0f); + const float upload_maximum = gauge_maximum(upload_valid ? upload : 0.0f); const float download_fraction = download_valid - ? fminf(download / ${internet_download_gauge_max_mbps}, 1.0f) : 0.0f; + ? fminf(download / download_maximum, 1.0f) : 0.0f; const float upload_fraction = upload_valid - ? fminf(upload / ${internet_upload_gauge_max_mbps}, 1.0f) : 0.0f; + ? fminf(upload / upload_maximum, 1.0f) : 0.0f; // Match the energy gauge: download outside, upload inside. it.filled_gauge(cx, cy, 140, 122, 100, muted); it.filled_gauge(cx, cy, 140, 122, static_cast(download_fraction * 100), download_color); @@ -745,8 +753,9 @@ display: it.printf(cx, 169, id(font_internet_value), upload_color, TextAlign::TOP_CENTER, "%s", upload_valid ? format_rate(upload).c_str() : "--"); it.printf(cx, 204, id(font_device), Color::WHITE, TextAlign::TOP_CENTER, - "Max: DL %.0f / UL %.0f Mbps", - ${internet_download_gauge_max_mbps}, ${internet_upload_gauge_max_mbps}); + "Max: DL %s / UL %s", + download_valid ? format_rate(download_maximum).c_str() : "--", + upload_valid ? format_rate(upload_maximum).c_str() : "--"); } else if (id(internet_view) == 1) { it.print(12, 10, id(font_device), Color::WHITE, "Internet ยท 1 h"); const int left = 28, right = 308, top = 62, zero = 122, bottom = 182;