Can't get any "homeassistant" sensors/binary_sensors/time working on ESP8266

Hi, I’m struggling to get any data from home assistant to appear on a display I’ve got on an ESP8266 unit. I’ve gotten the display working properly and can display static text, but any attempt to pull HA data fails. Here’s a couple examples:

binary_sensor:
  - platform: homeassistant
    name: "Input Boolean From Home Assistant"
    id: mike_home
    entity_id: input_boolean.mike_home

sensor:
  - platform: homeassistant
    id: attic_temp
    entity_id: sensor.attic_sensor_air_temperature
    internal: true

Trying to reference these fails with errors. Here’s how I’m trying to reference them:

      it.printf(0, 70, id(font_time), "Mike home:");
      it.printf(90, 70, id(font_time), id(mike_home))

      it.printf(0, 23, id(font_time), "Attic temp:");
      if (id(attic_temp).has_state()) {
        it.printf(127, 23, id(font_time), TextAlign::TOP_RIGHT , "%.1f°", id(attic_temp).state);

which generates errors like:

/config/esphome/esphome-web-14209c.yaml:86:46: error: no matching function for call to 'esphome::display::Display::printf(int, int, esphome::font::Font*&, esphome::homeassistant::HomeassistantBinarySensor*&)'

Is it possible this board type doesn’t support the HA platform?

esp8266:
  #board: nodemcuv2
  board: esp12e

Oh, and for time, I’m trying:

time:
  - platform: homeassistant
    id: esptime

and

      it.strftime(0, 60, id(font_time), TextAlign::BASELINE_LEFT, "%H:%M", id(esptime).now());

Finally, one last maybe unrelated thing. When I push this code to the ESP, it displays for a few seconds, then the ESP blinks and reboots, and it gets stuck in this loop for a few times.

Eventually it blanks the display and has a solid blue LED light on the ESP like it’s given up. Not sure what’s causing that as I’ve tried a larger power supply but it doesn’t seem to make a difference. Not sure how to debug the code but I can strip the code down to just a “Hello World” and I think that stays in place without any reboots.

Firstly, printf requires a format, thus the f in printf. Just use 'it.print. Secondly, they are sensors, all sensors require .state, for example:

      it.print(90, 70, id(font_time), id(mike_home).state)

Thanks, I feel like I’m getting closer. Here’s my new attempt and the error it generates. I’ll keep playing with it.

sensor:
  - platform: homeassistant
    id: attic_temp
    entity_id: sensor.attic_sensor_air_temperature
    internal: true

In the lambda:

      it.print(0, 100, id(font_date), "Attic temp");
      it.print(64, 100, id(font_date), id(attic_temp).state);

Error:

src/esphome/components/display/display.h:244:8: note:   no known conversion for argument 4 from 'bool' to 'const char*'
/config/esphome/atom-s3-oled-01.yaml:111:53: error: no matching function for call to 'esphome::display::Display::print(int, int, esphome::font::Font*&, float&)'
       it.print(64, 100, id(font_date), id(attic_temp).state);
                                                     ^

attic_temp is probably a float. You have 2 choices - convert to string in the print statement, or in this case use printf and provide a format:

      it.print(0, 100, id(font_date), "Attic temp");
      it.printf(64, 100, id(font_date), "%.1f", id(attic_temp).state);

or

      it.printf(0, 100, id(font_date), "Attic temp   %.1f", id(attic_temp).state);

Ok - just saw the bool error as well - that will probably require a template sensor… :smiley: - or maybe just a logic check. You also had the temp one right in your first attempt.

    if (id(mike_home).state) {
      it.print(90, 70, id(font_time), "Home")
    } else {
      it.print(90, 70, id(font_time), "Away")
    }

OK, I got the code to compile with your suggestions but now it shows “Nan” for the attic temp. Here’s my snippet:
it.printf(0, 100, id(font_date), "Attic temp %.1f", id(attic_temp).state);

And for the boolean, you are correct, it’s not able to display anything because of no known conversion for argument 4 from 'bool' to 'const char*'

I think a template would help; something like if false define something to “Away” and if true “Home”.

Yeah your first attempt for the attic temp was probably fine. I really shouldn’t try to help before I have had breakfast…

1 Like

Yeah so far I keep getting errors like no known conversion for argument 4 from 'float' to 'const char*' even for the “state” of a light. If I try using the formatting print (i.e. with the “%1.0f” argument) I get nan for the display output.

Still chugging through…

Good thing is the boolean one works! With the if statement in place it updates properly on the display when the HA helper is changed.

Ok - try bringing across the temp as a text sensor rather than a sensor. For some reason I have done that in one of my display projects. Then just use print, or printf with %s.

OK, making some progress, I think. The text_sensor idea helped, although not sure how much. I’m including the snippets to get the data and output it, as well as a screenshot of the display wit the weirdness that shows up now.

text_sensor:
  - platform: homeassistant
    id: attic_temp
    entity_id: sensor.attic_sensor_air_temperature
  - platform: homeassistant
    id: tv_light_brt
    entity_id: light.hue_tv_play_left
    attribute: brightness

And

    lambda: |-
      it.strftime(64, 10, id(font_time), id(my_gray), TextAlign::TOP_CENTER, "%l:%M %P", id(ha_time).now());
      it.print(10, 50, id(font_date), id(my_gray), "Mike:");
      if (id(mike_home).state) {
        it.print(70, 50, id(font_date), "Home");
      } else {
        it.print(70, 50, id(font_date), "Away");
      }

      it.print(10, 75, id(font_date), "TV LED");
      it.printf(70, 75, id(font_date), "%s", id(tv_light_brt));

      it.print(10, 100, id(font_date), "Attic");
      it.printf(70, 100, id(font_date), "%s", id(attic_temp).state);

Here’s the display:

When I look at the current status of those items in HA:

For the light “brightness: 102”
And the temp: “Air temperature 75.2”

Ok - your ESPHome logs should show what they are coming across as - maybe post those (or the relevant bits).

Man this is frustrating. I’m not a SWE but have coded in python and other languages, just not C.

Calling line:

      it.print(70, 75, id(font_date), id(my_blue), TextAlign::TOP_CENTER, id(tv_light).state);

Error:

/config/esphome/atom-s3-oled-01.yaml: In lambda function:
/config/esphome/atom-s3-oled-01.yaml:122:82: error: no matching function for call to 'esphome::display::Display::print(int, int, esphome::font::Font*&, esphome::Color&, esphome::display::TextAlign, std::__cxx11::string&)'
       it.print(70, 75, id(font_date), id(my_blue), TextAlign::TOP_CENTER, id(tv_light).state);
                                                                                  ^

I’m struggling with errors about “4 args provided, 6 needed, etc.” so I added the color and alignment to make those errors go away.

Still trying to figure out how to get those logs you talked about.

This one line generates all these errors. When I remove it the errors go away.

it.print(70, 100, id(font_date), id(my_blue), TextAlign::TOP_CENTER, id(attic_temp).state);

log:

/config/esphome/atom-s3-oled-01.yaml: In lambda function:
/config/esphome/atom-s3-oled-01.yaml:121:85: error: no matching function for call to 'esphome::display::Display::print(int, int, esphome::font::Font*&, esphome::Color&, esphome::display::TextAlign, std::__cxx11::string&)'
       it.print(70, 100, id(font_date), id(my_blue), TextAlign::TOP_CENTER, id(attic_temp).state);
                                                                                     ^
In file included from src/esphome.h:18,
                 from src/main.cpp:3:
src/esphome/components/display/display.h:215:8: note: candidate: 'void esphome::display::Display::print(int, int, esphome::display::BaseFont*, esphome::Color, esphome::display::TextAlign, const char*)'
   void print(int x, int y, BaseFont *font, Color color, TextAlign align, const char *text);
        ^~~~~
src/esphome/components/display/display.h:215:8: note:   no known conversion for argument 6 from 'std::__cxx11::string' {aka 'std::__cxx11::basic_string<char>'} to 'const char*'
src/esphome/components/display/display.h:225:8: note: candidate: 'void esphome::display::Display::print(int, int, esphome::display::BaseFont*, esphome::Color, const char*)'
   void print(int x, int y, BaseFont *font, Color color, const char *text);
        ^~~~~
src/esphome/components/display/display.h:225:8: note:   candidate expects 5 arguments, 6 provided
src/esphome/components/display/display.h:235:8: note: candidate: 'void esphome::display::Display::print(int, int, esphome::display::BaseFont*, esphome::display::TextAlign, const char*)'
   void print(int x, int y, BaseFont *font, TextAlign align, const char *text);
        ^~~~~
src/esphome/components/display/display.h:235:8: note:   candidate expects 5 arguments, 6 provided
src/esphome/components/display/display.h:244:8: note: candidate: 'void esphome::display::Display::print(int, int, esphome::display::BaseFont*, const char*)'
   void print(int x, int y, BaseFont *font, const char *text);
        ^~~~~
src/esphome/components/display/display.h:244:8: note:   candidate expects 4 arguments, 6 provided
*** [.pioenvs/atoms3-01/src/main.cpp.o] Error 1
========================= [FAILED] Took 21.99 seconds =========================

I’m making it worse and am going to give up for a while.

Tried this from another post:

      it.print(10, 100, id(font_date), "Attic");
      std::string temp = esphome::to_string(attic_temp);
      it.print(70, 100, id(font_date), temp);

Errors:

Compiling .pioenvs/atoms3-01/src/main.cpp.o
/config/esphome/atom-s3-oled-01.yaml: In lambda function:
/config/esphome/atom-s3-oled-01.yaml:124:55: error: no matching function for call to 'to_string(esphome::homeassistant::HomeassistantSensor*&)'
       std::string temp = esphome::to_string(attic_temp);
                                                       ^
In file included from /data/cache/platformio/packages/toolchain-xtensa-esp32s3/xtensa-esp32s3-elf/include/c++/8.4.0/string:52,
                 from /data/cache/platformio/packages/toolchain-xtensa-esp32s3/xtensa-esp32s3-elf/include/c++/8.4.0/stdexcept:39,
                 from /data/cache/platformio/packages/toolchain-xtensa-esp32s3/xtensa-esp32s3-elf/include/c++/8.4.0/array:39,
                 from src/esphome/components/api/api_noise_context.h:3,
                 from src/esphome/components/api/api_frame_helper.h:13,
                 from src/esphome/components/api/api_connection.h:3,
                 from src/esphome.h:3,
                 from src/main.cpp:3:
/data/cache/platformio/packages/toolchain-xtensa-esp32s3/xtensa-esp32s3-elf/include/c++/8.4.0/bits/basic_string.h:6481:3: note: candidate: 'std::__cxx11::string std::__cxx11::to_string(long long unsigned int)' <near match>
   to_string(unsigned long long __val)
   ^~~~~~~~~
/data/cache/platformio/packages/toolchain-xtensa-esp32s3/xtensa-esp32s3-elf/include/c++/8.4.0/bits/basic_string.h:6481:3: note:   conversion of argument 1 would be ill-formed:
/config/esphome/atom-s3-oled-01.yaml:124:45: error: invalid conversion from 'esphome::homeassistant::HomeassistantSensor*' to 'long long unsigned int' [-fpermissive]
       std::string temp = esphome::to_string(attic_temp);

Try:

it.print(70, 100, id(font_date), id(my_blue), TextAlign::TOP_CENTER, id(attic_temp).state.c_str());

And no I am not 100% sure why - I coded this a long time ago. Maybe that’s why there are so few examples of printing sensors in the ESPHome Display pages…

it.print(70, 100, id(font_date), id(my_blue), TextAlign::TOP_CENTER, id(attic_temp).state.c_str());

gives me:

/config/esphome/atom-s3-oled-01.yaml: In lambda function:
/config/esphome/atom-s3-oled-01.yaml:124:86: error: request for member 'c_str' in 'attic_temp->esphome::homeassistant::HomeassistantSensor::<anonymous>.esphome::sensor::Sensor::state', which is of non-class type 'float'
       it.print(70, 100, id(font_date), id(my_blue), TextAlign::TOP_CENTER, id(attic_temp).state.c_str());

I’ll keep poking at it.

None of these worked:

it.printf(70, 100, id(font_date), id(my_blue), TextAlign::TOP_CENTER, "%s", id(attic_temp).state.c_str());

it.printf(70, 100, id(font_date), id(my_blue), TextAlign::TOP_CENTER, "%s", String(attic_temp).state.c_str());

Trying some other ways. Wish there was better documentation on how to do this…

it.printf(70, 100, "Ot:%4.1f", id(font_date), id(attic_temp).state);

Gives this error

/config/esphome/atom-s3-oled-01.yaml:125:66: error: no matching function for call to 'esphome::display::Display::printf(int, int, const char [9], esphome::font::Font*&, float&)'
       it.printf(70, 100, "Ot:%4.1f", id(font_date), id(attic_temp).state);
                                                                  ^

UPDATE, had them in the wrong order. This compiles:
it.printf(70, 100, id(font_date), "Ot:%4.1f", id(attic_temp).state);

But still gives me NAN on the display. Looking that up it means “not a number”

Silly question - but I have to ask it because I’ve fallen for this in the past.

Have you added the specific ESP8266 device via integrations in home assistant?