Showing select type entity id on esp32 screen

I am trying to show the text of a select type id on an ESp32 screen.
Text and floats (numbers) are working fine, but when I try to show the value of a select (dropdown box) I get nom.

This is the relevant code (for the ESP device in esphome):

text_sensor:
  - platform: homeassistant
    id: sessy_power_strategy
    entity_id: select.sessy_dk5u_power_strategy
    internal: True
display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x32"
    address: 0x3C
    lambda: |-
      // Print Power Strategy (from homeassistant sensor)
      if (id(sessy_power_strategy).has_state()) {
        it.printf(0, 32, id(font1), TextAlign::BOTTOM_LEFT , "Strat: %s", id(sessy_power_strategy).state.c_str());
      }

As stated, the result on screen is “Strat: nom”

What am I missing here?

What do the logs say when you get that sensor from HA?

Hi Daryl,

On install it initially only says this in the logs:
[14:15:44][D][homeassistant.text_sensor:017]: ‘select.sessy_dk5u_power_strategy’: Got state ‘nom’
[14:15:44][D][text_sensor:064]: ‘sessy_power_strategy’: Sending state ‘nom’

The sensor has the following options:

Try:

    entity_id: 'select.sessy_dk5u_power_strategy'

I don’t have any integrations that create a select entity - so I can’t test. The quotes shouldn’t make any difference but worth a try.

Ok - I found a Zigbee button that creates a select entity and it works with or without quotes. I suspect the issue is on the HA side.

Find the entity in States under Developer Tools. Check the name - the current state and the valid states - they will be listed as options: followed by a comma separated list.

Hi Daryl,

Thank you for the replies! much appreciated.

So I am feeling like an idiot right now for not noticing this before, but nom is one of the options of the select. Not one of the displayed options though. So the select looks like this:


Is there a way to get the Human readable state names (like the screenshot I posted before) and use them? Or should I do a remap with if’s in the esp code?

I just changed the lambda to display the correct string to below code, and it works!
Thanks again!

      // Map Power Stratigies
      std::map<std::string, std::string> power_strategy_map {
        {"api", "API"},
        {"nom", "Net Zero"},
        {"roi", "Dynamic"},
        {"idle", "Idle"},
        {"sessy_connect", "SessyConnect"},
        {"eco", "Eco"},
      };
      // Print Power Strategy (from homeassistant sensor)
      if (id(sessy_power_strategy).has_state()) {
        it.printf(0, 32, id(font1), TextAlign::BOTTOM_LEFT , "Strat: %s", power_strategy_map[id(sessy_power_strategy).state.c_str()].c_str());
      }
1 Like