ESPhome: How to access attributes of an entity?

Hi,
does anyone know what’s wrong here?

sensor:
  - platform: template
    sensors:
      haWeatherTemp:
        friendly_name: "Temperatur von HomeAssistant"
        entity_id: weather.myzone
        value_template: "{{states.weather.myzone.attributes.temperature}}"

All examples I’ve found look similar.
But I get the following error:

sensor.template: [source /config/esphome/nodemcu1.yaml:55]
  platform: template

  [sensors] is an invalid option for [sensor.template]. Please check the indentation.
  sensors:  [source /config/esphome/nodemcu1.yaml:57]
    haWeatherTemp: 
      friendly_name: Temperatur von HomeAssistant
      entity_id: weather.kelpi_haus
      value_template: {{states.weather.kelpi_haus.attributes.temperature}}

Thanks for your answers,
Tom

Lower case letters only in your sensor id.

haWeatherTemp
1 Like

Sorry, no change:

[sensors] is an invalid option for [sensor.template]. Please check the indentation.
  sensors:  [source /config/esphome/nodemcu1.yaml:57]
    haweathertemp: 
      friendly_name: Temperatur von HomeAssistant
      entity_id: weather.kelpi_haus
      value_template: {{states.weather.kelpi_haus.attributes.temperature}}
sensor:  # how many times does this line appear in your config? Should be only once.
  - platform: template
    sensors:
      haweathertemp:
        friendly_name: "Temperatur von HomeAssistant"
        entity_id: weather.myzone # no need for this it has been depreciated in v0.116, remove it, though this is most likely not your error. Should only generate a warning in the log. 
        value_template: "{{states.weather.myzone.attributes.temperature}}"

Yes, sensor: occurs only once.

I’ve deleted the line

entity_id:

still no change …

Are you sure it is that sensor causing the issue?

Because I can’t see anything wrong with it.

When I delete those lines everything is fine …
error

What happens if you run a configuration check using Configuration / Server Controls / Configuration Validation ?

I’m thinking it’s an issue with your editor.

No, there is everything fine.

Then there’s your answer. Whatever editor you are using has an issue.

Your config is fine.

How can I use a different editor?
I’m just using the ESPhome AddOn in HA …

Wait. I completely missed that you are trying to use home assistant’s template sensor format in esphome. I thought you were making a home assistant template sensor. Despite esphome being in the title and tags. Sorry.

Yeah your config is completely wrong. You want this:

I moved your post to the correct forum category.

Oh, shame on me. I’ve mixed those things up …

Now I’ve tried this:

  - platform: template
    name: "Temperatur von HomeAssistant"
    id: haWeatherTemp
    lambda: |-
      return (states.weather.kelpi_haus.attributes.temperature);

Unfortunately “states” is not declared. Do you also know how I can query the attributes of an entity?

Forget the template sensor in esphome.

If you want to bring an attribute into esphome use what you had originally (with the corrections) in home assistant to create a sensor from the attribute. Then use this to bring it into ESPhome:

You have to do it that way because unfortunately this esphome sensor does not support attributes.

I’m about to go to bed. If you have trouble let me know and I’ll write it out some time tomorrow.

@Metal-Frog, were you able to do this?

Thank you @tom_l
I scanned the esphome docs here and as far as I understand, there is no way to map all attributes from a HA sensor into ESPHome. We only can map 1 HA sensor attribute to one sensor in ESPHome. Correct?
That unfortunately really blows up coding as I want to show lots of information on local dashboard

Yes that is correct.

Is it because your trying to use the actual attributes? Couldn’t you send the attribute values to a template sensor and then use them as individual sensors? I know that’s probably not ideal but you may be able to get what you want

That was already suggested.

Most of the questions asked on this forum have been answered here or elsewhere many times already. I also asked them a question and engaged in discourse. I was under the impression that was the purpose for these forums.