Replacement of value_template

Hi, I’m a little confused.
As an example here two typical and simple sensors I use:

- platform: template
  sensors:
    throughput_in_kb:
      friendly_name: Durchsatz in Kb
      value_template: "{{ (states('sensor.network_throughput_in_eth0') | float * 1000) |round(1) }}"
    outside_temperature_trend:
      friendly_name: "Temperatur Trend"
      value_template: >
        {% if states('binary_sensor.outside_temp_rising') == 'on' %}
          up
        {% elif states('binary_sensor.outside_temp_falling') == 'on' %}
          down
        {% else %}
          stable
        {% endif %}

Now I’ve read in the docs, that value_template is not used anymore and can be replaced by value, which works in automations and scripts.
And I’ve read in the docs, that a template sensor is state based or trigger based like this example mentioned in the community docs:

template:
  - sensor:
      - name: "Average temperature"
        unit_of_measurement: "°C"
        state: >
          {% set bedroom = states('sensor.bedroom_temperature') | float %}
          {% set kitchen = states('sensor.kitchen_temperature') | float %}

          {{ ((bedroom + kitchen) / 2) | round(1, default=0) }}

When I no replace “value_template” with “state” I get an error that state is an invalid expression. Even when I replace “value_template” with “value” it is the same error. So by now, I still work with value_template.
What did I misunderstood?

value_template has not been replaced. data_template and service_template can be changed to just data and service respectively.

state can only be used with the new template sensor integration (your second example), not the legacy template sensor platform (your first example)

aah, thanks. Then I’m up to date.
Does the new template sensor integration has any significant advantages vs the standard. What is the value add except some different attributes and the trigger part?

It supports state_class. You have to use customize to add this to the legacy platform. This was added for long term statistics and energy dashboard support.

1 Like

Oh, one more: You can reload the template integration after you make changes without restarting Home Assistant, which I am pretty sure is required for the legacy template sensor platform.