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

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?

It’s one of my ESPHome devices if that’s what you mean…

So when I try the temp sensor as a sensor:

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

With this print:
it.printf(70, 100, id(font_date), "%2.1f", id(attic_temp).state);

I get nan on the display like it’s not a number. But then a few seconds later it shows the actual temperature number! So I think I’m finally getting somewhere with your help.

It’s very much appreciated!

Yes, that is what I meant. Couldn’t think of the specific terminology off the top of my head.

Glad you’ve made some progress and got some values showing.

OMG found the motherload of posts on this thread:

I know all my answers are in there somewhere! I’m still trying to read the state of a lamp, and in addition I’d like to read an attribute like brightness

1 Like

I’m still fiddling around with different displays and ESP devices and have come across something else I hope someone has an answer for.

None of the “home assistant” links work, time, sensor, text_sensor, etc.

The code is copied straight from another working device, so I think it has something to do with the board type / platform / etc.

esp8266:
  board: nodemcuv2
#  board: esp12e
#  framework:
#   type: arduino

I have to use nodemcuv2 because the other one throws an error that it doesn’t know what pins D1 and D2 are, as defined here:

i2c:
  sda: D1
  scl: D2

My board is described as HiLetgo 3pcs ESP8266 NodeMCU CP2102 ESP-12E which to me tells me I should use a board selection with 12E in it, and the only two are shown above.

Also, I don’t know if it has something to do with the framework section, but my successful attempts above with the Atom S3 unit has this in it’s config:

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino

But the two boards I am trying to use say that the framework is an unknown setting.

Anyway, the display is working but the time is wrong and my temp sensor says “nan” like it doesn’t have any data from HA.

Also my text_sensor which works on the other board is not pulling data from the HA sensor.

Hmm – any chance it has something to do with the API encryption key?

I don’t know how that part works so I’ll research that. Maybe something has to be set up in HA to allow communications of sensors, etc.

OMG figured it out – it was the key. I changed it to a regular plaintext password and then the device ended up showing up under integrations as a new device, so I re-added it back in and the device can now talk to HA and gather sensor data, which is working now.

1 Like