From e881649c1a5f355cf121f8bd27c7388f32a16afa Mon Sep 17 00:00:00 2001 From: Simon Date: Wed, 25 Sep 2019 21:31:56 +0200 Subject: [PATCH] Add a way to retrieve battery level via HTTP (#10437) * Add a way to retrieve battery level via HTTP The MQTT way of receiving data only seems to work if you have configured a MQTT backend. Added a template sensor to get the battery level with a HTTP Owntracks backend. This way is tested on my Hometracks system. * Apply direct suggestions from code review Added the easy changes where @frenck gets attributed Co-Authored-By: Franck Nijhof * Applied suggestion to value_template Changed the way the value_template gets the battery_level as suggested by @frenck . Tested on my system to make sure it works. Co-Authored-By: Franck Nijhof --- source/_cookbook/track_battery_level.markdown | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/source/_cookbook/track_battery_level.markdown b/source/_cookbook/track_battery_level.markdown index d61575426ad..95a5a831de2 100644 --- a/source/_cookbook/track_battery_level.markdown +++ b/source/_cookbook/track_battery_level.markdown @@ -27,8 +27,12 @@ sensor: {% endraw %} ### Android and iOS Devices +While running the [Owntracks](/components/device_tracker.owntracks/) device tracker you can retrieve the battery level. +How you achieve this depends on how you have configured your Owntracks instance. -While running the [Owntracks](/components/device_tracker.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. +#### 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 %} ```yaml @@ -41,3 +45,19 @@ sensor: 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 %} +```yaml +sensor: +- platform: template + sensors: + your_battery_sensor_name: + value_template: "{{ state_attr('device_tracker.deviceid', 'battery_level') }}" + unit_of_measurement: '%' +``` +{% endraw %}