I have been an Avid HA user for 5+ years now. Professional IT guy. always HATED the ticky-tack syntax of Jinja…
The following Grok request is NOT verbatim. I played around with it for about 3-4 queries before landing on the code. Even if it is not perfect, it always gets me pointed in the right direction.
Grok - Create me a Home Assistant 2025.3 mushroom card that does the following:
changes color, tests for errors, always shows current state, change icon color and text to display current state. my garage door entity is cover.Bobs_garage_door_door
code produced by Grok:
type: custom:mushroom-template-card
primary: Bob's Door
secondary: >-
{%- set state = states('cover.Bobs_garage_door_door') -%} {%- if state ==
'unavailable' -%}
Status Unknown
{%- elif state in ['opening', 'closing'] -%}
{{ state|title }}
{%- else -%}
{%- set duration = (as_timestamp(now()) - as_timestamp(states.cover.Bobs_garage_door_door.last_changed)) | int -%}
{%- set mins = duration // 60 -%}
{{ 'Closed' if state == 'closed' else 'Open' }}
{%- if mins >= 60 -%}
-{{ (mins / 60)|round(1) }} hours
{%- else -%}
-{{ mins|round(0)|int }} min
{%- endif -%}
{%- endif -%}
icon: >-
{%- set state = states('cover.Bobs_garage_door_door') -%} {%- if state in
['opening', 'closing'] -%}
{{ state_attr('cover.Bobs_garage_door_door', 'icon') | default('mdi:garage-alert') }}
{%- elif state == 'unavailable' -%}
mdi:garage-alert-variant
{%- elif state == 'closed' -%}
mdi:garage
{%- else -%}
mdi:garage-open
{%- endif %}
grid_options:
columns: 4
rows: 1
entity: cover.bobs_garage_door_door
icon_color: |-
{%- set state = states('cover.Bobs_garage_door_door') -%}
{%- if state == 'unavailable' -%}
grey
{%- elif state == 'closed' -%}
teal
{%- else -%}
amber
{%- endif %}
multiline_secondary: true
tap_action:
action: toggle
FUN FUN FUN!
Ask Gemini to review your entire Automations.scripts file and see what it says!