Access a HA climate entity attribute from inside ESPhome?

I’m wanting to display the current HA climate action attribute of my Daikin AC, on a status page of the 16x2 LCD on a current project I have. I am so far unable though, LCD shows nothing where I hoped to see the attribute text.
I think I can get this attribute as described here (but perhaps this is not the case):
Climate Entity | Home Assistant Developer Docs (home-assistant.io)

In Esphome I have this text_sensor

  - platform: homeassistant
    id: ac_current_mode
    entity_id: climate.daikin_ac
    attribute: HVACAction
    internal: true

Is that a valid way to get the attribute data from HA into ESPhome?

Create a Template inside HA which pulls out the attribute into a sensor. That sensor can then be pulled into the ESP.

First use Developers Tools/ States to check the exact attribute name and details and then a Template. For example I pull out the Temperate

- sensor:
    # Temperature Thermostats
    - name: "Kitchen Heatmiser Temperature"
      unit_of_measurement: "°C"
      state: "{{ (state_attr('climate.kitchen','current_temperature') | float) | round(1)}}"

Recently I achieved something similar in ESPHome, but using a full-color LCD (M5Stack AtomS3) :

sensor:
  - platform: homeassistant
    id: current_temperature
    entity_id: climate.woonkamer
    attribute: current_temperature

Then, in my case I am able to show the text on the LCD like so :

it.printf(it.get_width()/2, it.get_height()/2, id(roboto), TextAlign::CENTER, "%.1f°C", id(current_temperature).state);

The example should probably be slightly altered for your case where you are using a character LCD.

Note that my example is a regular sensor, not a text_sensor.

As mentioned by @JulianDH, you can use the developer tools to make sure you are referring to the correct entity and/or attribute.

1 Like

Thanks Julian & Didel.

Got it working. Your tips about Developer tools attribute names was the missing link.
Although I had looked at the states in Dev Tools list before, I’d not actually selected the climate entity in the ‘Set state’ field (as that seemed counter intuitive to do when not setting a state). When I selected climate.daikin_ac the full list of applicable attributes is displayed. The attribute is not what’s in the climate entity docs…
So this works, and I can display on the LCD fine now thanks.

  - platform: homeassistant
    id: ac_current_mode
    entity_id: climate.daikin_ac
    attribute: hvac_action
    internal: true

The snippet of LCD code.
      } else if (id(display_page_id) == 4) {
        it.printf(0, 0, "AC status %s ", id(ac_current_mode).state.c_str());

No need for a HA Template here it seems so far.

and I didnt know you could pull out attribute inside ESPHome. I need to keep reading …

The attribute can be called into esphome without creating an intermediate sensor.

FWIW I have some example code here: HVAC - VAV control via ESPHome - #3 by zagnuts - the trick if any is to work out if you need to refer to the entity from home assistant as a sensor or text sensor, and how to then work with that to display properly eg id(name).state or id(name).state.c_str()