How to get temp and hum on an oled Home Assistant?

OT: I’m not sure if you’re being serious, or completely unaware of how helpful others have been to you. koying posted 19 replies within 3 days to your 38 40 messages to help you. Posting a complaint after 4 minutes of not receiving an answer is not going to encourage anyone to help you.

back to the issue:
Post your full yaml after the last changes, so we can check on it.

1 Like

wtf you talking about? xD
I’m just posting the situation… diddn’t critique anyone, just told you i have 20 peple trying to help me…

The complete opposite…
completely AWARE of how helpful others have, I even told you i have more than 20 people trying…

annyway… I think im on to something now… I completely diddn’t think about chatgpt… Asked gpt:hi i want to get an dht22 sensor reading humidity and temperature on an oled display: this is the code i have in the yaml: esphome:

here is the code… `esphome:
name: temp_and_hum_sensor
platform: ESP32
board: seeed_xiao_esp32c3

wifi:
ssid: “YOUR_WIFI_SSID”
password: “YOUR_WIFI_PASSWORD”

logger:

api:

ota:

i2c:
sda: GPIO6
scl: GPIO7
scan: False

font:

  • file: “Roboto-Regular.ttf”
    id: font1
    size: 12

display:

  • platform: ssd1306_i2c
    model: “SSD1306 128x64”
    address: 0x3C
    id: oled_display
    rotation: 0

sensor:

  • platform: dht
    model: DHT22
    pin: 2
    temperature:
    name: “Temperature”
    id: temperature_sensor
    humidity:
    name: “Humidity”
    id: humidity_sensor
    update_interval: 60s

text_sensor:

  • platform: template
    name: “Temperature Display”
    id: temperature_display
    icon: “mdi:thermometer”
    lambda: |-
    return {std::sprintf(“%.1f°C”, id(temperature_sensor).state)};
  • platform: template
    name: “Humidity Display”
    id: humidity_display
    icon: “mdi:water-percent”
    lambda: |-
    return {std::sprintf(“%.1f%%”, id(humidity_sensor).state)};

Update OLED display with temperature and humidity readings

interval:

  • interval: 10s
    then:
    • text_layout.set_text:
      id: text_temperature
      text: !lambda |-
      return id(temperature_display).state.c_str();
    • text_layout.set_text:
      id: text_humidity
      text: !lambda |-
      return id(humidity_display).state.c_str();
    • display.page.show: 1
      `

Now im compiling, so in 1hour and 20 min, I will know if it works :slight_smile: i will post the results :smiley:

Yeah. You’re saved now :roll_eyes:

2 Likes

I wouldn’t say that, chatgpt is not perfect, does alot of mistakes, but if you use it correctly it can be a gift from above ::stuck_out_tongue:

