11static constexpr uint32_t READ_TIMEOUT_ID = 0;
14 LOG_SENSOR(
"",
"CT Clamp Sensor",
this);
15 ESP_LOGCONFIG(TAG,
" Sample Duration: %.2fs", this->
sample_duration_ / 1e3f);
16 LOG_UPDATE_INTERVAL(
this);
38 const float rms_ac_squared = rms_ac_dc_squared - rms_dc * rms_dc;
40 if (rms_ac_squared > 0)
41 rms_ac = std::sqrt(rms_ac_squared);
42 ESP_LOGD(TAG,
"'%s' - Raw AC Value: %.3fA after %" PRIu32
" different samples (%" PRIu32
" SPS)",
62 if (std::isnan(value))
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
void stop()
Stop running the loop continuously.
void start()
Start running the loop continuously.
voltage_sampler::VoltageSampler * source_
The sampling source to read values from.
float sample_squared_sum_
float last_value_
The DC offset of the circuit.
uint32_t sample_duration_
Duration in ms of the sampling phase.
void dump_config() override
HighFrequencyLoopRequester high_freq_
High Frequency loop() requester used during sampling phase.
void publish_state(float state)
Publish a new state to the front-end.
virtual float sample()=0
Get a voltage reading, in V.
ESPHOME_LOG_TAG(TAG, "ct_clamp")