I have a custom button card which “works” but I am trying to modify now to adapt to the garbage being now a standard calendar entry.
This is the code for the button:
button_sidebar_small_garbage:
template: button_sidebar_big
styles:
grid:
- position: relative
custom_fields:
garbage:
- background-color: >
[[[
if (states['sensor.general_trash'].state <= 1)
return "red";
if (states['sensor.general_trash'].state >= 5)
return "green";
return "orange";
]]]
- border-radius: 50%
- position: absolute
- left: 70%
- top: 10%
- height: 15px
- width: 15px
- font-size: 10px
- line-height: 15px
recycling:
- color: >
[[[
if (states['sensor.recycling_trash'].state >= 7)
return "transparent";
if (states['sensor.recycling_trash'].state <= 1)
return "green"
return "orange";
]]]
- border-radius: 50%
- position: absolute
- left: 70%
- top: 60%
- height: 15px
- width: 15px
- font-size: 15px
- line-height: 15px
- animation: >
[[[
if (states['sensor.general_trash'].state >= 6)
return ;
if (states['sensor.general_trash'].state <= 2)
return "blink 0.75s ease infinite"
return "blink 5s ease infinite";
]]]
card:
- width: 55px
- height: 55px
- margin: 5px
- margin-top: 10px
icon:
- width: 50px
- height: 50px
state:
- value: 0
icon: mdi:trash-can-outline
styles:
icon:
- color: 'green'
- animation: blink 1s ease infinite
- value: 1
icon: mdi:trash-can
styles:
icon:
- color: 'green'
- animation: blink 1s ease infinite
- value: 2
icon: mdi:trash-can
styles:
icon:
- color: 'orange'
- animation: blink 2s ease infinite
custom_fields:
garbage: >
[[[
return states['sensor.general_trash'].state ;
]]]
recycling:
>
<b>♽</b>
Just realized that I need to access the attribute of the sensor called days, vs the state.
Right now, the calendar state returns 2.
Needs to return the number of days, which is a sensor attribute.
I can do it in jinja
{{state_attr('sensor.general_trash', 'days')}}
How do I integrate into my code?
On a related note, what are the best coding resources for learning YAML and jinja for Home Assistant? So far I have been learning by reading examples and adapting, but get stuck in what should be simple adaptations. Would like to learn the concepts and structure…