As many others, I would like to show some weather info on a display. Besides some textual info (temperature, humidity, etc…) I would like to use sime weather icons for the forecast.
I have studied several project codes from other people. but I only saw pretty long code snippets with a lot of "if's...then...else if".
I have an entity which gives me the forecast in text, for example “Sunny”, “Cloudy”, etc.
I have images and gave them the same id, like “Sunny”, “Cloudy”, etc.
In the display >> page code, I have for example the lines:
No, because the image name is hardcoded at compile time. If you work out a way to do it a lot of people will thank you.
I did suggest on another thread using an animated gif containing each of the images as a frame then using animation.set_frame to display the correct image. This still requires some lookup to select the image number…
Maybe there is a way by using the internal function calls of ESPhome. The only issue doing that is that the code may change, and you need a way to store the images. You can code the bmp in C++ I guess. Maybe…
And is it also not possible to put the whole “if…then” code in an external header.h file and return the needed
it.image(2, 185, id(Sunny));
In that way, if you have several weather images on your display, you only have to write the whole “if…then” code in the header file and let the header file generate the write it-line with the right image name and x- and y-coordinates…
I can give it a try!
I am not a professional programmer and only made several codes in C#, VB and a few other languages, but I am not a die hard in all those, so it is a lot of copying and trying!
Btw (and offtopic): I have build the display in a housing, but the touchscreen keeps working laggy and buggy. I now have added two optical sensors and use them as a button to go to the previous or next page and that works great!