Multiple sensors but share same template?

Since the electricity prices are quite insane (mostly), my idea is to have a couple of sensors that summarizes the cost for the upcoming night (sunset to sunrise) and based on that have automations that triggers the lightning (for instance, I will skip outdoor lights if expensive, or indoor lights if no one is home etc).

I´ve managed (hopefully somewhat correct) to fetch the values from the Nordpool integration available in HACS with a template like this:

{% set sunset_hour = state_attr('sun.sun', 'next_dusk')[11:13] | int %}
{% set sunrise_hour = state_attr('sun.sun', 'next_dawn')[11:13] | int %}

{% set ns_bm = namespace(cost_until_midnight = 0) %} 
{% for current_hour in range(sunset_hour, 24) %}
{% set hour_cost = state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'today')[current_hour] %}
{% set ns_bm.cost_until_midnight = ns_bm.cost_until_midnight + hour_cost %}
{% endfor %}

{% set ns_am = namespace(cost_after_midnight = 0) %} 
{% for current_hour in range(0, sunrise_hour) %}
{% set hour_cost = state_attr('sensor.nordpool_kwh_se4_sek_3_095_025', 'tomorrow')[current_hour] %}
{% set ns_am.cost_after_midnight = ns_am.cost_after_midnight + hour_cost %}
{% endfor %}

{% set total_cost = ns_bm.cost_until_midnight  + ns_am.cost_after_midnight %}
{% set total_hours = (24 - sunset_hour) + sunrise_hour %}
{% set average_cost = (total_cost / total_hours) | round(3) %}

{% set cheap_night = false %}
{% if average_cost < 1 %}
{% set cheap_night = true %}
{% endif %}

Hours between sunset and sunrise: {{ total_hours }}
Total cost for 1kwh: {{ total_cost }} kr
Average cost for 1kwh/hour: {{ average_cost }} kr
Cheap price during the night: {{ cheap_night }}```

Now I want some sensors based on this, at least a binary sensor for cheap_night (less than 1SEK/kWh on average) and also the average_cost would be nice. I don´t want to have this script on two different sensors though, that is a nightmare to administer.

Any ideas on how to share a template between multiple sensors? I´ve read some old threads about hooks, but not sure ig it can be applied here?

This is the only sensor I utilize right now:

template:
  - binary_sensor:
      - name: "Nordpool.CheapElectricityDuringNight"
        state: >
            *Script from above*