Problem with template integration

Hi all,

sorry, I cannot eliminate the error about the Template integration.

Can you tell me what´s wrong with the following code? I tried to change the syntax but it doesn´t work...

Thanks a lot!

Markus

- platform: template
    sensors:
      # Template sensor for current power comsumption
      power_current:
        unit_of_measurement: W
        friendly_name: "Power Current"
        availability: '{{ [ states(''sensor.shellypro3em_34987a469ca0_phase_a_active_power''),
            states(''sensor.shellypro3em_34987a469ca0_phase_b_active_power''), states(''sensor.shellypro3em_34987a469ca0_phase_c_active_power'')
            ] | map(''is_number'') | min }}'
        state: '{{ states(''sensor.shellypro3em_34987a469ca0_phase_a_active_power'')|float
            + states(''sensor.shellypro3em_34987a469ca0_phase_b_active_power'')|float +
            states(''sensor.shellypro3em_34987a469ca0_phase_c_active_power'')|float }}'
      

      # Template sensor for values of power import (active_power > 0)
      power_import:
        friendly_name: "Power Import"
        unit_of_measurement: "W"
        value_template: >-
          {% if (states('sensor.shellypro3em_34987a469ca0_phase_a_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_b_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')|float) > 0 %}
            {{ states('sensor.shellypro3em_34987a469ca0_phase_a_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_b_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')|float }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability_template: "{{
          [ states('sensor.shellypro3em_34987a469ca0_phase_a_active_power'),
          states('sensor.shellypro3em_34987a469ca0_phase_b_active_power'),
          states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')
          ] | map('is_number') | min
          }}"

      # Template sensor for values of power export (active_power < 0)
      power_export:
        friendly_name: "Power Export"
        unit_of_measurement: "W"
        value_template: >-
          {% if (states('sensor.shellypro3em_34987a469ca0_phase_a_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_b_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')|float) < 0 %}
            {{ (states('sensor.shellypro3em_34987a469ca0_phase_a_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_b_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')|float) * -1 }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability_template: "{{
          [ states('sensor.shellypro3em_34987a469ca0_phase_a_active_power'),
          states('sensor.shellypro3em_34987a469ca0_phase_b_active_power'),
          states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')
          ] | map('is_number') | min
          }}"

      # Template sensor for values of power consumption
      power_consumption:
        friendly_name: "Power Consumption"
        unit_of_measurement: "W"
        value_template: >-
          {% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) < 0 %}
            {{ 0 }}    
          {% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) > 0 %}
            {{ (states('sensor.power_solargen')|float(0)) - states('sensor.power_export')|float(0) }}    
          {% else %}
            {{ states('sensor.power_import')|float(0) + states('sensor.power_solargen')|float(0) }}
          {% endif %}

      # Template sensor for values of energy Solar generation (solar_power > 0)
      power_solargen:
        friendly_name: "Power Solar Generation"
        unit_of_measurement: "W"
        value_template: >-
          {% if ( 0 ) > 0 %}
            {{ ( 0 ) }}
          {% else %}
            {{ 0 }}
          {% endif %}

Maybe tell us about the error you are seing...

It is using the legacy syntax which was deprecated 6 months ago and fully removed in this months release. It looks like you changed 2 keys but didn't actually update the structure. By the looks of it, the provided config is likely configured directly under sensor (as was the case in your post 6 months ago) or in a file that is using sensor as its top-level key, meaning they are part of the sensor integration. Template entities need to be configured with template as their integration.

the platform key is no longer used for Template entities.

the sensors key is no longer used for Template entities.

the value_template key is no longer used for Template entities, it has been replace by state.

The availability_template key is no longer used for Template entities, it has been replace by availability.

The friendly_name key is no longer used for Template entities, it has been replace by name.

ID slugs are no longer used for Template entities, there are various configuration variables available to provide entity names and IDs.

The easiest way to fix this will be to change state and availability in power_current back to their original keys, then run the tool Petro has provided in the deprecation threads.

Ok, thank you for help.

The error I get ist this one:

My code looks now like this:

template:
    
      # Template sensor for current power comsumption
      power_current:
        unit_of_measurement: W
        friendly_name: "Power Current"
        availability: '{{ [ states(''sensor.shellypro3em_34987a469ca0_phase_a_active_power''),
            states(''sensor.shellypro3em_34987a469ca0_phase_b_active_power''), states(''sensor.shellypro3em_34987a469ca0_phase_c_active_power'')
            ] | map(''is_number'') | min }}'
        state: '{{ states(''sensor.shellypro3em_34987a469ca0_phase_a_active_power'')|float
            + states(''sensor.shellypro3em_34987a469ca0_phase_b_active_power'')|float +
            states(''sensor.shellypro3em_34987a469ca0_phase_c_active_power'')|float }}'
      

      # Template sensor for values of power import (active_power > 0)
      power_import:
        friendly_name: "Power Import"
        unit_of_measurement: "W"
        state: >-
          {% if (states('sensor.shellypro3em_34987a469ca0_phase_a_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_b_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')|float) > 0 %}
            {{ states('sensor.shellypro3em_34987a469ca0_phase_a_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_b_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')|float }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability: "{{
          [ states('sensor.shellypro3em_34987a469ca0_phase_a_active_power'),
          states('sensor.shellypro3em_34987a469ca0_phase_b_active_power'),
          states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')
          ] | map('is_number') | min
          }}"

      # Template sensor for values of power export (active_power < 0)
      power_export:
        friendly_name: "Power Export"
        unit_of_measurement: "W"
        state: >-
          {% if (states('sensor.shellypro3em_34987a469ca0_phase_a_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_b_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')|float) < 0 %}
            {{ (states('sensor.shellypro3em_34987a469ca0_phase_a_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_b_active_power')|float + states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')|float) * -1 }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability: "{{
          [ states('sensor.shellypro3em_34987a469ca0_phase_a_active_power'),
          states('sensor.shellypro3em_34987a469ca0_phase_b_active_power'),
          states('sensor.shellypro3em_34987a469ca0_phase_c_active_power')
          ] | map('is_number') | min
          }}"

      # Template sensor for values of power consumption
      power_consumption:
        friendly_name: "Power Consumption"
        unit_of_measurement: "W"
        state: >-
          {% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) < 0 %}
            {{ 0 }}    
          {% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) > 0 %}
            {{ (states('sensor.power_solargen')|float(0)) - states('sensor.power_export')|float(0) }}    
          {% else %}
            {{ states('sensor.power_import')|float(0) + states('sensor.power_solargen')|float(0) }}
          {% endif %}

      # Template sensor for values of energy Solar generation (solar_power > 0)
      power_solargen:
        friendly_name: "Power Solar Generation"
        unit_of_measurement: "W"
        state: >-
          {% if ( 0 ) > 0 %}
            {{ ( 0 ) }}
          {% else %}
            {{ 0 }}
          {% endif %}

What should I do with the IDs "power_current", etc.?

Markus

If you want to keep the same entity ID, use them as part of the default_entity_id.

You have not fixed the instances of friendly_name.

And, you still need to fix the structure. The value for template needs to be a list, not a dictionary. Check out the examples for state-based template sensors in the docs: