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 typestd::string
. Has to be in brackets{}
!return {};
if you don't want to publish a new state (advanced).
- 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 tonever
to disable updates. Defaults to60s
. - id (Optional,
config-id
): Manually specify the ID used for code generation. - All other options from
Text Sensor <config-text_sensor>
.
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");
/components/text_sensor/index
automation
template/text_sensor/template_text_sensor.h
Edit