Output

The output namespace contains all peripheral output components.

API Reference

BinaryOutput

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

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.

Parameters

void turn_on()

Enable this binary output.

void turn_off()

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 Functions

virtual void write_state(bool state) = 0

Protected Attributes

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

FloatOutput

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::MY9231OutputComponent::Channel, output::PCA9685OutputComponent::Channel

Public Functions

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.

Parameters
  • max_power: Automatically clamped from 0 to 1.

void set_level(float state)

Set the level of this float output, this is called from the front-end.

float get_max_power() const

Get the maximum power output.

void write_state(bool value)

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

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

Protected Functions

virtual void write_state(float state) = 0

Protected Attributes

float max_power_ = {1.0f}
template <typename T>
class TurnOnAction : public Action<T>

Public Functions

TurnOnAction(BinaryOutput *output)
void play(T x)

Protected Attributes

BinaryOutput *output_
template <typename T>
class TurnOffAction : public Action<T>

Public Functions

TurnOffAction(BinaryOutput *output)
void play(T x)

Protected Attributes

BinaryOutput *output_
template <typename T>
class SetLevelAction : public Action<T>

Public Functions

SetLevelAction(FloatOutput *output)
void set_level(std::function<float(T)> &&level)
void set_level(float level)
void play(T x)

Protected Attributes

FloatOutput *output_
TemplatableValue<float, T> level_