Question about new template vs legacy ones

First of all.

Can you still have legacy_templates: true in configuration.yaml and use the new ones?

I thought it would be a good times to try the new templates as I wanted to create new sensors.

I tried:

template:
  sensor:
    - name: poolheater_adjusted_wh
      unit_of_measurement: Wh
      device_class: energy
      state_class: total_increasing
      state: >
        {% set poolheater = states('sensor.poolheater_wh') | float %}
        {% set gpo = (states('sensor.daily_15a_gpo_kwh') | float * 1000 %}
        {{  poolheater - gpo }}

    - name: pooltotal_adjusted_wh
      unit_of_measurement: Wh
      device_class: energy
      state_class: total_increasing
      state: >
        {% set poolheater = states('sensor.poolheater_adjusted_wh') | float %}
        {% set pool = (states('sensor.pool_wh') | float %}
        {{ poolheater + pool }}

in my configuration.yaml

Check configuration gives me the all green, but when I restart I get:

Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected '}', expected ')') for dictionary value @ data['sensor'][0]['state']. Got "{% set poolheater = states('sensor.poolheater_wh') | float %} {% set gpo = (states('sensor.daily_15a_gpo_kwh') | float * 1000 %} {{ poolheater - gpo }}\n". (See /config/configuration.yaml, line 40).
Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected '}', expected ')') for dictionary value @ data['sensor'][0]['state']. Got "{% set poolheater = states('sensor.poolheater_wh') | float %} {% set gpo = (states('sensor.daily_15a_gpo_kwh') | float * 1000 %} {{ poolheater - gpo }}\n". (See /config/configuration.yaml, line 304). 

Not sure I follow the line number; line 40 has nothing to do with where my templates are defined

Must be missing something obvious… but what?

Second line of both your state templates open two brackets but only close one.

The error is pointing to the first template twice, though. If this is all in configuration.yaml, what’s on lines 40 and 304? The use of !includes can confuse the line numbering.

doh!
thanks :slight_smile:

line 40 is

rest_command: !include rest_command.yaml