Hello all,
I am trying to figure out how to properly write this, but I either get errors (bad formatting) or not a result.
Maybe anyone here with more knowledge can help me? What I am trying to do with my custom:button card is to have one icon, and then I have 2 rows that will have one icon and one date IF the date listed in the helper is AFTER today’s date.
So if I put a date into hjemmekontor helper (homeoffice) there should pop up a icon and a date, once that date passes, it should disappear.
Anyways, here is the part that won’t give me a result, and I will paste the complete code too (I have tried two different ways, that’s why “ferie” and “hjemmekontor” under custom fields are different…
custom_fields:
ferie: |
[[[
var dato = states['input_datetime.helper_dato_for_hjemmekontor'].date
if (dato > 'now().date()')
return `<ha-icon icon="mdi:beach" style="width: 25px; height: 25px; color: white;"> </ha-icon> ${states['input_datetime.helper_dato_for_hjemmekontor'].state} </span>`
]]]
hjemmekontor: |
[[[
if (states['input_datetime.helper_dato_for_hjemmekontor'].state > 'now().date()')
return `<ha-icon icon="mdi:office-building" style="width: 25px; height: 25px; color: white;"> </ha-icon> ${states['input_datetime.helper_dato_for_hjemmekontor'].state} </span>`
]]]
Complete code:
type: custom:button-card
name: Kalender
icon: mdi:calendar
show_state: false
show_name: false
size: 20px
styles:
grid:
- grid-template-areas: '"i" "ferie" "hjemmekontor"'
- grid-template-columns: 1fr
- grid-template-rows: 1fr min-content min-content
custom_fields:
ferie:
- align-self: start
- justify-self: center
hjemmekontor:
- align-self: start
- justify-self: center
custom_fields:
ferie: |
[[[
var dato = states['input_datetime.helper_dato_for_hjemmekontor'].date
if (dato > 'now().date()')
return `<ha-icon icon="mdi:beach" style="width: 25px; height: 25px; color: white;"> </ha-icon> ${states['input_datetime.helper_dato_for_hjemmekontor'].state} </span>`
]]]
hjemmekontor: |
[[[
if (states['input_datetime.helper_dato_for_hjemmekontor'].state > 'now().date()')
return `<ha-icon icon="mdi:office-building" style="width: 25px; height: 25px; color: white;"> </ha-icon> ${states['input_datetime.helper_dato_for_hjemmekontor'].state} </span>`
]]]