Template sensor array hour data to 30 minute

I have code to create an array, 24 values 1 for each hour
The starting value af the array depends on the time on that moment.
now I want to adjust the code so it outputs 48 values 1 for each 30 minutes

below the code for the 24 values depending on the day of the week the data in the array changes

{% if now().weekday() == 5 or now().weekday() == 6 %}
            {%- set load_cost = [0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115] %}
          {%- else -%}
            {%- set load_cost = [2,0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.115, 0.115] %}
          {%- endif %}
          {%- set values_all = namespace(all=[]) %}
          {% for i in range(load_cost | length) %}
            {%- set v = load_cost[i] | float %}
            {%- set values_all.all = values_all.all +  [v] %}
          {%- endfor %} {{ (values_all.all)[now().hour:24] + (values_all.all)[0:now().hour] }}

So I want in stead of an output like this
[0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.115, 0.115]

I want this
[0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.115, 0.115, 0.115, 0.115]

Thx in advance

ok, i have to admit, i’m a little confused by the code you have, but here’s a shot at it…

{% if now().weekday() == 5 or now().weekday() == 6 %}
# replace these two arrays with the real numbers you want.
            {%- set load_cost = [0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115] %}
{%- else -%}
            {%- set load_cost = [2,0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.115, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.155, 0.115, 0.115] %}
{%- endif %}
{% set start = now().hour * 2 + (now().minute / 30) | int %}
{{ load_cost[start:48] + load_cost[0:start] }}

as you can see, i took a lot of liberties with it, but since i don’t know what it’s for it may or may not be right… here are thoughts and questions

  1. your two arrays are of different lengths… one’s length 24 and one’s 25. is that intentional? one having that odd “2”… one of these things is not lke the other… but in both cases you only pull 24 elements into your resulting output. so a different number gets tossed from the second array always. is that right?
  2. you create a new namespace object and populate it… only to then spliced and rejoined the copied namespace. is there a reason you built the whole namespace copy? is that needed? if you look at what i did, i just spliced the original w/o doing that namespace stuff and looping.
    2a. if, for some reason, you must have a new namespace, you could eliminate the splice and join by copying over the right namespace element (start copying at the right index into your original array).
  3. note that i didn’t know what the “right” original new array values should be. so i just duplicated the originals. make sure you replace my arrays with the correct ones for your use case.

holler if i made incorrect assumptions…