Hey guys, first post here so hopefully the moderators won’t have to slam me too heavily…
I wanted to add my devices with batteries (laptops, phones etc) to my entirely mushroom-based dashboard so that they look something like this:
Now I ended up with this yaml:
chips:
- type: template
icon: |-
{% set number = (states('sensor.toddys_handset_battery_level') | int) %}
{% set state = (states('sensor.toddys_handset_battery_state')) %}
{% if (number >= 90) and (state == 'Not Charging') %}
mdi:battery
{% elif (number >= 90) and (state == 'Charging') %}
mdi:battery-charging
{% elif (number >= 80) and (state == 'Not Charging') %}
mdi:battery-80
{% elif (number >= 80) and (state == 'Charging') %}
mdi:battery-charging-80
{% elif (number >= 70) and (state == 'Not Charging') %}
mdi:battery-70
{% elif (number >= 70) and (state == 'Charging') %}
mdi:battery-charging-70
{% elif (number >= 60) and (state == 'Not Charging') %}
mdi:battery-60
{% elif (number >= 60) and (state == 'Charging') %}
mdi:battery-charging-60
{% elif (number >= 50) and (state == 'Not Charging') %}
mdi:battery-50
{% elif (number >= 50) and (state == 'Charging') %}
mdi:battery-charging-50
{% elif (number >= 40) and (state == 'Not Charging') %}
mdi:battery-40
{% elif (number >= 40) and (state == 'Charging') %}
mdi:battery-charging-40
{% elif (number >= 30) and (state == 'Not Charging') %}
mdi:battery-30
{% elif (number >= 30) and (state == 'Charging') %}
mdi:battery-charging-30
{% elif (number >= 20) and (state == 'Not Charging') %}
mdi:battery-20
{% elif (number >= 20) and (state == 'Charging') %}
mdi:battery-charging-20
{% elif (number >= 10) and (state == 'Not Charging') %}
mdi:battery-10
{% elif (number >= 10) and (state == 'Charging') %}
mdi:battery-charging-10
{% elif (number >= 0) and (state == 'Not Charging') %}
mdi:battery-outline
{% elif (number >= 0) and (state == 'Charging') %}
mdi:battery-charging-outline
{% else %}
mdi:battery
{% endif %}
entity: sensor.toddys_handset_battery_level
icon_color: |-
{% set number = (states('sensor.toddys_handset_battery_level') | int) %}
{% set state = (states('sensor.toddys_handset_battery_state')) %}
{% if (number >= 50) or (state == 'Charging') %}
green
{% elif (number <= 30) %}
red
{% else %}
orange
{% endif %}
content: iPhone {{ states('sensor.toddys_handset_battery_level') }}%
Now I know there are plenty of battery-related cards out there but I just wanted to keep it consistent with the rest of my mushroom dashboard so I tried to make my own one as you can see above.
So my question is - does anyone have any idea how to simplify the above yaml (or some other clever templating way to do it) as I want to do it for as many devices as I can and man that’s a lot of yaml…
edit: I just realised that in the first photo I have only applied the yaml to the 3rd chip so that’s why the other two are just the normal battery icon.