I created a separate calendar for each of my events, then i created a template sensors with calendar entities, which show days to event. Then you can show these sensors in a button card.
I’m not saying it’s the shortest way to do it, but it works…
- name: waste can #this sensor shows next trash to prepare
state: >
{% set black = states('sensor.other_waste')|int %}
{% set yellow = states('sensor.plastic_waste')|int %}
{% set brown = states('sensor.bio_waste')|int %}
{% set delta_room = [black ,yellow, brown] %}
{% set min_delta = min(delta_room) %}
{% set x = delta_room.index(min_delta) %}
{%if x == 0%}
Other waste
{%elif x==1%}
Plastic waste
{%elif x==2%}
Bio waste
{%else%}
Error!
{% endif %}
- name: trash days left
state: >
{%if states('sensor.waste_can') == 'Other waste'%}
{%if states('sensor.other_waste')=='0'%}
today
{%elif states('sensor.other_waste')=='1'%}
tomorrow
{%else%}
in {{states('sensor.other_waste') }} days
{% endif %}
{%elif states('sensor.waste_can')=='Plastic waste'%}
{%if states('sensor.plastic_waste')=='0'%}
today
{%elif states('sensor.plastic_waste')=='1'%}
tomorrow
{%else%}
in {{states('sensor.plastic_waste')}} days
{% endif %}
{%elif states('sensor.waste_can')=='Bio waste'%}
{%if states('sensor.bio_waste')=='0'%}
today
{%elif states('sensor.bio_waste')=='1'%}
tomorrow
{%else%}
in {{states('sensor.bio_waste')}} days
{% endif %}
{%else%}
Error!
{% endif %}
You can name sensors or bins whatever you want - this is translated from slovenian language to english for better understanding.
type: custom:button-card
styles:
icon:
- color: |
[[[
var type = entity.entity_id.split(".")[0];
if (type == "switch")
return 'green';
else
return 'xxxxxxxxxxx';
]]]
where “xxxxxxxxxxx” can be omitted, empty, “unset”, “initial”, “inherited”.
Probably you MUST specify a color always, there is no fallback to a “default color”.
Ildar, that’s pretty bad, because I only need to change the colors of specific entities, the rest I want to use their “default” color, which is the color they used depending on their state… Is there a way to know this color?
In fact, if I omit the last else case, which would be what I would like to do, the color is always white ? That’s pretty bad, right?
Ildar, thank you very much for your suggestion! As soon as I’ll try it, I’ll let you know if it works, which I guess it will!! I suspected that you will recommend me to use card_mod !! It would be nice that the custom button card developer would fix that…
Ildar, using cad_mod works quite well !! Many thanks!
Now I need to check if a variable I use for a select entity is not null and if it’s not null check whether the value is the same of the state of the entity to change the color. How do I do this in jinja2 ? Sorry for my lack of knowledge…
The following is the code in custopm button card:
if (variables.var_select_option_value) {
if (states[entity.entity_id].state == variables.var_select_option_value) {
return "rgb(0,100,255)";
} else {
return "Silver";
};
};
Basically I need to know how to call a variable, for the entity I just used the code of your example and I need to add the above code into the below code:
that might be a problem, because that is something that lives in the Frontend, and Jinja is connected with backend…
It makes me speak out my earlier thought, on why you would want to write this ‘generic’ template for all button cards? why not only do this on these specific cards, so you can leave out that test.
Could any CSS gurus help me with this. What I am trying to achieve is the fade in animation on page load. And then when I hover over the card, transition the opacity again. The opacity on hover changes but it does not respect the duration/fade.
Marius, because I have many cards with the same needs… So basically it’s not possible to read a variable set in each card? Unless it’s the main entity? That’s pretty frustrating?
I’ll need to fing a workaround…
Ildar, if this is possible it would be amazing!
I tried the following code, but it doesn’t seem to work, unfortunately. I might have done something wrong?: