Yet another template question

Trying to pull the temperature attribute out of weather.home:

Trying this code:

 - platform: template
   sensors:
     outdoor_temp:
       value_template: '{{ state_attr('weather.home', 'temperature') }}'
       friendly_name: 'Outdoor Temperature'

But I am getting this error:

Error loading /config/configuration.yaml: while parsing a block mapping
in "/config/configuration.yaml", line 447, column 8
expected <block end>, but found '<scalar>'
in "/config/configuration.yaml", line 447, column 40

What am I doing wrong? Thanks!

Try this:

template:
   sensor:
     - name: Outdoor Temp
       unique_id: outdoor_temp
       state: "{{ state_attr('weather.home', 'temperature') }}"

If you want to keep your syntax (aka “legacy”), you have to quote your expression right.

"{{ state_attr('weather.home', 'temperature') }}"

in your code, you’re opening a quote at '{{ then close at (' then open again at ') and finally close at }}', Jinja2 can not understand that.

If you don’t want to use “”, then you can do a line break:

vaue_template: >
  {{ state_attr('weather.home', 'temperature') }}

Or use the “modern” templating given by @jchh

1 Like

I should have explained that I also corrected it whilst formatting for the 'modern way. Thanks for clarifying that @Olivier1974 :slight_smile:

Thanks! This works.