Card-templater help?

I can’t seem to get this card to work.

I’m trying to use it with picture-elements.

Essentially like this (with a few "elements" below which have been omitted here)
type: custom:card-templater
entities:
  - cover.model_y_charger_door
  - cover.model_y_trunk
  - cover.model_y_frunk
  - binary_sensor.model_y_doors
card:
  type: picture-elements
  image_template: >-
    {% set open_states = ['open', 'on', 'true'] %} {% set
    closed_states = ['closed', 'off', 'false'] %} {% set charger_door
    = states('cover.model_y_charger_door') %} {% set trunk =
    states('cover.model_y_trunk') %} {% set frunk =
    states('cover.model_y_frunk') %} {% set driver_front =
    state_attr('binary_sensor.model_y_doors', 'driver_front') %} {%
    set driver_rear = state_attr('binary_sensor.model_y_doors',
    'driver_rear') %} {% set passenger_front =
    state_attr('binary_sensor.model_y_doors', 'passenger_front') %} {%
    set passenger_rear = state_attr('binary_sensor.model_y_doors',
    'passenger_rear') %}

    {# Determine the trunk and port status #} {% set trunks_or_ports =
    'no_trunks_or_ports_open' %} {% if charger_door in open_states and
    trunk in closed_states and frunk in closed_states %}
      {% set trunks_or_ports = 'charging_port_open' %}
    {% elif charger_door in open_states and trunk in open_states and
    frunk in closed_states %}
      {% set trunks_or_ports = 'charging_port_and_trunk_open' %}
    {% elif charger_door in open_states and trunk in closed_states and
    frunk in open_states %}
      {% set trunks_or_ports = 'charging_port_and_frunk_open' %}
    {% elif charger_door in open_states and trunk in open_states and
    frunk in open_states %}
      {% set trunks_or_ports = 'charging_port_trunk_frunk_open' %}
    {% elif charger_door in closed_states and trunk in open_states and
    frunk in closed_states %}
      {% set trunks_or_ports = 'trunk_open' %}
    {% elif charger_door in closed_states and trunk in closed_states
    and frunk in open_states %}
      {% set trunks_or_ports = 'frunk_open' %}
    {% elif charger_door in closed_states and trunk in open_states and
    frunk in open_states %}
      {% set trunks_or_ports = 'frunk_and_trunk_open' %}
    {% endif %}

    {# Determine the door status #} {% set doors_open =
    'no_doors_open' %} {% if driver_front in open_states and
    driver_rear in closed_states and passenger_front in closed_states
    and passenger_rear in closed_states %}
      {% set doors_open = 'front_left_door_open' %}
    {% elif driver_front in closed_states and driver_rear in
    closed_states and passenger_front in open_states and
    passenger_rear in closed_states %}
      {% set doors_open = 'front_right_door_open' %}
    {% elif driver_front in closed_states and driver_rear in
    open_states and passenger_front in closed_states and
    passenger_rear in closed_states %}
      {% set doors_open = 'back_left_door_open' %}
    {% elif driver_front in closed_states and driver_rear in
    closed_states and passenger_front in closed_states and
    passenger_rear in open_states %}
      {% set doors_open = 'back_right_door_open' %}
    {% elif driver_front in open_states and driver_rear in
    closed_states and passenger_front in open_states and
    passenger_rear in closed_states %}
      {% set doors_open = 'both_front_doors_open' %}
    {% elif driver_front in closed_states and driver_rear in
    open_states and passenger_front in closed_states and
    passenger_rear in open_states %}
      {% set doors_open = 'both_back_doors_open' %}
    {% elif driver_front in open_states and driver_rear in open_states
    and passenger_front in closed_states and passenger_rear in
    closed_states %}
      {% set doors_open = 'both_left_doors_open' %}
    {% elif driver_front in closed_states and driver_rear in
    closed_states and passenger_front in open_states and
    passenger_rear in open_states %}
      {% set doors_open = 'both_right_doors_open' %}
    {% elif driver_front in open_states and driver_rear in
    closed_states and passenger_front in closed_states and
    passenger_rear in open_states %}
      {% set doors_open = 'front_left_and_back_right_doors_open' %}
    {% elif driver_front in closed_states and driver_rear in
    open_states and passenger_front in open_states and passenger_rear
    in closed_states %}
      {% set doors_open = 'front_right_and_back_left_doors_open' %}
    {% elif driver_front in open_states and driver_rear in open_states
    and passenger_front in open_states and passenger_rear in
    closed_states %}
      {% set doors_open = 'both_front_doors_and_back_left_door_open' %}
    {% elif driver_front in open_states and driver_rear in
    closed_states and passenger_front in open_states and
    passenger_rear in open_states %}
      {% set doors_open = 'both_front_doors_and_back_right_door_open' %}
    {% elif driver_front in open_states and driver_rear in open_states
    and passenger_front in closed_states and passenger_rear in
    open_states %}
      {% set doors_open = 'both_back_doors_and_front_left_door_open' %}
    {% elif driver_front in closed_states and driver_rear in
    open_states and passenger_front in open_states and passenger_rear
    in open_states %}
      {% set doors_open = 'both_back_doors_and_front_right_door_open' %}
    {% elif driver_front in open_states and driver_rear in open_states
    and passenger_front in open_states and passenger_rear in
    open_states %}
      {% set doors_open = 'all_doors_open' %}
    {% endif %}
    '/local/images/tesla_cars/models/y/black/{{ trunks_or_ports }}/{{doors_open }}.png'
  elements:

The weird thing (to me) is:

  1. If using Developer toolsTemplate in HA UI, the template above renders to:
'/local/images/tesla_cars/models/y/black/no_trunks_or_ports_open/no_doors_open.png'
  1. If I replace image_template: ... in the above with:
image: '/local/images/tesla_cars/models/y/black/no_trunks_or_ports_open/no_doors_open.png'

(so not using card-templater) it works fine.

  1. If I try to render the template, but just explicitly give it the value:
image_template: '/local/images/tesla_cars/models/y/black/no_trunks_or_ports_open/no_doors_open.png'

this doesn’t work either.

Any ideas?