Button card and battery level

Hello,
I’m doing a dashboard for my phones and I’m having a issue about the battery level icon.
The battery icon show me correctly the level but, when I add the Iphone battery level, I have a “sensor” icon.
I could force a battery icon in my customize file or in the custom card, but my level didn’t change in function of my battery.
Do you have an idea about that ?
Capture

My sensor :

  - platform: template
    sensors:
      battery_iphone:
        friendly_name: "Battery iPhone"
        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

And my custom button card :

    type: horizontal-stack
  - cards:
      - color_type: icon
        entity: sensor.galaxy_s8_battery_sensor
        show_name: false
        show_state: true
        size: 20%
        tap_action:
          action: more-info
        type: 'custom:button-card'
      - color_type: icon
        entity: sensor.battery_iphone
        show_name: false
        show_state: true
        size: 20%
        tap_action:
          action: more-info
        type: 'custom:button-card'
 

Not related to your problem, but does this work?

value_template: >-
                {%- if state_attr('device_tracker.iphone', 'battery') %}
                {{ state_attr('device_tracker.iphone', 'battery')|round }}
                {% else %}
                {{ states('sensor.battery_iphone') }}
                {%- endif %}

If the battery level of the device tracker is not available it will give the state of the battery sensor you are defining, I don’t understand how this can work.

Normaly, when you give put the device_class:battery for the sensor, the icon is a battery and it changes in function of the level of battery (as you can see on my screenshot for example my S8 have 32% of battery, the icon is “battery-30” automaticly). And for my iphone, this functionality doesn’t work (I have a typical sensor icon with the eye and not a battery with the level)
Do you understand my problem ?

Yes I understand your issue, but I don’t know how to help you, for me your code looks alright.
I was just pointing out some other issue you’ll get when the battery level of the device tracker is not available.

does it have an icon if you put the sensor in a regular entities card? Just checked here and it does show properly.

just to be sure: this is the device_tracker tracking the new mobile_app device ? The old iOS tracker sensors are stale now, and not updated any longer

I use the iCloud tacking because the official app is in chinese on my phone (Post here).
But, when I add the “device_class: battery” , I should have a battery icon and the icon change in function of the level of battery, isn’t it ?
Effectively , when I use the entities card, I have the battery icon :
image
To complete, when I click on my “sensor” (the eye icon in my first post), I can see the battery icon and it change in function of the level.
image

Thank you for your help

well, you’re right!
I see that now also, didn’t have buttons with battery sensors yet, so never noticed before. Seems the buttons don’t show the device_class battery. They do show on the mobile_app battery sensors, and show on customized sensors.

You should get in touch with @romrider :wink: