The output namespace contains all peripheral output components.

API Reference


class BinaryOutput

The base class for all binary outputs i.e.

outputs that can only be switched on/off.

This interface class provides one method you need to override in order to create a binary output component yourself: write_value(). This method will be called for you by the MQTT Component through enable()/disable() to indicate that a new value should be written to hardware.

Note that this class also allows the user to invert any state, but you don’t need to worry about that because the value will already be inverted (if specified by the user) within set_state_(). So write_state will always receive the correctly inverted state.

Additionally, this class provides high power mode capabilities using PowerSupplyComponent. Every time the output is enabled (independent of inversion!), the power supply will automatically be turned on.

Subclassed by output::FloatOutput, output::GPIOBinaryOutputComponent

Public Functions

virtual void write_enabled(bool enabled) = 0

Write a binary state to hardware, inversion is already applied.

void set_inverted(bool inverted)

Set the inversion state of this binary output.

void set_power_supply(PowerSupplyComponent *power_supply)

Use this to connect up a power supply to this output.

Whenever this output is enabled, the power supply will automatically be turned on.


void enable()

Enable this binary output.

void disable()

Disable this binary output.

bool is_inverted() const

Return whether this binary output is inverted.

PowerSupplyComponent *get_power_supply() const

Return the power supply assigned to this binary output.

template <typename T>
TurnOffAction<T> *make_turn_off_action()
template <typename T>
TurnOnAction<T> *make_turn_on_action()

Protected Attributes

bool inverted_ = {false}
PowerSupplyComponent *power_supply_ = {nullptr}
bool has_requested_high_power_ = {false}


class FloatOutput : public output::BinaryOutput

Base class for all output components that can output a variable level, like PWM.

Floating Point Outputs always use output values in the range from 0.0 to 1.0 (inclusive), where 0.0 means off and 1.0 means fully on. While using floating point numbers might make computation slower, it makes using maths much easier and (in theory) supports all possible bit depths.

If you want to create a FloatOutput yourself, you essentially just have to override write_state(float). That method will be called for you with inversion and max power already applied. It is

This interface is compatible with BinaryOutput (and will automatically convert the binary states to floating point states for you). Additionally, this class provides a way for users to set a maximum power output

Subclassed by output::ESP8266PWMOutput, output::LEDCOutputComponent, output::PCA9685OutputComponent::Channel

Public Functions

virtual void write_state(float state) = 0

Write a floating point state to hardware, inversion and max_power is already applied.

void set_max_power(float max_power)

Set the maximum power output of this component.

All values are multiplied by this float to get the adjusted value.

  • max_power: Automatically clamped from 0 to 1.

void set_state_(float state)

This is the method that is called internally by the MQTT component.

void enable()

Override BinaryOutput’s enable() and disable() so that we can convert it to float.

void disable()

Override BinaryOutput’s enable() and disable() so that we can convert it to float.

float get_max_power() const

Get the maximum power output.

void write_enabled(bool value)

Implement BinarySensor’s write_enabled; this should never be called.

template <typename T>
SetLevelAction<T> *make_set_level_action()

Protected Attributes

float max_power_ = {1.0f}