Skip to content

Latest commit

 

History

History
86 lines (62 loc) · 2.46 KB

template.rst

File metadata and controls

86 lines (62 loc) · 2.46 KB

Template Text Sensor

The template text sensor platform allows you to create a text sensor with templated values using lambdas <config-lambda>.

# Example configuration entry
text_sensor:
  - platform: template
    name: "Template Text Sensor"
    lambda: |-
      return {"Hello World"};
    update_interval: 60s

Possible return values for the lambda:

  • return {"STRING LITERAL"}; the new value for the sensor of type std::string. Has to be in brackets {}!
  • return {}; if you don't want to publish a new state (advanced).

Configuration variables:

  • name (Required, string): The name of the text sensor.
  • lambda (Optional, lambda <config-lambda>): Lambda to be evaluated every update interval to get the new value of the text sensor
  • update_interval (Optional, config-time): The interval to check the text sensor. Set to never to disable updates. Defaults to 60s.
  • id (Optional, config-id): Manually specify the ID used for code generation.
  • All other options from Text Sensor <config-text_sensor>.

text_sensor.template.publish Action

You can also publish a state to a template text sensor from elsewhere in your YAML file with the text_sensor.template.publish action.

# Example configuration entry
text_sensor:
  - platform: template
    name: "Template Text Sensor"
    id: template_text

# in some trigger
on_...:
  - text_sensor.template.publish:
      id: template_text
      state: "Hello World"

  # Templated
  - text_sensor.template.publish:
      id: template_text
      state: !lambda 'return "Hello World";'

Configuration options:

  • id (Required, config-id): The ID of the template text sensor.
  • state (Required, string, templatable <config-templatable>): The state to publish.

Note

This action can also be written in lambdas:

id(template_text).publish_state("Hello World");

See Also

  • /components/text_sensor/index
  • automation
  • template/text_sensor/template_text_sensor.h
  • Edit