Show temperature on tm1637 diplay

Hello everyone. I’m trying to set up an ESP32 with a MAX6675 sensor and a TM1632 display. I would like the temperature to be read and shown on the display. This is my configuration but it is incorrect. I can’t understand why. Could you give me a hand?

esphome:
  name: termometro-caldaia
  friendly_name: Termometro caldaia

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "cancelled"

ota:
  - platform: esphome
    password: "cancelled"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "cancelled"
    password: "cancelled"

captive_portal:
    
spi:
  miso_pin: GPIO13
  clk_pin: GPIO12
sensor:
  - platform: max6675
    name: "Temperatura acqua"
    id: temperatura_acqua
    cs_pin: GPIO45
    update_interval: 10s
    
text_sensor:
  - platform: homeassistant
    id: temperatura_acqua
    entity_id: sensor.esp_caldaia_temperatura_acqua
    attribute: teperatura_acqua
    

display:
  - platform: tm1637
    id: tm1637_display
    clk_pin: GPIO4
    dio_pin: GPIO5
    inverted: true
    intensity: 3
    update_interval: 10s
    length: 4
    lambda: |-
      it.printf(0, id(sensor.esp_caldaia_temperatura_acqua).state);

error from esphome builder:

Lambda contains reference to entity-id-style ID 'sensor.esp_caldaia_temperatura_acqua'. The id() wrapper only works for ESPHome-internal types. For importing states from Home Assistant use the 'homeassistant' sensor platforms.

what can i do please?

You are referring to the source sensor from HA - not the one you defined in the Home Assistant sensor.

Your ESPHome sensor is like:

    lambda: |-
      it.printf(0, id(temperatura_acqua).state);

Welcome to forum.
Your error message tells what’s wrong. You need to use esphome id, not entity id.

it.printf(0, 0, id(my_font), "Temp: %s", id(temperatura_acqua).state.c_str());


You need to convert the text sensor to C-style string.
ps. every component has to have unique id.

Thank you for the answer, you were very fast! last night I had tried with Zoogara’s suggestion but the esp32 no longer connected to the network… Maybe I made some typos. I thought there was some problem so I tried to get around it by using the HomeAssistant sensor. Now I tried again with the modification described by Zoogara and indeed the esp32 connected. I can’t verify the proper functioning of the display right now but I’ll look tonight. Thank you very much zoogara! Thank you very much for the insight Karosm.

sorry maybe I misunderstood. I tried to change the configuration using Zoogara’s suggestion but the results were:

  1. Device disconnection
  2. display off.
    I’m sure the display works because if I write “it.print(“0123”);” 0123 is shown on the display. at this point I reread what Karosm wrote but after compiling it I get an error… The sensor is float type.
    I am continuing to search on the internet but the proposed solutions, in my case, do not work.

Can you post the code, that gave that error.
Did you fix your max6675-sensor and text_sensor having same id?

esphome:
  name: esp-caldaia
  friendly_name: esp caldaia

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "cancelled"

ota:
  - platform: esphome
    password: "cancelled"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Caldaia Fallback Hotspot"
    password: "cancelled"

captive_portal:

spi:
  miso_pin: GPIO13
  clk_pin: GPIO12

sensor:

- platform: max6675
  name: "temperatura acqua"
  id: temperatura_acqua
  cs_pin: GPIO45
  update_interval: 10s

text_sensor:
  - platform: homeassistant
    name: "temperatura acqua"
    id: esp_caldaia_temperatura_acqua
    entity_id: sensor.esp_caldaia_temperatura_acqua

display:
  - platform: tm1637
    id: tm1637_display
    clk_pin: GPIO4
    dio_pin: GPIO5
    intensity: 7
    update_interval: 10s
    length: 4
    lambda: |-
      it.printf(0, 0, "Temp: %s", id(temperatura_acqua).state.c_str());
