Wrong number display on max7219digit (SOLVED)

I have a problem displaying a integer sensor value from home assistant to a max7219 display.
This is the definition of my sensor

  - platform: homeassistant
    name: "Consumi da home Assistant"
    entity_id: sensor.power_energy_power
    unit_of_measurement: "W"
    device_class: "energy"
    state_class: "measurement"

and this is the lambda definition

it.printf(0, 0, id(digit_font), TextAlign::TOP_LEFT, "Consumption: %i W", id("Consumi da home Assistant"));

In the logs I see
[13:04:28][D][sensor:117]: ‘Consumi da home Assistant’: Sending state 523.00000 W with 1 decimals of accuracy

But the string printed on display is “Consumption: 67 W”

How is possible ?

Just replace “Consumption: %i W” with “Consumption: %.1f W”. You want a float, not an integer.

With your suggestion I have this warning

Compiling /data/dot_matrix_display/.pioenvs/dot_matrix_display/src/main.cpp.o
/config/esphome/dot_matrix_display.yaml: In lambda function:
/config/esphome/dot_matrix_display.yaml:55:110: warning: format '%f' expects argument of type 'double', but argument 7 has type 'int' [-Wformat=]
       it.printf(0, 0, id(digit_font), TextAlign::TOP_LEFT, "Consumption: %.1f W", id("Consumi da home Assistant"));

The text show is always “Consumption: 2.0” despite of the sensor value that fluctuates from 400 to 410 w

Problem SOLVED
I changed sensor definition adding id tag

  - platform: homeassistant
    name: "Consumi da home Assistant"
    id: "power_energy"
    entity_id: sensor.power_energy_power
    unit_of_measurement: "W"
    device_class: "energy"
    state_class: "measurement"

And using this ID in the lamba function:

it.printf(0, 0, id(digit_font), TextAlign::TOP_LEFT, "Consumption: %.1f W", id(power_energy).state);