How to get the battery level?

No data for me while I enabled app in the config and reinstalled the app. Also, how is the battery drain compared to Google Maps location sharing? Since that has a LOT of data and I don’t seem to notice any drain.

For anyone else who found this thread with similar issues like me:

I also had to add mobile_app: to my configuration file and then reinstall the Android app for the integration to show up.

After the integration showed up it the entity only showed “unknown” for its state. It showed the proper data finally after I changed my reporting in OwnTracks (on the same device) to manual reporting in the OwnTracks app. I’m not sure if its correlation or causation, but I feel like I tried everything else (uninstall app, remove and re-add integration, restarting my Home Assistant server all along the way).

Hope that helps!

Anybody can help me please…
I dont have in my Home Assistant State like device_tracker…
I have installed latest version Mobile App 1.1.1(32)
In integration i dont have integration Mobile app but when i try add i get info to go web page and see compatible application.

In configuration i add mobile_app: but nothing change.

EDIT
I clear cache and memory for app on my smartphone and again config connection with HA. Now show the same as @xalex75 , that show only
device_tracker.ELM-L29 unknow and source_type: GPS and friendly name. No show any other info.

EDIT
Ok when disable localization in Android and again Enable show for me all info.

Mine got infos after about 2 hours.
But after that it stopped updating. Yesterday when I went home, it was still showing me at work, and this morning too.

Mine looks fine, both battery & GPS info are correct today as well. Power settings on your HA app, maybe? I think Huawei’s default behavior is very aggressive about stuff like that…

Mine started working with location after a while. Seems to work fine when I’m not home, but last night when I was sleeping it had like tens of false reports that I was not home. My home radius is pretty big, so it’s jumping all over the place it seems. My Google Maps sharing location is way more accurate it seems!

I didn’t have any issues with my location being “unknown”, but I do keep getting inaccurate locations. It seems to keep defaulting back to reporting me as “home” for short periods of time before getting an accurate reading again. For example it correctly reported when I left the house and got to work today, but then has multiple 1-5 minutes periods where it reports me as home before switching back to work. I tried changing the battery optimization settings but it’s still doing it. I switched back to google location reporting for now.

I’m having similar issues again, where my location is not being updated and my logs are now showing a “received invalid webhook payload” error in my home assistant logs. The mobile app appears to be trying to report a negative value for my altitude. I wonder if that has something to do with it

It is possible to get the sensor out of this entity, I mean, I would like to have a separate sensor to have kind of alarm when the battery is low?

Yes, you create a template sensor and point it to the attribute battery_level.

2 Likes

Create a Template Sensor (https://www.home-assistant.io/integrations/template/).

sensor:
  - platform: template
    sensors:
      phone_battery:
        friendly_name: "Phone Battery"
        unit_of_measurement: '%'
        value_template: "{{ state_attr('device_tracker.sm_g975u_2', 'battery_level') }}"
2 Likes

thanks flamingm0e
I’m trying to do that, but i’m quite new and its the first sensor i’ll create, I’m following this:

but I don’t know how to include that on the configuration

at the moment i have this but is not working

sensor:
  - platform: template
    sensors:
      phonebatt:
        friendly_name: "bateria telefono"
        unit_of_measurement: '%'
        value_template: "{{ states_sensor.battery_level.attributes['Battery Level']}}"

what i’m doing wrong???
thanks

You can also get it using:

- platform: template
  sensors:
    phone_battery:
      friendly_name: "Phone Battery"
      unit_of_measurement: "%"
      value_template: "{{ states.device_tracker.oneplus_a6003.attributes.battery_level | round(0) }}"
      device_class: battery
3 Likes

You have to tell it what sensor to read the attributes of. You can’t be so generic and expect it to know what sensor you want the battery level from.

1 Like

yeah, that is was I suspect, but I don’t know where to include that info
my device is call sm-g930F, where I can include this on my actual config??

There are 2 examples, literally right there…

You should follow the user documentation, and not the developer documentation.

ok, a lot to learn here yet,
after reading this


and this

I think my problem is on the line
value_template: "{{ states_sensor.battery_level.attributes['device_tracker.sm_g930f', Battery Level']}}"
I’m having a syntax error, but my knowledge on this is not enough yet

Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: expected token ‘,’, got ‘Level’) for dictionary value @ data[‘sensors’][‘phone_battery’][‘value_template’]. Got “{{ states_sensor.battery_level.attributes[‘device_tracker.sm_g930f’, Battery Level’]}}”. (See ?, line ?). Please check the docs at https://home-assistant.io/integrations/template/

Are you really not reading the comments here?

Seriously. 2 of us gave you perfectly working examples, but it’s YOUR responsibility to change the device tracker to be named correctly.

thanks flamingm0e
just trying to learn how its works, of course if I just copied that it will work, but thats not my point here.
I was trying to follow home assistant companion documentation to make it works. Probably its my lack of knowledge in any type of programing.
Anyway, its working now. I’m using
value_template: "{{state_attr('device_tracker.sm_g930f', 'battery_level')}}"

`