From badb6c8a17c15207de5e6f70d832b8ef9e104c38 Mon Sep 17 00:00:00 2001 From: PaulParis1 <46383511+PaulParis1@users.noreply.github.com> Date: Sun, 12 Jan 2020 10:53:15 +0100 Subject: [PATCH] Add Android example (#11686) * Add Android example Add Android example configuration * :pencil2: Tweak * :pencil2: Add information * :pencil2: Tweaks Co-authored-by: Klaas Schoute Co-authored-by: Franck Nijhof --- source/_cookbook/track_battery_level.markdown | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source/_cookbook/track_battery_level.markdown b/source/_cookbook/track_battery_level.markdown index 76051b8c5aa..3028e1322e1 100644 --- a/source/_cookbook/track_battery_level.markdown +++ b/source/_cookbook/track_battery_level.markdown @@ -29,7 +29,32 @@ sensor: ``` {% endraw %} +### Android Devices + +On your Android device, once the official [Home Assistant companion app](https://companion.home-assistant.io/) is installed and connected to your Home Assistance instance, you will be able to display the battery level in the frontend by adding a [template sensor](/integrations/template) to your configuration YAML file. You can also use the battery [sensor device class](/integrations/sensor/#device-class) to dynamically change the icon with the battery level. + +{% raw %} +```yaml +sensor: + - platform: template + sensors: + battery_phone: + friendly_name: AndroidPhone Battery + unit_of_measurement: '%' + value_template: >- + {%- if state_attr('device_tracker.xxxxx', 'battery_level') %} + {{ state_attr('device_tracker.xxxxx', 'battery_level')|round }} + {% else %} + {{ states('device_tracker.xxxxx') }} + {%- endif %} + device_class: battery +``` +{% endraw %} + +Replace 'device_tracker.xxxxx' with your phone name as shown under Configuration/Devices Device Info/Entities, for example: 'device_tracker.mi_a1' + #### MQTT + If you have configured Owntracks to send reports via MQTT you can use the received data via a MQTT sensor. Replace username with your MQTT username (for the embedded MQTT it's simply homeassistant), and deviceid with the set Device ID in Owntracks.