Duty Cycle Sensor

See Application::make_duty_cycle_sensor().

API Reference

class DutyCycleSensor : public sensor::PollingSensorComponent

Public Functions

DutyCycleSensor(const std::string &name, GPIOPin *pin, uint32_t update_interval = 15000)
void setup()

Where the component’s initialization should happen.

Analogous to Arduino’s setup(). This method is guaranteed to only be called once. Defaults to doing nothing.

float get_setup_priority() const

priority of setup().

higher -> executed earlier

Defaults to 0.

Return
The setup priority of this component

void dump_config()
void update()
std::string unit_of_measurement()

Override this to set the Home Assistant unit of measurement for this sensor.

Return “” to disable this feature.

Return
The icon of this sensor, for example “°C”.

std::string icon()

Override this to set the Home Assistant icon for this sensor.

Return “” to disable this feature.

Return
The icon of this sensor, for example “mdi:battery”.

int8_t accuracy_decimals()

Return the accuracy in decimals for this sensor.

void ICACHE_RAM_ATTR HOT sensor::DutyCycleSensor::on_interrupt()

Public Static Functions

void ICACHE_RAM_ATTR HOT sensor::DutyCycleSensor::gpio_intr()

Protected Attributes

GPIOPin *pin_
volatile uint32_t last_interrupt_ = {0}
volatile uint32_t on_time_ = {0}
volatile bool last_level_ = {false}
DutyCycleSensor *next_
DutyCycleSensor *sensor::duty_cycle_sensors = nullptr