Android battery statuses via google maps

I have gps tracking on, working just fine on all units needed. However I must be doing something wrong.
I only get 1 battery sensor for one phone, tracking is fine on all 3 phones, but i can only get one to show up battery status.
Here is the code from configuration.yaml

 platform: template
    sensors:
      phone_battery:
        friendly_name: 'Ph 1'
        value_template: '{{states.device_tracker.google_maps_xxxxxxxxxxxxxxxx0754.attributes.battery_level | round}}'
        unit_of_measurement: '%'


  - platform: template
    sensors:
      phone_battery: 
        friendly_name: 'Ph 2'
        value_template: '{{states.device_tracker.google_maps_XXXXXXXXXXXXXXXX759.attributes.battery_level | round}}'
        unit_of_measurement: '%'

when I add the sensors in my glance, all i get listed is the Ph 1 sensor, the one for Ph 2 dont show up at all. What am I missing ?

You need to give the two sensors different names:

platform: template
    sensors:
      phone_battery_ph1:
        friendly_name: 'Ph 1'
        value_template: '{{states.device_tracker.google_maps_xxxxxxxxxxxxxxxx0754.attributes.battery_level | round}}'
        unit_of_measurement: '%'


      phone_battery_ph2: 
        friendly_name: 'Ph 2'
        value_template: '{{states.device_tracker.google_maps_XXXXXXXXXXXXXXXX759.attributes.battery_level | round}}'
        unit_of_measurement: '%'

And you don’t need the extra

platform: template
    sensors:

although I don’t think it does any harm or really makes a difference if you do.

And for an added bonus you can include this to give meaningful icons:

        icon_template: >
          {% if state_attr('device_tracker.google_maps_xxxxxxxxxxxxxxxx0754', 'battery_charging') %}
            {% set charging = 'charging-' %}
          {% endif %}  
          {% set battery_level = state_attr('device_tracker.google_maps_xxxxxxxxxxxxxxxx0754', 'battery') | default(0) | int %}
          {% set battery_round = (battery_level / 10) | int * 10 %}
          {% if battery_round >= 100 %}
            mdi:battery
          {% elif battery_round > 0 %}
            mdi:battery-{{ charging }}{{ battery_round }}
          {% else %}
            mdi:battery-alert
          {% endif %}
3 Likes

Thank you !! that was super easy… The icon template, you linking to, would it just go at the end of the battery sensors ?

yep.

        unit_of_measurement: '%'
        icon_template: >
1 Like

Thank you again !
started with my first raspi 2 weeks ago, so a little steep learning curve, but slowly getting there :slight_smile: Will the icon change when charging ?

Yes, so long as Google reports it as charging but I have found that a bit slow sometimes.

Keep at it. If my experience is anything to go by you might hit a slump in about another two weeks!! But remember it will get easier and many things will suddenly make a lot more sense.

And there are a ton of very helpful people (much more so than me) here if you get stuck.

1 Like

Yeah I have noticed, people are really helpful, just like you. Well I have been bitten badly by the whole home automation bug, so thats why there are 2 more raspi units in the mail on the way here. :slight_smile:

Regarding the icon script, it seems its showing the battery icon with the ! mark inside (guessing the battery alert) all the time even if not charging or low battery.

That’s strange.
Have you looked in the Dev States page to see what it reports for battery_charging?
image

also you can put the whole template into the Dev Template page and see what mdi-icon it is returning
image