I think this Lovelace card-templater card (Jinja2 card templating in Lovelace!) could be valid for what you want