5namespace total_daily_energy {
7static const char *
const TAG =
"total_daily_energy";
10 float initial_value = 0;
35 if (t.day_of_year != this->last_day_of_year_) {
51 if (std::isnan(
state))
53 const uint32_t now =
millis();
55 const float new_state =
state;
56 float delta_hours = (now - this->
last_update_) / 1000.0f / 60.0f / 60.0f;
57 float delta_energy = 0.0f;
60 delta_energy = delta_hours * (old_state + new_state) / 2.0;
63 delta_energy = delta_hours * old_state;
66 delta_energy = delta_hours * new_state;
virtual ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash)=0
uint32_t get_object_id_hash()
void publish_state(float state)
Publish a new state to the front-end.
float state
This member variable stores the last state that has passed through all filters.
ESPTime now()
Get the time in the currently defined timezone.
time::RealTimeClock * time_
uint16_t last_day_of_year_
void publish_state_and_save(float state)
void process_new_state_(float state)
void dump_config() override
TotalDailyEnergyMethod method_
ESPPreferenceObject pref_
@ TOTAL_DAILY_ENERGY_METHOD_TRAPEZOID
@ TOTAL_DAILY_ENERGY_METHOD_LEFT
@ TOTAL_DAILY_ENERGY_METHOD_RIGHT
Providing packet encoding functions for exchanging data with a remote host.
ESPPreferences * global_preferences
uint32_t IRAM_ATTR HOT millis()