Template works in editor, not in config

I am stumped.
Can anyone please tell me whats wrong with the value template below?

- platform: template
  sensors:
    garage_humidity_difference:
      value_template: '{{ state_attr('weather.met_no', 'humidity') - ( states('sensor.garage_sensor_humidity')|int ) }}'
      friendly_name: 'Luftfuktighet ute vs garasje'
      #entity_id: sensor.garage_humidity_difference
      unit_of_measurement: '%'

It resolves in the template editor, but when I add it to my config I get the following error:

Error loading /config/configuration.yaml: while parsing a block mapping
in “/config/sensors/garage_humidity_difference.yaml”, line 4, column 7
expected , but found ‘< scalar >’
in “/config/sensors/garage_humidity_difference.yaml”, line 4, column 39

I can’t for the life of me see what’s wrong.

looks like you needed double qoutes instead of single quotes in some places, its valid in my config now

  - platform: template
    sensors:
      garage_humidity_difference:
        value_template: '{{ state_attr("weather.met_no", "humidity") - ( states("sensor.garage_sensor_humidity")|int ) }}'
        friendly_name: "Luftfuktighet ute vs garasje"
        #entity_id: sensor.garage_humidity_difference
        unit_of_measurement: '%'

Man!
So Templates need " instead of ’ ? Did not know that.
Thanks!

it depends…

the real issue is that the quotes inside the brackets {{}} need to be the opposite of the ones on the outside.

you can do it either way. so you could do this: “{{…’…’…}}” or this ‘{{…"…"…}}’ and both are valid.

it has to do with the way the parser sees the code.

Using your original code from the first post HA sees this

'{{ state_attr('
weather.met_no
', '
humidity
') - ( states('
sensor.garage_sensor_humidity
')|int ) }}'
1 Like