Add Template Sensor device_class support (#5220)

* Add Template Sensor device_class support

* Update battery templates

* Update track battery level example
This commit is contained in:
Otto Winter 2018-05-01 20:33:26 +02:00 committed by Paulus Schoutsen
parent 77a14ad9d9
commit dcda30e25b
3 changed files with 10 additions and 28 deletions

View file

@ -32,7 +32,7 @@ Open OwnTracks and go to Connection preferences:
- Mode: Select **Private HTTP**
- Host: [Home Assistant URL]:[port]/api/owntracks/[your name]/[device name]
- Identification: Turn **Authentication** on, username `homeassistant` and password is your API password that you use to login to Home Assistant.
Host example: If I host my Home Assistant at `https://example.duckdns.org`, my name is Paulus and my phone is a Pixel I would set the host to be `https://example.duckdns.org/api/owntracks/paulus/pixel`. This will result in an entity with an ID of `device_tracker.paulus_pixel`. You can pick any name for the user and the device.
Since the battery data is available as an attribute of the device tracker entity, it can be tracked with a [`template` sensor](/components/sensor.template/).
@ -47,17 +47,6 @@ sensor:
friendly_name: Pixel of Paulus
unit_of_measurement: "%"
value_template: '{{ states.device_tracker.paulus_pixel.attributes.battery|int }}'
icon_template: >-
{% set battery_level = states.device_tracker.paulus_pixel.attributes.battery|default(0)|int %}
{% set battery_round = (battery_level / 10) |int * 10 %}
{% if battery_round >= 100 %}
mdi:battery
{% elif battery_round > 0 %}
mdi:battery-{{ battery_round }}
{% else %}
mdi:battery-alert
{% endif %}
entity_id:
- device_tracker.paulus_pixel
device_class: battery
```
{% endraw %}

View file

@ -69,6 +69,11 @@ sensor:
description: Defines a template for the entity picture of the sensor.
required: false
type: template
device_class:
description: The type/class of the sensor to set the icon in the frontend.
required: false
type: device_class
default: None
{% endconfiguration %}
## {% linkable_title Considerations %}