/config/esphome/esp-caldaia.yaml:60:60: error: request for member 'c_str' in 'temperatura_acqua->esphome::max6675::MAX6675Sensor::esphome::sensor::Sensor.esphome::sensor::Sensor::state', which is of non-class type 'float'
   60 |       it.printf(0, 0, "Temp: %s", id(temperatura_acqua).state.c_str());
      |                                                            ^~~~~
*** [.pioenvs/esp-caldaia/src/main.cpp.o] Error 1

If that’s the id you want to print.

but that is pointing to max6675 sensor.

So if you want to print that HA text sensor:

 lambda: |-
      it.printf(0, 0, "Temp: %s", id(esp_caldaia_temperatura_acqua).state.c_str());

But if you are looking for to print the max6675 sensor , you need:

 lambda: |-
      it.printf(0, 0, "Temp: %1f", id(temperatura_acqua).state);

So what you actually want to print?

i tried with :

lambda: |-
      it.printf(0, 0, "Temp: %s", id(esp_caldaia_temperatura_acqua).state.c_str());

but like as

lambda: |-
      it.printf(0, 0, "Temp: %1f", id(temperatura_acqua).state);

the esp lost connection. logs :

INFO Processing unexpected disconnect from ESPHome API for esp-caldaia @ esp ip
WARNING Disconnected from API
INFO Successfully resolved esp-caldaia @ esp ip in 0.000s
WARNING Can't connect to ESPHome API for esp-caldaia @ esp ip: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='esp ip', port=6053))]: [Errno 111] Connect call failed ('esp ip', 6053) (SocketAPIError)
INFO Trying to connect to esp-caldaia @ esp ip in the background

Look, can you answer the question:

I tried to print “HA text-sensor” but for me it is not important what is printed. I would just like to see the current temperature on the display :sweat_smile:

That HA text sensor has been doing just confusion here, so remove it from your configuration.

To display max6675 output, this lambda is enough:

 lambda: |-
      it.printf(0, 0, "Temp: %.1f", id(temperatura_acqua).state);

Ok, I removed the “text_sensor” and I used :

display:
  - platform: tm1637
    id: tm1637_display
    clk_pin: GPIO4
    dio_pin: GPIO5
    intensity: 7
    update_interval: 10s
    length: 4
    lambda: |-
      it.printf(0, 0, "Temp: %.1f", id(temperatura_acqua).state);

The problem is that I get this error back:

INFO Starting log output from esp_ip using esphome API
INFO Successfully resolved esp-caldaia @ esp_ip in 0.000s
WARNING Can't connect to ESPHome API for esp-caldaia @ esp_ip: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='esp_ip', port=6053))]: [Errno 111] Connect call failed ('esp_ip', 6053) (SocketAPIError)
INFO Trying to connect to esp-caldaia @ esp_ip in the background

It’s not related to the sensor reading print lambda on display…
Something else you were tinkering with?

no. if I delete the display from the configuration I don’t get any connection error.

You are right, I didn’t bother to look what kind of display you have. Only 4 digits.

it.printf(0, "%.1f", id(temperatura_acqua).state);

Okay, now it works. I send the final configuration in case someone needs it

esphome:
  name: esp-caldaia
  friendly_name: esp caldaia

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: esp-idf

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "cancelled"

ota:
  - platform: esphome
    password: "cancelled"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esp-Caldaia Fallback Hotspot"
    password: "cancelled"

captive_portal:

spi:
  miso_pin: GPIO13
  clk_pin: GPIO12

sensor:

- platform: max6675
  name: "temperatura acqua"
  id: temperatura_acqua
  cs_pin: GPIO45
  update_interval: 10s

display:
  - platform: tm1637
    id: tm1637_display
    clk_pin: GPIO4
    dio_pin: GPIO5
    intensity: 7
    update_interval: 10s
    length: 4
    lambda: |-
      it.printf(0, "%.1f", id(temperatura_acqua).state);

I thank you Karosm for making me understand the difference between the various IDs and for patiently responding to my requests.

You’re welcome.
Without that HA text sensor confusing there you/we likely solved this at first step :wink:

1 Like