Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions source/_components/template.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down