ESPHome  2022.6.3
total_daily_energy.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "esphome/core/hal.h"
8 
9 namespace esphome {
10 namespace total_daily_energy {
11 
16 };
17 
18 class TotalDailyEnergy : public sensor::Sensor, public Component {
19  public:
20  void set_restore(bool restore) { restore_ = restore; }
21  void set_min_save_interval(uint32_t min_interval) { this->min_save_interval_ = min_interval; }
22  void set_time(time::RealTimeClock *time) { time_ = time; }
23  void set_parent(Sensor *parent) { parent_ = parent; }
24  void set_method(TotalDailyEnergyMethod method) { method_ = method; }
25  void setup() override;
26  void dump_config() override;
27  float get_setup_priority() const override { return setup_priority::DATA; }
28  void loop() override;
29 
30  void publish_state_and_save(float state);
31 
32  protected:
33  void process_new_state_(float state);
34 
39  uint16_t last_day_of_year_{};
40  uint32_t last_update_{0};
41  uint32_t last_save_{0};
42  uint32_t min_save_interval_{0};
43  bool restore_;
44  float total_energy_{0.0f};
45  float last_power_state_{0.0f};
46 };
47 
48 } // namespace total_daily_energy
49 } // namespace esphome
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:18
void set_method(TotalDailyEnergyMethod method)
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock...
float state
This member variable stores the last state that has passed through all filters.
Definition: sensor.h:132
void set_min_save_interval(uint32_t min_interval)
void set_time(time::RealTimeClock *time)
Definition: a4988.cpp:4
Base-class for all sensors.
Definition: sensor.h:47