Formatted text with embedded value

I’m trying to print a line like:

Last feedt: 677 gm.

printf only takes two agruments, apprently, so this…

it.printf(0, 21, id(arial), "Last feed: %.0f", id(fish_food_hopper).state, "gm");
…doesn’t print the gm part and delivers a warning during compliation.

Is it possible to achieve what I want and still keep spacing correct as the value length changes or do I have to separately print the “gm”?

Additionally, what is a good safe source of fonts? My current test font can’t print a ‘w’!

Perhaps you need to ensure fish_food_hopper has a unit_of_measurement of g (or gm if you prefer non standard)

Thank you, @nickrout.

Does printf print the units by default? That’ll make things much simpler if so.

How about if you try
it.printf(0, 21, id(arial), "Last feed: %.0fgm", id(fish_food_hopper).state);

Otherwise, Arial should be a good choice to cover most characters (I’m using Ubuntu font and it also works for my needs) - did you copy it to “ESPHome” folder inside your config folder and define it like:

font:
  - file: "Arial.ttf"
    id: arial
    size: 14

Thanks, @AdmiralStipe.

I’m using an arial font and it prints Ws as an S with grave accent!

This works. I had misunderstood the order and sequence. I appreciate your help.

Yes, that’s where I had it. I’ve changed it to an arial font from my Mac and it’s fine now.

Setting the unit for the sensor is having no impact on printf. Why would that be?

sensor:
  - platform: hx711
    name: "Fish food hopper"
    id: fish_food_hopper
    dout_pin: 27
    clk_pin: 26
    filters:
      - calibrate_linear:   
        - 406000 -> 0    
        - 3405000 -> 5000
      - sliding_window_moving_average:    
          window_size: 10    
          send_every: 3
    update_interval: 1.0s
    unit_of_measurement: gm