Text Sensor

See Application::register_text_sensor().

API Reference


class TextSensor : public Nameable

Subclassed by text_sensor::MQTTSubscribeTextSensor, text_sensor::TemplateTextSensor, text_sensor::VersionTextSensor

Public Functions

TextSensor(const std::string &name)
void publish_state(std::string state)
void set_icon(const std::string &icon)
void add_on_state_callback(std::function<void(std::string)> callback)
std::string get_icon()
std::string icon()
std::string unique_id()
TextSensorStateTrigger *make_state_trigger()
bool has_state()

Public Members

std::string state

Protected Attributes

CallbackManager<void(std::string)> callback_
optional<std::string> icon_
bool has_state_ = {false}
class TextSensorStateTrigger : public Trigger<std::string>

Public Functions

TextSensorStateTrigger(TextSensor *parent)


class MQTTTextSensor : public mqtt::MQTTComponent

Public Functions

MQTTTextSensor(TextSensor *sensor)
void send_discovery(JsonObject &root, mqtt::SendDiscoveryConfig &config)

Send discovery info the Home Assistant, override this.

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.

void dump_config()
void publish_state(const std::string &value)
void send_initial_state()
bool is_internal()

Protected Functions

std::string component_type() const

Override this method to return the component type (e.g. “light”, “sensor”, …)

std::string friendly_name() const

Get the friendly name of this MQTT component.

Protected Attributes

TextSensor *sensor_