Template sensor not populating

Hello, Everyone. I’ve been trying to add two template sensors to my configuration.yaml file and am not having any luck with it populating. I have double-checked that the sensors it is dependent on exist, but I don’t see any other reasons why it won’t populate. For what it’s worth, the state section does work as tested in the Developer Tools section.

Any help would be appreciated

Here are the two template sensors:

# EV Incremental Diff Sensors for Driveway and Garage
template:
  - sensor:
      - name: "Driveway Charger Energy Increment"
        unique_id: "driveway_charger_energy_increment"
        unit_of_measurement: "kWh"
        state: >
          {% set current_energy = states('sensor.driveway_charger_energy') | float %}
          {% set previous_energy = state_attr('sensor.driveway_charger_energy_increment', 'last_value') | float(0) %}
          {% if current_energy >= previous_energy %}
            {{ (current_energy - previous_energy) | round(2) }}
          {% else %}
            0
          {% endif %}
        attribute_templates:
          last_value: "{{ states('sensor.driveway_charger_energy') | float }}"

      - name: "Garage Charger Energy Increment"
        unique_id: "garage_charger_energy_increment"
        unit_of_measurement: "kWh"
        state: >
          {% set current_energy = states('sensor.garage_charger_energy_new') | float %}
          {% set previous_energy = state_attr('sensor.garage_charger_energy_increment', 'last_value') | float(0) %}
          {% if current_energy >= previous_energy %}
            {{ (current_energy - previous_energy) | round(2) }}
          {% else %}
            0
          {% endif %}
        attribute_templates:
          last_value: "{{ states('sensor.garage_charger_energy_new') | float }}"```

attribute_templates is not a valid variable ID for the current format. Also, you would need to provide a more robust default method for the first run since the attributes you are using to provide the values for your previous_energy variables won’t exist. You would be better served using a trigger-based approach:

# EV Incremental Diff Sensors for Driveway and Garage
template:
  - trigger:
      - trigger: state
        entity_id: sensor.driveway_charger_energy
        not_to:
          - unknown
          - unavailable
    sensor:
      - name: "Driveway Charger Energy Increment"
        unique_id: "driveway_charger_energy_increment"
        unit_of_measurement: "kWh"
        state: >
          {% set current_energy = trigger.to_state.state | float(0) %}
          {% set previous_energy = trigger.from_state.state | float(0) %}
          {% if current_energy >= previous_energy %}
            {{ (current_energy - previous_energy) | round(2) }}
          {% else %}
            0
          {% endif %}

  - trigger:
      - trigger: state
        entity_id: sensor.garage_charger_energy_new
        not_to:
          - unknown
          - unavailable
    sensor:
      - name: "Garage Charger Energy Increment"
        unique_id: "garage_charger_energy_increment"
        unit_of_measurement: "kWh"
        state: >
          {% set current_energy = trigger.to_state.state | float(0) %}
          {% set previous_energy = trigger.from_state.state | float(0) %}
          {% if current_energy >= previous_energy %}
            {{ (current_energy - previous_energy) | round(2) }}
          {% else %}
            0
          {% endif %}