This works for auto-entities because it’s an attribute of the entity, however when using the template-card you wouldn’t define an entity but a value that comes from jinja template so this won’t work out of the box.
This is going to be a big challenge. It’s too bad that Lovelace itself or Card-Tools doesn’t provide a way to handle entities, values, attributes in a consistent way that can be used in any card…
Currently setting the bar direction is the only option. Also I did look into adding a value config option so you can use the template card, but this seems to be a bit more tricky than I had first thought. But i’ll see if I can add this to a future release.
Release 0.1.5 adds optimizations for the card CSS styles. For some reason I had over-complicated the way the colors are being used, so this should make the card perform better on low-end devices.
Seems there is no way to set the colour of the ‘blank’ part of the bar, only to set the hue of the’used’ portion… So I can’t reverse the colours on the bar it seems.
My value of days left is decreasing every day… I could create a template sensor that goes the other direction but it honestly seems silly to have to do that. I’m using the template card just so I can avoid having to create 20 different sensors.
Yea I know hue isn’t the most common way of defining the color, however this is part of some of the logic I started out with. I’m looking into making it possible to define a color instead of a color hue.
Any chance we could use an attribute to set the maximum or minimum? In my case, I’m showing number of days and that could be anywhere between 28 and 31 days in a month but I have an attribute that says how many days in the current cycle… would be great to be able to use that instead of a static value.
I would say this is a perfect use case for the config-template-card if you’re using a single entity per card config (as in not using the entities list). For the next release I will make it so if no min or max is configured it will look for a min and max value in the attributes for the entity.
But then will the entity attributes need to include min and max keys? I’m already using the attribute for the card’s value… why not just allow attributes for min/max as well?
This is my card:
- type: 'custom:bar-card'
title: Month Use
entity: sensor.abb_usage
attribute: daysUsed
min: 0
max: 31
height: 20px
direction: right
unit_of_measurement: days
These are the attributes for the entity
So yeah… The daysTotal changes each month of course so setting max to that attribute works
Well this is basically what the template card is for. However I’ve added an option to defined the attribute in the card config in version 0.1.6.
Plus some more new features like setting the color instead of hue and the option to let the bar drain instead of fill.
I will most likely remove the hue option in a future release, but for now you can use either.
added color config option, hue will be deprecated in future release
severity will now accept color attribute instead of hue attribute, hue attribute will be deprecated in future release
added left-reverse, right-reverse, up-reverse, down-reverse options to direction config option
min,max and target will now also accept an attribute object
I never said it doesn’t, but the template card only works for anything that is not the entity since that expects it to be an actual entity_id. Min or max for example expect a number which the template card generates, so in this case it will work.