Help with sensor to monitor Min Max Cell Voltages

Hi

I am trying to create a sensor that will show the Min, Max and Delta voltages of the cells in my battery modules, and output the cell number for the Min Max

This code works in template editor but not when I add it to my Yaml code, I just get a Null output (no errors)

I have 5 battery modules in total and the goal it to monitor the Min, Max and Delta.

Image of the Result from template editor

Image of the state attributes

template:
  - sensor:
      - name: "Battery Module Cell V Max Min Delta"
        state: >-      
         {% set voltages = [
          states('sensor.esp_monitor_cells_voltage_201') | float(0),
          states('sensor.esp_monitor_cells_voltage_202') | float(0),
          states('sensor.esp_monitor_cells_voltage_203') | float(0),
          states('sensor.esp_monitor_cells_voltage_204') | float(0),
          states('sensor.esp_monitor_cells_voltage_205') | float(0),
          states('sensor.esp_monitor_cells_voltage_206') | float(0),
          states('sensor.esp_monitor_cells_voltage_207') | float(0),
          states('sensor.esp_monitor_cells_voltage_208') | float(0),
          states('sensor.esp_monitor_cells_voltage_209') | float(0),
          states('sensor.esp_monitor_cells_voltage_210') | float(0),
          states('sensor.esp_monitor_cells_voltage_211') | float(0),
          states('sensor.esp_monitor_cells_voltage_212') | float(0),
          states('sensor.esp_monitor_cells_voltage_213') | float(0),
          states('sensor.esp_monitor_cells_voltage_214') | float(0),
          states('sensor.esp_monitor_cells_voltage_215') | float(0)
         ] %}
         {% set max_voltage = voltages | max %}
         {% set max_cell = voltages.index(max_voltage) + 1 %}
         {% set min_voltage = voltages | min %}
         {% set min_cell = voltages.index(min_voltage) + 1 %}
         {% set delta = max_voltage - min_voltage %}
        attributes:
            Maximum_Cell_No: "{{ max_cell }}"
            Maximum_Cell_Voltage: "{{ '%.3f' | format(max_voltage) }}"
            Lowest_Cell_No: "{{ min_cell }}"
            Lowest_Cell_Voltage: "{{ '%.3f' | format(min_voltage) }}"
            Voltage_Delta: "{{ '%.3f' | format(delta) }}"

Depends on the specific BMS but would it not be easier to pull all the battery data from the BMS? That’s what I do with my 3 packs.