jruben4
(Jason)
June 18, 2023, 4:44pm
1
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!
jchh
((not John))
June 18, 2023, 5:21pm
2
Try this:
template:
sensor:
- name: Outdoor Temp
unique_id: outdoor_temp
state: "{{ state_attr('weather.home', 'temperature') }}"
Olivier1974
(Olivier Toussaint)
June 18, 2023, 5:45pm
3
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
jchh
((not John))
June 18, 2023, 5:56pm
4
I should have explained that I also corrected it whilst formatting for the 'modern way. Thanks for clarifying that @Olivier1974