Getting NAN values in my e-ink screen in ESPHome

Hello. I’m trying to display some temperature values from HA into a waveshare_epaper display.
however, I’m getting NAN all the time.

I can see that values are being received on the ESP sensor:

[13:51:45][D][homeassistant.binary_sensor:026]: 'input_boolean.e_ink_prevent_deep_sleep': Got state OFF
[13:51:45][D][binary_sensor:034]: 'E-ink esphome Prevent Deep Sleep': Sending initial state OFF
[13:51:45][D][homeassistant.sensor:024]: 'sensor.mijia_temperature': Got state 23.80
[13:51:45][D][sensor:125]: 'office_temp': Sending state 23.80000  with 1 decimals of accuracy
[13:51:45][D][homeassistant.sensor:024]: 'sensor.mj_salon_temp': Got state 23.40
[13:51:45][D][sensor:125]: 'salon_temp': Sending state 23.40000  with 1 decimals of accuracy

Just out of curiosity, I tried to put the printf statement behind an if flag like this:

         if (id(office_temp).has_state())
          it.printf(0, 25, id(font1), TextAlign::TOP_LEFT, "%.1fC", id(office_temp).state);
         else 
          ESP_LOGD("screen", "No data from HA for office_temp");

and now I get a value on the screen.
My guess is that the display is trying to update itself when the values are not available yet, and then it overrides whatever value it has with the not available one yet. But why all the times it is not available? How is that possible? It is an e-ink display, setup to do updates not often, why it always tries to refresh when values are not available? If it were updating every second, then I could understand that it may be always with the latest invalid value.
In any case, is it advisable to always run this kind of checks?


  - platform: homeassistant
    id: CL
    entity_id: sensor.hot_water
    internal: true

  - platform: homeassistant
    id: ST
    entity_id: sensor.mmc_3e_temp
    internal: true
    lambda: |-
      // 296x126

      it.strftime(155, 5, id(clk), TextAlign::TOP_CENTER, "%H:%M", id(esptime).now());
      it.printf(155, 35, id(tmp), TextAlign::TOP_CENTER, "%2.0f%%", id(STh).state );
      it.printf(155, 65, id(tmp), TextAlign::TOP_CENTER, "%2.0f%%", id(HGh).state );

      it.printf(5, 5, id(tmp), "CL %4.1f°", id(CL).state );
      it.printf(5, 35, id(tmp), "ST %4.1f°", id(ST).state );
      it.printf(5, 65, id(tmp), "HG %4.1f°", id(HG).state );

      it.printf(295, 5, id(eb), TextAlign::TOP_RIGHT, "%4.0f W", id(EBL1p).state );
      it.printf(295, 35, id(eb), TextAlign::TOP_RIGHT, "%4.0f W", id(EBL2p).state );
      it.printf(295, 65, id(eb), TextAlign::TOP_RIGHT, "%4.0f W", id(EBL3p).state );

      it.filled_rectangle(0, 93, 296, 128);
      it.printf(10, 98, id(mk), COLOR_OFF, "TMT %1.0f", id(MILK_TMT).state );
      it.printf(286, 98, id(mk), COLOR_OFF, TextAlign::TOP_RIGHT, "DC %2.0f", id(MILK_DC).state );

font:

  - file: 'fonts/lucida.ttf'
    id: eb
    size: 22

  - file: 'fonts/lucida.ttf'
    id: clk
    size: 22

  - file: 'fonts/lucida.ttf'
    id: tmp
    size: 22

  - file: 'fonts/lucida.ttf'
    id: mk
    size: 30

NaN values is wifi connection issues

I’m also using deep sleep, so not sure if that can make a difference.

By the way, I see thwt any sensor I declare to read from homeassistant appears duplicated in home assistant once the esphome device is configured. Is internal: true to prevent that?

Yes.

If you use deepsleep, you need a low update interval for homeassistant sensors.

Or control all with lambdas

https://www.reddit.com/r/Esphome/comments/m2su9i/run_script_after_wakeup_from_deep_sleep/

What do you mean by that? Is something I can configure in the sensor itself?

  - platform: homeassistant
    id: CL
    entity_id: sensor.hot_water
    internal: true
    update_interval: 5

Keep esp more time awake.

1 Like

Do you mean that using that update_interval will keep the ESP more time awake or that I need to keep it more time awake myself ?

I think that is the more optimal thing to do, but I am not sure how.
Currently, on boot I disable the deep sleep, and I have a couple of scripts that run on events.
I think the ideal scenario will be to not call the update method of the screen until I have all the values from HA, but I am not sure which one what will be the best way of doing this.

This is what comes to my mind:

  • Create a script that checks that everything has a value, and if there is call the component update of the screen
  • In the on_value method of the the sensors coming from HA call the script
  • As the last thing the screen does after updating, goes to sleep.

Will that make sense?