Variable image name

I have a 4,2 inch display, connected to an esp32 board.

With the line:

lambda: |-
  it.image(10, 45, id(Rainy));

I can place a weather icon on the display.

But in this way I have to make a lot of ifs>>then for every weather type there is.

I have also a text sensor, which get the weathertype of that moment and the values are Strings like ‘Rainy’, ‘Sunny’ etc.
I have a folder with all weather icons, with the same name as the weather types, like ‘Rainy.png’, ‘Sunny.png’, etc

Is it possible to make one lambda line with some kind of placeholder/variable?

I tried things like:

lambda: |-
  it.image(10, 45, id(id(weather_icon_now).state));

where

 id(weather_icon_now).state

is the text variable which get the current weathertype from the weather integration.

I am looking for a way to show a weather icon, without the whole if/than bunch of code, but did not find an example…

Have a look at animation in the display component. You can create an “animated” gif consisting of the images you need, then use set_frame() to choose your image to display.

Apose animation maker is one way to load your images into the gif:

1 Like

Also - no. Unfortunately that seems to be fixed at compile time.