ESPhome sensor to oled

Hello, I want to send text information from my Home Assistant entity to my ESPHome-OLED. I’ve tried for many hours to test %s, %f, .c_str(), without success. In the ESPHome log, I receive numbers when the state of sensor.restafal is a number. But when I change the state manually in Home Assistant to any text, then ESPHome receives ‘nan’. So, my first problem is: how to receive strings and numbers? The second problem is to show it on the LCD. Sometimes the OLED shows ‘0.0000’, other times it shows white squares.

thx for the help

log:

[21:53:38][W][homeassistant.sensor:015]: 'sensor.restafval': Can't convert 'restafval' to number!
[21:53:38][D][sensor:094]: 'restafval': Sending state nan  with 1 decimals of accuracy

Homeassitant entity : “textstring in most cases” eg : “Restafval”
sensor.restafval

ESPHOME code :

display:
  - platform: ssd1306_i2c
    i2c_id: bus_a
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-      
      it.printf(64, 0, id(font1), TextAlign::TOP_CENTER, "Mitt Smarta Hus");
      it.strftime(0, 60, id(font1), TextAlign::BASELINE_LEFT, "%H:%M", id(esptime).now());      
      it.printf(127, 60, id(font1), TextAlign::BASELINE_RIGHT ,"%s", id(ownip).state.c_str());
     
      it.printf(127, 23, id(font1), TextAlign::TOP_RIGHT , "%f", id(restafval));


    

sensor:
  - platform: homeassistant
    id: restafval
    entity_id: sensor.restafval
    internal: true

 

Your need the text sensor version

hello !
thx for the tip , unfortunaly it does not work

i changed it to :
the result is on the oled : “0.000000”

it.printf(127, 23, id(font1), TextAlign::TOP_RIGHT , "%f", to_string(id(restafval).state.c_str()));

and

text_sensor:
  - platform: homeassistant
    id: restafval
    entity_id: sensor.restafval
    internal: true

solved :

      it.printf(127, 23, id(font1), TextAlign::TOP_RIGHT , "%s",id(restafval).state.c_str());