Custom Text Sensor

This integration can be used to create custom text sensors in esphomelib using the C++ (Arduino) API.

Please first read Custom Sensor Component guide, the same principles apply here and text sensors are very similar to sensors internally.

The example below is an example of a custom text sensor which constantly publishes the message “Hello World!”.

#include "esphomelib.h"
using namespace esphomelib;

class MyCustomTextSensor : public PollingComponent, public text_sensor::TextSensor {
  // constructor
  MyCustomTextSensor() : PollingComponent(15000) {}

  void setup() override {
    // This will be called by App.setup()
  void update() override {
    // This will be called every "update_interval" milliseconds.
    // Publish state
    publish_state("Hello World!");

(Store this file in your configuration directory, for example my_text_sensor.h)

And in YAML:

# Example configuration entry
    - my_text_sensor.h

- platform: custom
  lambda: |-
    auto my_custom_sensor = new MyCustomTextSensor();
    return {my_custom_sensor};

    name: "My Custom Text Sensor"

Configuration variables:

  • lambda (Required, lambda): The lambda to run for instantiating the text sensor(s).

  • text_sensors (Required, list): A list of text sensors to initialize. The length here must equal the number of items in the return statement of the lambda.

See text_sensor::TextSensor