The output namespace contains all peripheral output components.

API Reference


class output::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 output::BinaryOutputwrite_enabled(bool enabled) = 0

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

void output::BinaryOutputset_inverted(bool inverted)

Set the inversion state of this binary output.

void output::BinaryOutputset_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 output::BinaryOutputenable()

Enable this binary output.

void output::BinaryOutputdisable()

Disable this binary output.

bool output::BinaryOutputis_inverted() const

Return whether this binary output is inverted.

PowerSupplyComponent *output::BinaryOutputget_power_supply() const

Return the power supply assigned to this binary output.

Protected Attributes

bool output::BinaryOutputinverted_ = {false}
PowerSupplyComponent *output::BinaryOutputpower_supply_ = {nullptr}
bool output::BinaryOutputhas_requested_high_power_ = {false}


class output::FloatOutput

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

Inherits from output::BinaryOutput

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

Public Functions

virtual void output::FloatOutputwrite_state(float state) = 0

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

void output::FloatOutputset_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 output::FloatOutputset_state_(float state)

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

void output::FloatOutputenable()

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

void output::FloatOutputdisable()

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

float output::FloatOutputget_max_power() const

Get the maximum power output.

void output::FloatOutputwrite_enabled(bool value)

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

Protected Attributes

float output::FloatOutputmax_power_ = {1.0f}