gadgetchnnel / lovelace-card-templater

Custom Lovelace card which allows Jinja2 templates to be applied to other cards
120 stars 6 forks source link

[Image] under [picture elements] does not work #60

Open zheng1112 opened 2 years ago

zheng1112 commented 2 years ago

type: custom:card-templater card: type: picture-elements

image: /local/ui/one1.jpg # OK

image_template: '{{ states("input_text.text12") }}' # error

elements:

Aephir commented 1 year ago

I'm not quite sure whether my issue is the same, but in case it is:

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: '/local/images/tesla_cars/models/y/black/no_trunks_or_ports_open/no_doors_open.png' # <-- Works
  image_template: '/local/images/tesla_cars/models/y/black/no_trunks_or_ports_open/no_doors_open.png' # <-- Does not work
elements:
  etc...
In case it helps, here's the full config with "image_template". The template renders correctly in HA "Template" in developer tools ``` 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: - type: state-label entity: sensor.model_y_range style: top: 7.2% left: 22% font-weight: bold font-size: 100% color: '#8a8a8d' font-family: gotham - type: state-icon show_name: true title: Refresh Data entity: button.model_y_force_data_update icon: mdi:refresh style: top: 9.5% left: 90% color: '#039be5' width: 40px height: 50px tap_action: action: call-service service: button.press service_data: {} target: entity_id: button.model_y_force_data_update ```