Add cookbook entry for battery levels

This commit is contained in:
Fabian Affolter 2016-01-29 10:54:39 +01:00
parent 58a9a98a66
commit e24bcbf058

View File

@ -0,0 +1,38 @@
---
layout: page
title: "Track your battery level"
description: "Basic example how to track the battery level of your mobile devices."
date: 2016-01-29 09:00
sidebar: false
comments: false
sharing: true
footer: true
---
### {% linkable_title Battery level %}
The [iCloud](/components/device_tracker.icloud/) is gathering various details about your device including the battery level. To display it in the Frontend use a [template sensor](/components/sensor.template/).
```yaml
- platform: template
sensors:
battery_iphone:
unit_of_measurement: '%'
value_template: >-
{% raw %}{%- if states.device_tracker.iphone.attributes.battery %}
{{ states.device_tracker.iphone.attributes.battery }}
{% else %}
{{ states.sensor.battery_iphone.state }}
{%- endif %}{% endraw %}
```
While running the [Owntracks](/components/device_tracker.owntracks/) device tracker you can retrieve the battery level with a MQTT sensor.
```yaml
- platform: mqtt
state_topic: "owntracks/tablet/tablet"
name: "Battery Tablet"
unit_of_measurement: "%"
value_template: {% raw %}'{{ value_json.batt }}'{% endraw %}
```