mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-06-05 01:36:49 +00:00
1.7 KiB
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 phone 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 component is gathering various details about your device including the battery level. To display it in the Frontend use a template sensor. You can also use the battery
sensor device class to dynamically change the icon with the battery level.
{% raw %}
sensor:
- platform: template
sensors:
battery_iphone:
friendly_name: iPhone Battery
unit_of_measurement: '%'
value_template: >-
{%- if states.device_tracker.iphone.attributes.battery %}
{{ states.device_tracker.iphone.attributes.battery|round }}
{% else %}
{{ states.sensor.battery_iphone.state }}
{%- endif %}
device_class: battery
{% endraw %}
{% 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.
{% raw %}
sensor:
- platform: mqtt
state_topic: "owntracks/username/deviceid"
name: "Battery Tablet"
unit_of_measurement: "%"
value_template: '{{ value_json.batt }}'
device_class: battery
{% endraw %}