Template shows up and works in "Template" developer tools but is not available in the GUI to add to dashboard

I have written the following template which works under developer tools and calculates fine but once added to the config.YAML file (indented correctly) it does not show up as an avaialble entity. Can anyone help . Note that the first example below IS working and the entity DOES show up in the GUI

I should add that when I include both of these template sensors in the YAML file the second one stops the first from showing up in the GUI. If I delete the second one from the YAML file, the first then reappears in the GUI. Very odd!!

First example that is available in GUI

 - name: Energy Cost Per Hour
      unit_of_measurement: "GBP"
      state_class: total_increasing
      device_class: energy
      state: "{{ (states('sensor.smart_meter_electricity_power') | float * states('sensor.smart_meter_electricity_import_unit_rate') | float) | round(2) }}"

Second example that isnt available. Not sure why!!

- name: Energy Cost Per Week + Standing Charge
      unique_id: Cost Per Week
      unit_of_measurement: "GBP"
      state_class: total_increasing
      device_class: energy
      value_template: > 
          {% set start_of_week = now().replace(hour=0, minute=0, second=0) - timedelta(days=now().weekday()) %}
          {% set days_since_start_of_week = now().weekday() + 1 %}
          {% set entity1_value = (states('sensor.smart_meter_electricity_import_this_week') | float * states('sensor.smart_meter_electricity_import_unit_rate') | float) | float | round(2) %}
          {% set entity2_value = (states('sensor.smart_meter_electricity_import_standing_charge') | float) | round(2) %}
          {{ entity1_value + ((entity2_value * days_since_start_of_week) | float) | round(2) }}

Your second example is using the incorrect key value_template, for template sensors configured under the template integration it should be state.

Thanks all sorted now.