But i have not got it yet…
(from all i have learned from haos and esp last weeks, I’m 90 percent sure something wont work this time either, waiting for an error, but who knows…

and i was right xD

/config/esphome/hemmis.yaml: In lambda function:
/config/esphome/hemmis.yaml:67:64: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
return {std::sprintf(“%.1f°C”, id(temperature_sensor).state)};
^
/config/esphome/hemmis.yaml:67:59: error: cannot convert ‘float’ to ‘const char*’
return {std::sprintf(“%.1f°C”, id(temperature_sensor).state)};
^
In file included from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/cstdio:42,
from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/ext/string_conversions.h:43,
from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/bits/basic_string.h:6400,
from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/string:52,
from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/stdexcept:39,
from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-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-riscv32-esp/riscv32-esp-elf/sys-include/stdio.h:244:32: note: initializing argument 2 of ‘int sprintf(char*, const char*, …)’
int sprintf (char *__restrict, const char *__restrict, …)
^
~
/config/esphome/hemmis.yaml:67:65: error: could not convert ‘{}’ from ‘’ to ‘esphome::optional<std::__cxx11::basic_string >’
return {std::sprintf(“%.1f°C”, id(temperature_sensor).state)};
^
/config/esphome/hemmis.yaml: In lambda function:
/config/esphome/hemmis.yaml:73:60: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
return {std::sprintf(“%.1f%%”, id(humidity_sensor).state)};
^
/config/esphome/hemmis.yaml:73:55: error: cannot convert ‘float’ to ‘const char*’
return {std::sprintf(“%.1f%%”, id(humidity_sensor).state)};
~^
In file included from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/cstdio:42,
from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/ext/string_conversions.h:43,
from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/bits/basic_string.h:6400,
from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/string:52,
from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-elf/include/c++/8.4.0/stdexcept:39,
from /data/cache/platformio/packages/toolchain-riscv32-esp/riscv32-esp-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-riscv32-esp/riscv32-esp-elf/sys-include/stdio.h:244:32: note: initializing argument 2 of ‘int sprintf(char*, const char*, …)’
int sprintf (char *__restrict, const char *__restrict, …)
^
~
/config/esphome/hemmis.yaml:73:61: error: could not convert ‘{}’ from ‘’ to ‘esphome::optional<std::__cxx11::basic_string >’
return {std::sprintf(“%.1f%%”, id(humidity_sensor).state)};
^
/config/esphome/hemmis.yaml: In lambda function:
/config/esphome/hemmis.yaml:80:7: error: ‘it’ was not declared in this scope
it = id(oled_display).get_text_draw(0);
^
/config/esphome/hemmis.yaml:80:7: note: suggested alternative: ‘int’
it = id(oled_display).get_text_draw(0);
^
int
/config/esphome/hemmis.yaml:80:26: error: ‘class esphome::ssd1306_i2c::I2CSSD1306’ has no member named ‘get_text_draw’; did you mean ‘get_text_bounds’?
it = id(oled_display).get_text_draw(0);
^
~~~~
get_text_bounds
/config/esphome/hemmis.yaml:83:21: error: ‘class esphome::ssd1306_i2c::I2CSSD1306’ has no member named ‘async_display’; did you mean ‘display’?
id(oled_display).async_display();
^~~~~~~~~~~~~
display
*** [.pioenvs/hemmis/src/main.o] Error 1
========================= [FAILED] Took 111.50 seconds =========================

Please keep us updated. We’re eager to find out!
Damn.

So now… how about posting your last yaml?

I just did 12 min ago

Properly formatted, not the chatgpt one.

1 Like
esphome:
  name: hemmis
  friendly_name: hemmis

esp32:
  board: seeed_xiao_esp32c3
  variant: ESP32C3
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "6Q6KlUXNo/sFmWFl95FQ9w+xrD0wGvPkI9nhIRYOKbo="

ota:
  password: "3e0cf106f66397e5c25b617030953960"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Hemmis Fallback Hotspot"
    password: "BDjQBIjT7kdG"

captive_portal:
web_server:
display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    id: oled_display
    rotation: 0

i2c:
  sda: GPIO6
  scl: GPIO7
  scan: False
font:
  - file: "Roboto-Regular.ttf"
    id: font1
    size: 12

sensor:
  - platform: dht
    model: DHT22
    pin: 2
    temperature:
      name: "Temperature"
      id: temperature_sensor
    humidity:
      name: "Humidity"
      id: humidity_sensor
    update_interval: 60s

text_sensor:
  - platform: template
    name: "Temperature Display"
    id: temperature_display
    icon: "mdi:thermometer"
    lambda: |-
      return std::string(std::to_string(id(temperature_sensor).state).c_str()) + "°C";
  - platform: template
    name: "Humidity Display"
    id: humidity_display
    icon: "mdi:water-percent"
    lambda: |-
      return std::string(std::to_string(id(humidity_sensor).state).c_str()) + "%";

# Update OLED display with temperature and humidity readings
interval:
  - interval: 10s
    then:
      - lambda: |-
          auto draw = id(oled_display).make_draw();
          draw->print(id(temperature_display).state.c_str());
          draw->println(" ");
          draw->print(id(humidity_display).state.c_str());
          id(oled_display).display();

This one did work?

I’m waiting for the slow compilation, ill update when it’s done :slight_smile:

now i get : /config/esphome/hemmis.yaml: In lambda function: /config/esphome/hemmis.yaml:80:33: error: 'class esphome::ssd1306_i2c::I2CSSD1306' has no member named 'get_preparer'; did you mean 'set_writer'? auto draw = id(oled_display).get_preparer(); ^~~~~~~~~~~~ set_writer /config/esphome/hemmis.yaml:81:38: error: 'OLED_COLOR_BLACK' was not declared in this scope draw->fill_rect(0, 0, 128, 64, OLED_COLOR_BLACK); ^~~~~~~~~~~~~~~~ /config/esphome/hemmis.yaml:81:38: note: suggested alternative: 'LOG_COLOR_BLACK' draw->fill_rect(0, 0, 128, 64, OLED_COLOR_BLACK); ^~~~~~~~~~~~~~~~ LOG_COLOR_BLACK /config/esphome/hemmis.yaml:82:27: error: 'FONT_FACE' was not declared in this scope draw->set_text_font(FONT_FACE("Roboto-Regular.ttf", 12)); ^~~~~~~~~ /config/esphome/hemmis.yaml:83:28: error: 'OLED_COLOR_WHITE' was not declared in this scope draw->set_text_color(OLED_COLOR_WHITE); ^~~~~~~~~~~~~~~~ /config/esphome/hemmis.yaml:83:28: note: suggested alternative: 'LOG_COLOR_I' draw->set_text_color(OLED_COLOR_WHITE); ^~~~~~~~~~~~~~~~ LOG_COLOR_I *** [.pioenvs/hemmis/src/main.o] Error 1

id’s were misplaced

esphome:
  name: hemmis
  friendly_name: hemmis

esp32:
  board: seeed_xiao_esp32c3
  variant: ESP32C3
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "6Q6KlUXNo/sFmWFl95FQ9w+xrD0wGvPkI9nhIRYOKbo="

ota:
  password: "3e0cf106f66397e5c25b617030953960"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Hemmis Fallback Hotspot"
    password: "BDjQBIjT7kdG"

sensor:
  - platform: dht
    model: AUTO_DETECT
    pin: 2
    temperature:
      name: "Temperature"
      id: dht_temp
    humidity:
      name: "Humidity"
      id: dht_humidity
    update_interval: 15s
i2c:
  sda: GPIO6
  scl: GPIO7
  scan: False

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    address: 0x3C
    lambda: |-
      it.printf(0, 0, id(font1), TextAlign::TOP_LEFT, "%.1f°", id(dht_temp).state);
      
font:
  - file: 'Roboto-Regular.ttf'
    id: font1
    size: 12

Firmware:

https://nextcloud.semperpax.be/s/dZ2Fx2FHF6ifTai/download/hemmis-factory.bin

it\s compiling… what is that firmware file?

It’s the result of the compilation.
You can flash it directly to the ESP with https://web.esphome.io/ in chrome/edge

we are close :smiley:
Now i get only one the display: 23.9’
nothing more… Would like to also show humidity… and like this: temp: “value”
hum: “Value”

Pal, if you cannot proceed from here, it’s pretty much desperate :wink:

1 Like