Card-mod variables

I am using cad-mod and have the following styling that changes the background when on.
Is it possible to assign the entity as variable that can be used in the styling as I want to use this across all light buttons and don’t want to have to retype the entity name each time.
Or… maybe there is a better way.
Thanks in advance.

type: custom:mushroom-light-card
entity: light.terrace_front_door_left
use_light_color: true
show_brightness_control: true
collapsible_controls: false
fill_container: false
secondary_info: state
tap_action:
  action: toggle
hold_action:
  action: more-info
card_mod:
  style: |
    ha-card {
      background: {% if is_state('light.terrace_front_door_left', 'on') %}
                    {% set r = state_attr('light.terrace_front_door_left', 'rgb_color')[0] %}
                    {% set g = state_attr('light.terrace_front_door_left', 'rgb_color')[1] %}
                    {% set b = state_attr('light.terrace_front_door_left', 'rgb_color')[2] %}
                    rgba({{r}}, {{g}}, {{b}}, 0.4) !important
                  {% else %}
                    var(--card-background-color)
                  {% endif %};
    }

Temlplates have the config variable which is the card config, and then you can use config.entity

what Darryn says, and you can probably also use the rgba(from r g b / 0.4) technique and only use the config.entity once

uix:
  style: |
    ha-card {
      {% set rgb = state_attr(config.entity,'rgb_color')| join(', ') %}
      background: rgba(from rgb({{ rgb }}) r g b /0.4);
    }

and then add the template for state check on

{% if is_state(config.entity, 'on') %}

together

uix:
  style: |
    ha-card {
      background: 
      {% if is_state(config.entity, 'on') %}
        {% set rgb = state_attr(config.entity,'rgb_color')| join(',') %}
         rgba(from rgb({{ rgb }}) r g b /0.4)
      {% else %} var(--card-background-color)
      {% endif %};
    }

read up on that relative color at Using relative colors - CSS | MDN

btw since the attribute is formatted (r,g,b)

you could even leave out that join filter and use them as follows

uix:
  style: |
    ha-card {
      background: 
      {% if is_state(config.entity, 'on') %}
        {% set rgb = state_attr(config.entity,'rgb_color') %}
         rgba(from rgb{{ rgb }} r g b /0.4)
      {% else %} var(--card-background-color)
      {% endif %};
    }

where

rgba(from rgb{{ rgb }} r g b /0.4)

evaluates to

rgba(from rgb(r,g,b) r g b /0.4)

which is the exact format you need

thank you all solved now