ESPHome display: Can I use "it.print" with more than one variable?

Hi,
I’m using ESPhome with ESP32 and a display to show the current song played. I would like to have both in one text line.
Is it possible to “it.print” a line with two variables (text sensors)? Like “<current_song> - <current_artist>
It works with a single variable:
it.print(78, 212, id(font21), id(my_grey), TextAlign::TOP_LEFT, id(current_song).state.c_str());

How can I add another one (current_artist)?

Thank you very much.

Best regards
Axel

what works for me:

      it.printf(0, 0, id(myfont14), "status: %s", id(displaymessage).c_str());      # ONE VARIABLE              
      it.printf(0, 20, id(myfont14), "global1i=%i %s", id(global1i), id(bootmsg));  # TWO VARIABLE 
      it.printf(0, 40, id(myfont14), "global1i=%i %s %s", id(global1i), id(bootmsg), id(bootmsg2));  # THREE 

You can add more %? and more , variables within the it.printf()
In my example, id(global1i) is a global variable,
otherwise it would be written as id(global1i).state
.c_str() was a really good find as well for displaying std::string globals

1 Like

That looks great. Thank you. I will test it tomorrow.

Your are using it.print (static text) and it seems to only allow one input string at the end.
I am using it.printf (formatted text) which is designed to do allow much more.
See both at: “Display Component — ESPHome

You COULD pre build your string for it.print but that’d probably be, uh, crazy loco.

1 Like

Worked like a charm. Printf is fine. Thank you! :smiley:

superb! is it possible two variable in same it.print with different font type?

1 Like