Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Custom Jinja macros that provide a way to get a styled battery icon based on a battery level.

License

Notifications You must be signed in to change notification settings

Nuhser/battery-icons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Battery Icons Macros

Version Last commit GitHub Repo stars
HACS

This template contains Jinja macros that can be used to convert the state of a battery in Home Assistant into either a matching Material Design Icon or a color that matches the current battery level. Both will be returned as strings and can be used in many ways.

One example of a use case would be a Mushroom Template Badge that shows the current battery state of a wall-mounted tablet.

image

Installation

Without HACS
  1. Download the contents from battery_icons.jinja from the master-branch.
  2. Add the file to your <config>/custom_templates-folder.
  3. Reload your configuration from within the developer tools in Home Assistant.
  4. The template should now be ready for use.
With HACS
  1. Search for "Battery Icons" in HACS.
  2. Download the repository via HACS.
  3. The template should now be ready for use.

You can also use this button to add the repository to your Home Assistant instance via HACS:

Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.

Documentation

battery_icon

Takes the given battery level and the current charging state and returns an Material Design Icon based on them as a string. The battery level can either be given as a number directly or as a string that will be converted.

Syntax

battery_icon(battery_level_raw, is_charging=false)

Param Type Explanation
battery_level_raw string or number Will be converted into a float and used for determining the corresponding icon.
is_charging boolean Can be used to change the icon depending on the current charging state of the battery. If omitted, the macro will never return a charging-icon. (Default: false)

Examples

Input

{%- from 'battery_icons.jinja' import battery_icon -%}
{{ battery_icon(states('sensor.wall_tablet_battery_level'), (states('binary_sensor.wall_tablet_is_charging') == 'on')) }}

Output

Depends on the current battery states. Here's one example:

mdi:battery-charging-70

battery_color

Takes the given battery level and returns a corresponding color as a string based on it. The battery level can either be given as a number directly or as a string that will be converted.

Syntax

battery_color(battery_level_raw)

Param Type Explanation
battery_level_raw string or number Will be converted into a float and used for determining the corresponding color.

Examples

Input

{%- from 'battery_icons.jinja' import battery_color -%}
{{ battery_color(states('sensor.wall_tablet_battery_level')) }}

Output

Depends on the current battery states. Here's one example:

orange

About

Custom Jinja macros that provide a way to get a styled battery icon based on a battery level.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages