If you have not tried AI, you should!

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

image

FUN FUN FUN!

Ask Gemini to review your entire Automations.scripts file and see what it says! :slight_smile:

I wouldn’t completely rely on it. The code it provide is fairly convoluted.

I’d also suggest avoiding capitalized letters when naming entities.

Here is a consolidated method for the same code you posted

type: custom:mushroom-template-card
entity: cover.Bobs_garage_door_door
primary: Garage Door
secondary: |
  {% set s = states(entity) %}
  {% if s == 'opening'%} Opening
  {% elif s == 'open' %} Opened
  {% elif s == 'closing' %} Closing
  {% elif s == 'closed' %} Closed
  {% endif %}
  {{ relative_time(states[entity].last_changed) }}
icon: |-
  {% set s = states(entity) %}
  {% if s == 'open'%} mdi:garage-open
  {% elif s == 'opening' or s == 'closing' %} mdi:garage-alert
  {% elif s == 'closed' %} mdi:garage
  {% endif %} 
icon_color: |-
  {% set s = states(entity) %}
  {% if s == 'open'%} red
  {% elif s == 'opening' or s == 'closing' %} yellow 
  {% elif s == 'closed' %} green
  {% else %}
    grey
  {% endif %} 
tap_action:
  action: toggle
layout: horizontal