Passing input_text params from HA to ESPHome printf lines

I have added a ILI9341 TFT display to one of my ESPHome devices.
It works fine when setting x/y positioning, fonts, colors etc. directly in the lambda printf line.

Now I would like to get the printf parameters from HA to control :
x & y position
font
font size
font color
text string

I am using the HA input_text helper, and that works fine for getting the text_string (input_text.displaytext)

but I don’t know how to get the others ;
x_pos
y_pos
font name
font size
and font color.

Googling & trying to find a solution in HA Community didn’t help…

Regarding fonts/font sizes, & colors, its ok if the input_text content just “points” to my predefined fonts/font sizes & colors in the ESPHome file

Is there an easy way to do this ??

The first line in my lambda code works fine , but I would like the second lambda line to execute by getting all parameters from the input_text values…


> Blockquote

text_sensor:
  - platform: homeassistant
    name: displayxpos
    entity_id: input_text.displayxpos
    id: displayxpos
  - platform: homeassistant
    name: displayypos
    entity_id: input_text.displayypos
    id: displayypos
  - platform: homeassistant
    name: displaytext
    entity_id: input_text.displaytext
    id: displaytext
  - platform: homeassistant
    name: displayfont
    entity_id: input_text.displayfont
    id: displayfont
  - platform: homeassistant
    name: displayfontcolor
    entity_id: input_text.displayfontcolor
    id: displayfontcolor

color:
  - id: yellow
    red: 100%
    green: 100%
    blue: 0%

  - id: red
    red: 100%
    green: 0%
    blue: 0%

  - id: navy
    red: 0%
    green: 0%
    blue: 50%

  - id: black
    red: 0%
    green: 0%
    blue: 0%

  - id: white
    red: 100%
    green: 100%
    blue: 100%

  - id: blue
    blue: 100%
  
  - id: green
    green: 100%

font:
  - file: fonts/Teko-SemiBold.ttf
    id: text_44
    size: 44

  - file: fonts/Teko-SemiBold.ttf
    id: text_96
    size: 96

spi:
  clk_pin: GPIO7
  mosi_pin: GPIO11
  miso_pin: GPIO9


display:
  - platform: ili9xxx
    model: TFT 2.4
    cs_pin: 5
    dc_pin: 12
    reset_pin: 33  ### Not used ###

    lambda: |-
      it.printf(120, 20, id(text_44), id(white), TextAlign::TOP_CENTER, "%s", to_string( id(displaytext).state).c_str());   
      it.printf(id(displayxpos), id(displayypos), id(displayfont) id(displaycolor),TextAlign::TOP_CENTER, "%s", (id(displaytext).state.c_str());

I am not sure that the positions are templatable. I can’t see any examples of it.printf which has a templated <x> and <y> in this page Display Component — ESPHome

If you have an example of it being done, please post a link to it :slight_smile:

No, sorry I dont have that,
I have tried a lot of possible solutions, with no luck, so this is just a “wishlist”…
If it would be possible to template only some of the parameters, the priority would be :
#1 Textcolor
#2 Font
(getting the textstring from input_text works fine)…

So if it would be possible to template color & font, that would be great.

In that case (even if its not possible to template x&y positions, a quick & dirty solution could maybe be, just add all the lines that should appear on the display as printf-lines (with fixed x&y positions), and then set the textcolor for the lines that should be hidden, to the same color as the background to hide them.

And when they should appear just change the textcolor again for these lines, and “hide” the others"…
Not very elegant, but a possible workaround ??

(Looking forward for replies to a better solution…)