home-assistant.io/source/_cookbook/track_battery_level.markdown
Eirik H c08e19578a Describe the state_topic setting for battery tracking using Owntracks (#3322)
I wasn't sure what the /tablet/tablet section of the state_topic part meant so had to google a bit to figure it out. With this change, users will immediately understand what they should set as the topic.
2017-09-08 09:22:19 +02:00

1.7 KiB

layout, title, description, date, sidebar, comments, sharing, footer, ha_category
layout title description date sidebar comments sharing footer ha_category
page Track your battery level Basic example how to track the battery level of your mobile devices. 2016-01-29 09:00 true false true true Automation Examples

{% linkable_title iOS Devices %}

If you have a device running iOS (iPhone, iPad, etc), The iCloud is gathering various details about your device including the battery level. To display it in the Frontend use a template sensor.

sensor:
  - platform: template
    sensors:
      battery_iphone:
        unit_of_measurement: '%'
        value_template: >-
            {% raw %}{%- if states.device_tracker.iphone.attributes.battery %}
                {{ states.device_tracker.iphone.attributes.battery|round }}
            {% else %}
                {{ states.sensor.battery_iphone.state }}
            {%- endif %}{% endraw %}

The else part is used to have the sensor keep it's last state if the newest iCloud update doesn't have any battery state in it (which happens sometimes). Otherwise the sensor will be blank.

{% linkable_title Android and iOS Devices %}

While running the Owntracks device tracker you can retrieve the battery level with 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.

sensor:
  - platform: mqtt
    state_topic: "owntracks/username/deviceid"
    name: "Battery Tablet"
    unit_of_measurement: "%"
    value_template: {% raw %}'{{ value_json.batt }}'{% endraw %}