Home Assistant sensor in esphome

I have two power supplies at my workbench (12V and 24V). The input power to those is handled by sonoff s26 wall outlet switches (running esphome). I also have a small touchscreen within my arms reach and I use that to turn the PSUs on and off. I want to be able to pull the state of those esphome outlet switches to show in the display (haven’t decided if it’ll be just a colour or what, that’s not important for this, really). I keep getting the following warning and I don’t know what I am doing wrong here:

[11:27:29][D][sensor:094]: '24V PSU': Sending state nan  with 1 decimals of accuracy

I have all the devices added to home assistant and I can see the states and control it from there just fine. I did try the c_str() but then I get the following error:

/config/display-study.yaml: In lambda function:
/config/display-study.yaml:200:83: error: request for member 'c_str' in 'psu24->esphome::homeassistant::HomeassistantSensor::<anonymous>.esphome::sensor::Sensor::state', which is of non-class type 'float'
         it.printf(180,83, id(roboto), id(my_green), TextAlign::CENTER, "%s", id(psu24).state.c_str());

display yaml config:

sensor:
  - platform: homeassistant
    name: "12V PSU"
    entity_id: binary_sensor.smart_plug_12v_psu_sonoff_s26_12v_psu_state
    id: psu12
    internal: true
  - platform: homeassistant
    name: "24V PSU"
    entity_id: binary_sensor.smart_plug_24v_psu_sonoff_s26_24v_psu_state
    id: psu24
    internal: true

display:
  - platform: ili9xxx
    id: tft_display
    model: TFT 2.4
    ...
    lambda: |-
        it.printf(60,83, id(roboto), id(my_green), TextAlign::CENTER, "%f",id(psu12).state);
        it.printf(180,83, id(roboto), id(my_green), TextAlign::CENTER, "%f", id(psu24).state);

sonoff outlet switch yaml config:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Sonoff S26_12v_psu Button"
    on_press:
      - switch.toggle: relay
  - platform: switch
    name: "Sonoff s26_12v_psu state"
    source_id: relay

switch:
  - platform: gpio
    name: "Sonoff S26_12v_psu Relay"
    pin: GPIO12
    restore_mode: "RESTORE_DEFAULT_OFF"
    id: "relay"

Thank you in advance for your help!

That “value” is sometimes sent while HA is starting up or if the sensor is unavailable. Since “NaN” isn’t valid for a binary sensor, ESPHome is complaining when it gets sent. If it isn’t affecting things, I’d be tempted to just ignore the warning.

You use sensor component for binary sensor? Try:

binary_sensor:
  - platform: homeassistant

Yes! That fixed it! Thank you!