ESPhome: How to access attributes of an entity?

Tags: #<Tag:0x00007f327078add0> #<Tag:0x00007f327078ab28>

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

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.