Add energy monitor using riemann sum algorithm.

This commit is contained in:
2026-05-30 16:49:57 +02:00
parent d7337fd634
commit 31848bf26c
2 changed files with 21 additions and 3 deletions
+7 -3
View File
@@ -365,7 +365,7 @@ class Meter {
esphome::display::BaseFont *value_font, int display_page = 0,
bool atorch_connected = false,
float atorch_voltage = NAN, float atorch_current = NAN, float atorch_power = NAN,
float atorch_capacity = NAN, float atorch_temperature = NAN) {
float atorch_capacity = NAN, float atorch_energy = NAN, float atorch_temperature = NAN) {
const Color bg(0, 0, 0);
const Color fg(210, 210, 210);
// Chosen to map to a neutral dark gray in the RGB332 8-bit display palette.
@@ -452,11 +452,13 @@ class Meter {
char current_text[24];
char power_text[24];
char capacity_text[24];
char energy_text[24];
char temperature_text[24];
this->format_metric_(voltage_text, sizeof(voltage_text), atorch_voltage, "V", 2);
this->format_metric_(current_text, sizeof(current_text), atorch_current, "A", 3);
this->format_metric_(power_text, sizeof(power_text), atorch_power, "W", 2);
this->format_metric_(capacity_text, sizeof(capacity_text), atorch_capacity, "Ah", 3);
this->format_metric_(energy_text, sizeof(energy_text), atorch_energy, "Wh", 3);
this->format_metric_(temperature_text, sizeof(temperature_text), atorch_temperature, "°C", 1);
it.filled_rectangle(0, 0, 320, 30, atorch_connected ? panel_dim : panel_inactive);
@@ -476,8 +478,10 @@ class Meter {
it.filled_rectangle(10, 233, 300, 1, border);
it.filled_rectangle(10, 212, 1, 22, border);
it.filled_rectangle(309, 212, 1, 22, border);
it.print(24, 216, font, inactive, esphome::display::TextAlign::TOP_LEFT, "CAPACITY");
it.print(306, 212, value_font, value_color, esphome::display::TextAlign::TOP_RIGHT, capacity_text);
it.print(20, 216, font, inactive, esphome::display::TextAlign::TOP_LEFT, "CAP");
it.print(64, 216, font, value_color, esphome::display::TextAlign::TOP_LEFT, capacity_text);
it.print(170, 216, font, inactive, esphome::display::TextAlign::TOP_LEFT, "ENERGY");
it.print(306, 216, font, value_color, esphome::display::TextAlign::TOP_RIGHT, energy_text);
}
}
+14
View File
@@ -326,6 +326,7 @@ display:
id(atorch_current).has_state() ? id(atorch_current).state : NAN,
id(atorch_power).has_state() ? id(atorch_power).state : NAN,
id(atorch_capacity).has_state() ? id(atorch_capacity).state : NAN,
id(atorch_energy_calculated).has_state() ? id(atorch_energy_calculated).state : NAN,
id(atorch_temperature).has_state() ? id(atorch_temperature).state : NAN
);
@@ -480,6 +481,19 @@ sensor:
name: "${friendly_name} Atorch Dim Backlight"
id: atorch_dim_backlight
- platform: integration
name: "${friendly_name} Atorch Energy"
id: atorch_energy_calculated
sensor: atorch_power
time_unit: h
unit_of_measurement: "Wh"
icon: "mdi:lightning-bolt"
device_class: energy
state_class: total_increasing
accuracy_decimals: 3
restore: true
integration_method: trapezoid
text_sensor:
- platform: template
name: "${friendly_name} OWON Reading"