Updated to 115.1 HASS extremely slow. Problem is templates

Im pretty new to this but i guess this code is pretty bad, alot of states, im reaching out couse i dont fully understand how i can solve it with groups atribute.

 - platform: command_line
   name: pellets cm
   json_attributes:
     - CmAnv
     - Cmkvar
     - Av
     - procentkv
     - Procentanv
     
   command: 'python2 /home/homeassistant/.homeassistant/python/testny.py'
   value_template: "{{ state_attr('sensor.pellets_cm', 'procentkv') }}"
   unit_of_measurement: 'cm'
   
 - platform: template
   sensors:
     pellets_kvar:
       friendly_name: "Pellets kvar"
       unit_of_measurement: '%'
       value_template: "{{ state_attr('sensor.pellets_cm', 'procentkv') }}"
       icon_template: 
        '{% if (states.sensor.pellets_kvar.state) == "100" %}
          mdi:battery
        {% elif (states.sensor.pellets_kvar.state) >= "90" %}
          mdi:battery-90
        {% elif (states.sensor.pellets_kvar.state) >= "80" %}
          mdi:battery-80
        {% elif (states.sensor.pellets_kvar.state) >= "70" %}
          mdi:battery-70
        {% elif (states.sensor.pellets_kvar.state) >= "60" %}
          mdi:battery-60
        {% elif (states.sensor.pellets_kvar.state) >= "50" %}
          mdi:battery-50

im just guessing but do i get it right that i have to do something like this?

grupp_pellets_niva:
    name: pellets niva
    entities:
      - sensor.pellets_cm
      - sensor.pellets_anvant
      - sensor.pellets_kvar
      - sensor.pellets2

and then

 - platform: template
   sensors:
     pellets_kvar:
       friendly_name: "Pellets kvar"
       unit_of_measurement: '%'
       value_template: "{{ expand ('group.pellets_niva') | selectattr ('state', 
  'sensor.pellets_cm', 'procentkv') }}"
       icon_template: 

The Template Sensor emplate doesn’t contain a single instance of states.

This template refers to the states of all entities in your system:

{{ states | selectattr('attributes.device_class', 'door') | map(attribute='entity_id') | list }}

See how it begins with the word states and proceeds to filter it selectattr and map? That’s completely different from anything in your Template Sensor which refers to the state of specific entities and not all entities.

ah i understand thx.