Compile time errors

Hi guys,
Could someone more knowledgeable than me with ESPhome please see where I’m going wrong here.

The errors on compile in Python are:

src\main.cpp:242:7: error: stray '\302' in program
       if (temperature->has_state()) { it.printf(10, 0, my_font, TextAlignTOP_LEFT , %.1f°, temperature->state); }
       ^
src\main.cpp:242:7: error: stray '\260' in program
Compiling .pioenvs\esp_poe_test\lib904\AsyncTCP-esphome\AsyncTCP.cpp.o
src\main.cpp: In lambda function:
src\main.cpp:242:24: error: 'class esphome::dht::DHT' has no member named 'has_state'
       if (temperature->has_state()) { it.printf(10, 0, my_font, TextAlignTOP_LEFT , %.1f°, temperature->state); }
                        ^
src\main.cpp:242:65: error: 'TextAlignTOP_LEFT' was not declared in this scope
       if (temperature->has_state()) { it.printf(10, 0, my_font, TextAlignTOP_LEFT , %.1f°, temperature->state); }
                                                                 ^
src\main.cpp:242:85: error: expected primary-expression before '%' token
       if (temperature->has_state()) { it.printf(10, 0, my_font, TextAlignTOP_LEFT , %.1f°, temperature->state); }
                                                                                     ^
src\main.cpp:242:106: error: 'class esphome::dht::DHT' has no member named 'state'
       if (temperature->has_state()) { it.printf(10, 0, my_font, TextAlignTOP_LEFT , %.1f°, temperature->state); }

And my mashup of code:

esphome:
  name: esp_poe_test
  platform: ESP32
  board: esp32-poe-iso
  
ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0
  power_pin: GPIO12
  manual_ip:
    static_ip: 10.0.0.20
    gateway: 10.0.0.139
    subnet: 255.0.0.0

i2c:
  sda: 13
  scl: 16
  scan: True
  id: bus_a
  
font:
    file: BebasNeue-Regular.ttf
    id: my_font
    size: 68

display:
    platform: ssd1306_i2c
    model: SSD1306 128x64
    #reset_pin D0
    address: 0x3C
    rotation: 0°
    lambda:
      if (id(temperature).has_state()) {
        it.printf(10, 0, id(my_font), TextAlignTOP_LEFT, %.1f°, id(temperature).state);
      }
  
sensor:
    platform: dht
    pin: 35
    id: temperature
    temperature:
      name: temperature
    humidity:
      name: humidity
    model: AM2302  
    update_interval: 60s  
    
web_server:
    port: 80

Thanks in advance for any tips!

1 Like

Try adding this after the lambda

    lambda: |-

I’ve marked this solved by micque (thanks micque!) but it turned out that wasn’t the only bad syntax :slight_smile:
Jesserockz on Discord was super helpful with straightening it out. Thanks Jesse!
I was also battling bad sensors that I must’ve damaged earlier on, just to double up on the experience :wink:

Here’s the working code for anyone else’s reference:

esphome:
  name: esp_poe_test
  platform: ESP32
  board: esp32-poe-iso
  
ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0
  power_pin: GPIO12
  manual_ip:
    static_ip: 10.0.0.20
    gateway: 10.0.0.139
    subnet: 255.0.0.0

i2c:
  sda: 13
  scl: 16
  scan: True
  id: bus_a
  
font:
    file: BebasNeue-Regular.ttf
    id: my_font
    size: 68
    
sensor:
    platform: dht
    pin: GPIO5
    temperature:
      id: temperature
      name: temperature
    humidity:
      id: humidity
      name: humidity
    model: DHT11  
    update_interval: 60s     

display:
    platform: ssd1306_i2c
    model: SSD1306 128x64
    #reset_pin D0
    address: 0x3C
    rotation: 0°
    lambda: |-
      if (id(temperature).has_state()) {
        it.printf(10, 0, id(my_font), TextAlign::TOP_LEFT, "%.1f°", id(temperature).state);
      }
  
    
web_server:
    port: 80
   
  
logger:
    level: DEBUG 
    baud_rate: 19200