attributes
The attributes
platform supports sensors which break out a specified attribute
from other entities.
To enable the attributes
sensor in your installation, add the following to your configuration.yaml
file:
# Example configuration.yaml entry
sensor:
- platform: attributes
friendly_name: "Batteries"
attribute: battery_level
device_class: battery
entities:
- sensor.myslipo_1_0
- sensor.myslipo_2_0
- sensor.myslipo_3_0
- sensor.myslipo_4_0
- platform: attributes
friendly_name: "Last changed"
attribute: last_triggered
icon: 'mdi:clock'
time_format: '%e %B - %H:%M:%S'
entities:
- automation.temp_changed
Configuration variables:
strftime
type string to beautify time attribute output. Applicable only when attribute last_changed
or last_triggered
is selected. Cheatsheet for strftime formatting here.You can find this integration in the community store.
You need to copy the attributes
folder from this repo to the custom_components
folder in the root of your configuration. The file tree should look like this:
└── ...
└── configuration.yaml
└── custom_components
└── attributes
└── __init__.py
└── manifest.json
└── sensor.py
Note: if the
custom_components
directory does not exist, you need to create it.
This example shows how to extract the battery_level
attribute.
sensor:
- platform: attributes
friendly_name: "Batteries"
attribute: battery_level
unit_of_measurement: "%"
entities:
- sensor.test1
- sensor.test2
- sensor.test3
If an attribute is
battery
orbattery_level
and you don't specifyicon
ordevice_class
is notbattery
, the following icon_template is applied (fullness). The result is that the battery icon becomes as full as the battery based on percentage.
{% if batt == 'unknown' %}
{% if batt > 95 %}
mdi:battery
{% elif batt > 85 %}
mdi:battery-90
{% elif batt > 75 %}
mdi:battery-80
{% elif batt > 65 %}
mdi:battery-70
{% elif batt > 55 %}
mdi:battery-60
{% elif batt > 45 %}
mdi:battery-50
{% elif batt > 35 %}
mdi:battery-40
{% elif batt > 25 %}
mdi:battery-30
{% elif batt > 15 %}
mdi:battery-20
{% elif batt > 10 %}
mdi:battery-10
{% else %}
mdi:battery-outline
{% endif %}
{% else %}
mdi:battery-unknown
{% endif %}
This example shows how to extract the last_triggered
attribute in human-readable format.
sensor:
- platform: attributes
friendly_name: "Last changed"
attribute: last_triggered
icon: 'mdi:clock'
time_format: '%e %B - %H:%M:%S'
entities:
- automation.dummy_changed
If you select attribute
last_changed
orlast_triggered
and you specify time_format, your datetime will get translated to your local timezone and will be formatted likestrftime()
e.g., 2017-08-08T13:14:21.651894+00:00 gets translated into the specified strftime format with timezone applied. The result would be: 8 August 15:14:21 if your timezone is UTC+2