
* Update attribute
Update `device tracker` attribute to reflect changes in iOS app with release of 2.0/2019
* Change known_devices.yaml example explanation
iOS App 2.0/2019 no long users `known_devices.yaml` so change explanation of example to something that does.
Reword
* Update notification example
Update example automation to reflect changes in in ios app (now used cross-platform domain `mobile_app`)
* Update to reference companion apps
The simplest solution to get battery level is with the companion apps so this should be made clear.
* Add android
We have an android app now 🎉
2.2 KiB
title, description, ha_category
title | description | ha_category |
---|---|---|
Track your phone battery level | Basic example how to track the battery level of your mobile devices. | Automation Examples |
Android and iOS Devices
The Home Assistant Companion Apps for iOS and Android pass the current battery level to Home Assistant with every location update. The default name of the sensor used is sensor.battery_level
.
iOS Devices
If you have a device running iOS (iPhone, iPad, etc), The iCloud integration 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 state_attr('device_tracker.iphone', 'battery') %}
{{ state_attr('device_tracker.iphone', 'battery')|round }}
{% else %}
{{ states('sensor.battery_iphone') }}
{%- endif %}
device_class: battery
{% endraw %}
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.
{% raw %}
sensor:
- platform: mqtt
state_topic: "owntracks/username/deviceid"
name: "Battery Tablet"
unit_of_measurement: "%"
value_template: '{{ value_json.batt }}'
device_class: battery
{% endraw %}
HTTP
If you have configured Owntracks to send reports to your Home Assistant instance via HTTP you can use a template sensor.
Replace deviceid
with the set Device ID in Owntracks.
{% raw %}
sensor:
- platform: template
sensors:
your_battery_sensor_name:
value_template: "{{ state_attr('device_tracker.deviceid', 'battery_level') }}"
unit_of_measurement: '%'
{% endraw %}