Question about Syntax (Template to Lovelace)

Hi!

Newbie with a question:
I want to generate an URL that looks like this in the Template-Editor and is working.

/local/images/weather/{{state_attr('sensor.wetter','wetterAktuell').weather[0].id}}{{states('input_text.daynight')}}.png

Now i want to use that URL in e,g, Picture-Cards or Custom-Button-Cards.
But that won’t work. So how is the right Syntax for that?

Cheers - m
M.

Zunächst muss die Syntax in Englisch geschrieben werden

  1. Place the picture-xxx card inside a "custom:config-template-card" (CTC).
  2. Declare a variable in CTC: "varMyUrl: some_expression".
  3. Use this variable for an image’s URL - or that "some_expression" itself.

Now regarding that “some_expression”.
CTC uses JS, not jinjia.
So you need to rebuild your template according to JS syntax.
The easiest way is - create a template sensor to keep the URL as per your template, then use this sensor in CTC: "varMyUrl: states['sensor_my_url'].state".

1 Like