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
46 changes: 46 additions & 0 deletions source/_components/sensor.template.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ sensor:
description: Name to use in the frontend.
required: false
type: string
friendly_name_template:
description: Defines a template for the name to be used in the frontend (this overrides friendly_name).
required: false
type: template
entity_id:
description: A list of entity IDs so the sensor only reacts to state changes of these entities. This can be used if the automatic analysis fails to find all relevant entities.
required: false
Expand Down Expand Up @@ -244,3 +248,45 @@ sensor:
{% endif %}
```
{% endraw %}

### {% linkable_title Change the Friendly Name Used in the Frontend %}

This example shows how to change the `friendly_name` based on a date.
Explanation: we add a multiple of 86400 seconds (= 1 day) to the current unix timestamp to get a future date.

{% raw %}
```yaml
sensor:
- platform: template
sensors:
forecast_1_day_ahead:
friendly_name_template: >-
{%- set date = as_timestamp(now()) + (1 * 86400 ) -%}
{{ date|timestamp_custom("Tomorrow (%-m/%-d)") }}
value_template: "{{ sensor.darksky_weather_forecast_1 }}"
forecast_2_days_ahead:
friendly_name_template: >-
{%- set date = as_timestamp(now()) + (2 * 86400 ) -%}
{{ date|timestamp_custom("%A (%-m/%-d)") }}
value_template: "{{ sensor.darksky_weather_forecast_2 }}"
```
{% endraw %}

This example shows how to change the `friendly_name` based on a state.

{% raw %}
```yaml
sensor:
- platform: template
sensors:
net_power:
friendly_name_template: >-
{% if states('sensor.power_consumption')|float < 0 %}
Power Consumption
{% else %}
Power Production
{% end %}
value_template: "{{ states('sensor.power_consumption') }}"
unit_of_measurement: 'kW'
```
{% endraw %}