Template configuration format error

Hello,

In the logbooks I keep getting the error:

“WARNING (MainThread) [homeassistant.components.template.config] The entity definition format under template: differs from the platform configuration format. See Template - Home Assistant

I have no idea how to fix this, the scripts does work, but i like to resolve the error.

This is the code:

---
# Energie DSMR Readings and Prices
#
sensors:
  # DSMR METER READINGS #

  # CALCULATION TARIF LOW + NORMAL
  hourly_energy:
    friendly_name: Hourly energy
    unit_of_measurement: kWh
    value_template: "{{ states('sensor.hourly_energy_offpeak')|float + states('sensor.hourly_energy_peak')|float }}"
  daily_energy:
    friendly_name: Daily energy
    unit_of_measurement: kWh
    value_template: "{{ states('sensor.daily_energy_offpeak')|float + states('sensor.daily_energy_peak')|float }}"
  weekly_energy:
    friendly_name: Weekly energy
    unit_of_measurement: kWh
    value_template: "{{ states('sensor.weekly_energy_offpeak')|float + states('sensor.weekly_energy_peak')|float }}"
  monthly_energy:
    friendly_name: Monthly energy
    unit_of_measurement: kWh
    value_template: "{{ states('sensor.monthly_energy_offpeak')|float + states('sensor.monthly_energy_peak')|float }}"
  yearly_energy:
    friendly_name: Yearly energy
    unit_of_measurement: kWh
    value_template: "{{ states('sensor.yearly_energy_offpeak')|float + states('sensor.yearly_energy_peak')|float }}"
  # LAST PERIODS GAS
  yesterday_gas:
    friendly_name: Yesterday Gas
    unit_of_measurement: m3
    value_template: "{{ state_attr('sensor.daily_gas','last_period') }}"
  last_week_gas:
    friendly_name: last Week Gas
    unit_of_measurement: m3
    value_template: "{{ state_attr('sensor.weekly_gas','last_period') }}"
  last_month_gas:
    friendly_name: last Month Gas
    unit_of_measurement: m3
    value_template: "{{ state_attr('sensor.monthly_gas','last_period') }}"
  last_year_gas:
    friendly_name: last Year Gas
    unit_of_measurement: m3
    value_template: "{{ state_attr('sensor.yearly_gas','last_period') }}"

  # LAST PERIODS energy
  yesterday_energy:
    friendly_name: Yesterday energy
    unit_of_measurement: kWh
    value_template: "{{ state_attr('sensor.daily_energy_offpeak','last_period')|float + state_attr('sensor.daily_energy_peak','last_period')|float }}"
  last_week_energy:
    friendly_name: Last Week energy
    unit_of_measurement: kWh
    value_template: "{{ state_attr('sensor.weekly_energy_offpeak','last_period')|float + state_attr('sensor.weekly_energy_peak','last_period')|float }}"
  last_month_energy:
    friendly_name: Last Month energy
    unit_of_measurement: kWh
    value_template: "{{ state_attr('sensor.monthly_energy_offpeak','last_period')|float + state_attr('sensor.monthly_energy_peak','last_period')|float }}"
  last_year_energy:
    friendly_name: Last Year energy
    unit_of_measurement: kWh
    value_template: "{{ state_attr('sensor.yearly_energy_offpeak','last_period')|float + state_attr('sensor.yearly_energy_peak','last_period')|float }}"

  # SHORT energy
  # Daily
  daily_energy_short:
    value_template: "{{ '%.3f'%(states('sensor.daily_energy') | float) | float }}"
    unit_of_measurement: "kWh"
  # Yesterdag
  yesterday_energy_short:
    value_template: "{{ '%.3f'%(states('sensor.yesterday_energy') | float) | float }}"
    unit_of_measurement: "kWh"
  # Weekly
  weekly_energy_short:
    value_template: "{{ '%.3f'%(states('sensor.weekly_energy') | float) | float }}"
    unit_of_measurement: "kWh"
  # Last Week
  last_week_energy_short:
    value_template: "{{ '%.3f'%(states('sensor.last_week_energy') | float) | float }}"
    unit_of_measurement: "kWh"
  # Monthly
  monthly_energy_short:
    value_template: "{{ '%.3f'%(states('sensor.monthly_energy') | float) | float }}"
    unit_of_measurement: "kWh"
  # Last Month
  last_month_energy_short:
    value_template: "{{ '%.3f'%(states('sensor.last_month_energy') | float) | float }}"
    unit_of_measurement: "kWh"
  # Yearly
  yearly_energy_short:
    value_template: "{{ '%.3f'%(states('sensor.yearly_energy') | float) | float }}"
    unit_of_measurement: "kWh"
  # Last Year
  last_year_energy_short:
    value_template: "{{ '%.3f'%(states('sensor.last_year_energy') | float) | float }}"
    unit_of_measurement: "kWh"

  # CACULATIONS
  # kWh to Watt
  energy_kwh_to_watt:
    friendly_name: "Actueel Watt"
    unit_of_measurement: "Watt"
    value_template: "{{ (states.sensor.power_consumption.state | float * 1000) | round(0) }}"
  # Gemiddeld Gas Day
  average_gas_day:
    unit_of_measurement: "m3"
    value_template: >-
      {% set a = states('sensor.last_month_gas') | float %}
      {{ (a / 30.41) | round(3) }}
  # Gemiddeld Energy Day
  average_energy_day:
    unit_of_measurement: "kWh"
    value_template: >-
      {% set a = states('sensor.last_month_energy') | float %}
      {{ (a / 30.41) | round(3) }}

  # ENERGIE Levercancier Prijzen
  today_gas_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.daily_gas') | float %}
      {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
      {% set c = states('input_number.netbeheerkosten_gas') | float / 365 %}
      {% set d = states('input_number.vaste_leveringskosten_gas') | float / 365 %}
      {{ (((a * b) + c) + d) | round(2) }}

  yesterday_gas_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.yesterday_gas') | float %}
      {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
      {% set c = states('input_number.netbeheerkosten_gas') | float / 365 %}
      {% set d = states('input_number.vaste_leveringskosten_gas') | float / 365 %}
      {{ (((a * b) + c) + d) | round(2) }}

  week_gas_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.weekly_gas') | float %}
      {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
      {% set c = states('input_number.netbeheerkosten_gas') | float / 52 %}
      {% set d = states('input_number.vaste_leveringskosten_gas') | float / 52 %}
      {{ (((a * b) + c) + d) | round(2) }}

  last_week_gas_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.last_week_gas') | float %}
      {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
      {% set c = states('input_number.netbeheerkosten_gas') | float / 52 %}
      {% set d = states('input_number.vaste_leveringskosten_gas') | float / 52 %}
       {{ (((a * b) + c) + d) | round(2) }}

  month_gas_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.monthly_gas') | float %}
      {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
      {% set c = states('input_number.netbeheerkosten_gas') | float / 12 %}
      {% set d = states('input_number.vaste_leveringskosten_gas') | float / 12 %}
      {{ (((a * b) + c) + d) | round(2) }}

  last_month_gas_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.last_month_gas') | float %}
      {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
      {% set c = states('input_number.netbeheerkosten_gas') | float / 12 %}
      {% set d = states('input_number.vaste_leveringskosten_gas') | float / 12 %}
      {{ (((a * b) + c) + d) | round(2) }}

  year_gas_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.yearly_gas') | float %}
      {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
      {% set c = states('input_number.netbeheerkosten_gas') | float %}
      {% set d = states('input_number.vaste_leveringskosten_gas') | float %}
       {{ (((a * b) + c) + d) | round(2) }}

  last_year_gas_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.last_year_gas') | float %}
      {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
      {% set c = states('input_number.netbeheerkosten_gas') | float %}
      {% set d = states('input_number.vaste_leveringskosten_gas') | float %}
      {{ (((a * b) + c) + d) | round(2) }}

  today_energy_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.daily_energy') | float %}
      {% set b = states('input_number.all_in_enkeltarief_stroom') | float %}
      {% set c = states('input_number.netbeheerkosten_stroom') | float / 365 %}
      {% set d = states('input_number.vaste_leveringskosten_stroom') | float / 365 %}
      {% set e = states('input_number.vermindering_energiebelasting_stroom') | float / 365 %}
      {{ ((((a * b) + c) + d) + e) | round(2) }}

  yesterday_energy_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.yesterday_energy') | float %}
      {% set b = states('input_number.all_in_enkeltarief_stroom') | float %}
      {% set c = states('input_number.netbeheerkosten_stroom') | float / 365 %}
      {% set d = states('input_number.vaste_leveringskosten_stroom') | float / 365 %}
      {% set e = states('input_number.vermindering_energiebelasting_stroom') | float / 365 %}
      {{ ((((a * b) + c) + d) + e) | round(2) }}

  week_energy_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.weekly_energy') | float %}
      {% set b = states('input_number.all_in_enkeltarief_stroom') | float %}
      {% set c = states('input_number.netbeheerkosten_stroom') | float / 52 %}
      {% set d = states('input_number.vaste_leveringskosten_stroom') | float / 52 %}
      {% set e = states('input_number.vermindering_energiebelasting_stroom') | float / 52 %}
      {{ ((((a * b) + c) + d) + e) | round(2) }}

  last_week_energy_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.last_week_energy') | float %}
      {% set b = states('input_number.all_in_enkeltarief_stroom') | float %}
      {% set c = states('input_number.netbeheerkosten_stroom') | float / 52 %}
      {% set d = states('input_number.vaste_leveringskosten_stroom') | float / 52 %}
      {% set e = states('input_number.vermindering_energiebelasting_stroom') | float / 52 %}
      {{ ((((a * b) + c) + d) + e) | round(2) }}

  month_energy_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.monthly_energy') | float %}
      {% set b = states('input_number.all_in_enkeltarief_stroom') | float %}
      {% set c = states('input_number.netbeheerkosten_stroom') | float / 12 %}
      {% set d = states('input_number.vaste_leveringskosten_stroom') | float / 12 %}
      {% set e = states('input_number.vermindering_energiebelasting_stroom') | float / 12 %}
      {{ ((((a * b) + c) + d) + e) | round(2) }}

  last_month_energy_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.last_month_energy') | float %}
      {% set b = states('input_number.all_in_enkeltarief_stroom') | float %}
      {% set c = states('input_number.netbeheerkosten_stroom') | float / 12 %}
      {% set d = states('input_number.vaste_leveringskosten_stroom') | float / 12 %}
      {% set e = states('input_number.vermindering_energiebelasting_stroom') | float / 12 %}
      {{ ((((a * b) + c) + d) + e) | round(2) }}

  year_energy_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.yearly_energy') | float %}
      {% set b = states('input_number.all_in_enkeltarief_stroom') | float %}
      {% set c = states('input_number.netbeheerkosten_stroom') | float %}
      {% set d = states('input_number.vaste_leveringskosten_stroom') | float %}
      {% set e = states('input_number.vermindering_energiebelasting_stroom') | float %}
      {{ ((((a * b) + c) + d) + e) | round(2) }}

  last_year_energy_price:
    unit_of_measurement: "EUR"
    value_template: >-
      {% set a = states('sensor.last_year_energy') | float %}
      {% set b = states('input_number.all_in_enkeltarief_stroom') | float %}
      {% set c = states('input_number.netbeheerkosten_stroom') | float %}
      {% set d = states('input_number.vaste_leveringskosten_stroom') | float %}
      {% set e = states('input_number.vermindering_energiebelasting_stroom') | float %}
      {{ ((((a * b) + c) + d) + e) | round(2) }}

Can someone please help find out what i am doing wrong?

Have a look at the first example in the documentation for Legacy Template Sensor configuration format. Take note of the line specifying the platform type that appears before the line containing the word sensors:

Where is that in your posted configuration?

I have it like this:

configuration.yaml:
packages: !include_dir_named integrations
__
template: !include_dir_list …/entities/templates
__
sensor: !include_dir_list …/entities/sensors

So, the code is in entities/templates/code.yaml
It is not inside the “sensor” file anymore.

Isn’t is just sensor: and not sensors:

If the domain is template then that means you are using the new way of defining Template Sensors (as opposed to the legacy method). However, in that case, your “new style” configuration is using “old style” options.

There’s no friendly_name option in the new style (it’s name) and the configuration structure is different.

Refer to the documentation for State-based Template Sensors.

1 Like

Yes, that is correct.
Then I have to find out how to “convert” the code to the new format I think.

Typo:
friendly_name would be name in “new style”, actually. value_template is what became state

2 Likes

Fixed it seconds before you spotted it. :slightly_smiling_face:

1 Like

It’s all in the documentation but it’s not merely changing the names of a few options. The overall structure has also changed. Pay close attention to the example showing multiple sensors.

1 Like

I know, thats the hard part haha, I am very new in code so it will not be in a few days :stuck_out_tongue:

Also template: !include_dir_list …/entities/templates makes it difficultier with more sensors in one file.

I assume you know that the template domain is exclusively for Template Sensors defined with the new format. It cannot contain Template Sensors defined with the old format or a sensor based on a different platform.

Yes, but I have dir_list and not dir_list_merge,
I am confused wheter or not to place every template in a seerate file or if i can make the whole code in one file.

I have to look it all up when I have more time