mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-21 16:27:19 +00:00
New template sensor attributes docs (#10204)
* Updated documentation for template sensor with attributes * Update template.markdown Fix documentation
This commit is contained in:
parent
15529fcbf4
commit
167d3ba340
@ -68,6 +68,15 @@ sensor:
|
||||
description: Defines a template for the entity picture of the sensor.
|
||||
required: false
|
||||
type: template
|
||||
attribute_templates:
|
||||
description: Defines templates for attributes of the sensor.
|
||||
required: false
|
||||
type: map
|
||||
keys:
|
||||
"attribute: template":
|
||||
description: The attribute and corresponding template.
|
||||
required: true
|
||||
type: template
|
||||
device_class:
|
||||
description: Sets the class of the device, changing the device state and icon that is displayed on the UI (see below). It does not set the `unit_of_measurement`.
|
||||
required: false
|
||||
@ -246,6 +255,38 @@ sensor:
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
### Add Custom Attributes
|
||||
|
||||
This example shows how to add custom attributes.
|
||||
|
||||
{% raw %}
|
||||
```yaml
|
||||
sensor:
|
||||
- platform: template
|
||||
sensors:
|
||||
my_device:
|
||||
value_template: >-
|
||||
{% if is_state('device_tracker.my_device_nmap','home') %}
|
||||
Home
|
||||
{% else %}
|
||||
{{ states('device_tracker.my_device_gps') }}
|
||||
{% endif %}
|
||||
attribute_templates:
|
||||
latitude: >-
|
||||
{% if is_state('device_tracker.my_device_nmap','home') %}
|
||||
{{ state_attr('zone.home','latitude') }}
|
||||
{% else %}
|
||||
state_attr('device_tracker.my_device_gps','latitude')
|
||||
{% endif %}
|
||||
longitude: >-
|
||||
{% if is_state('device_tracker.my_device_nmap','home') %}
|
||||
{{ state_attr('zone.home','longitude') }}
|
||||
{% else %}
|
||||
{{ state_attr('device_tracker.my_device_gps','longitude') }}
|
||||
{% endif %}
|
||||
```
|
||||
{% endraw %}
|
||||
|
||||
### Working without entities
|
||||
|
||||
The `template` sensors are not limited to use attributes from other entities but can also work with [Home Assistant's template extensions](/docs/configuration/templating/#home-assistant-template-extensions).
|
||||
|
Loading…
x
Reference in New Issue
Block a user