if (id(sternzeichen).state == "taurus") {
it.image(37, 2, id(taurus));
That all works… but because there are 12 different zodiacsigns, i have to make 12 checks for the sign… thats a lot of code and i am wondering, if there is a shorter way…?
So the state of the sensor is “taurus”, the id of the image is “taurus” and the name of the image is “taurus.png”…
(inside the zodiacsign.yaml is just the name of the zodiacsign, now “taurus”)
i can use $zodiacsign in the path…
it.image(37, 2, id($zodiacsign));
The problem is, i have found no way to read in the zodiacsign.yaml, when the zodiac changes…
i have to flash the esp32 to re-read the zodiacsign.yaml with !include…
I did have a quick search about this, and as I understand it now the ESPHome Display component currently only supports static images that are downloaded on the device during flashing.
Please correct me when this is incorrect.
However, it looks like there is an dynamic image support in the making.
See this Pull request: Add runtime online image support #4710
So may be in the near future there will be a dynamic image option for ESPHome?
I know this is a bit of a necro but I found this post while attempting to solve the same problem. I finally got it working, the solution is pass the image pointer to the function - the function needs to be defined to accept esphome::image::Image*. Below is a simplified version of my code.
I haven’t touched C++ since freshmen college so apologies if any of my terminology is off.
image:
- file: mdi:microphone-off
id: img_microphone_off
resize: 60x60
- file: mdi:microphone
id: img_microphone_on
resize: 60x60
- file: mdi:phone-classic
id: img_meeting_on
resize: 60x60
# 1.14 inch, 135*240 Colorful TFT LCD, ST7789v2
display:
- platform: st7789v
model: TTGO TDisplay 135x240
cs_pin: GPIO5
dc_pin: GPIO14
reset_pin: GPIO12
lambda: |-
int current_offset = 20;
int image_offset = 75; // height + buffer
float horizontal_offset = 37.5;
// Retrieve state of devices
bool b_audio_on = id(audio_on).state;
bool b_video_on = id(camera_on).state;
bool b_meeting_on = id(in_meeting).state;
// Helper function to draw an image at the next position
auto drawImage = [&](int ¤t_offset, esphome::image::Image* image) {
it.image(horizontal_offset, current_offset, image);
current_offset += image_offset; // Increase offset after drawing
};
drawImage(current_offset, id(img_meeting_on));
drawImage(current_offset, b_audio_on ? id(img_microphone_on) : id(img_microphone_off));