Help with variable

Hello, I made a bed sensor and the sensor count how many hours and now many min I slept, I want to show the stats from last week, I want to know how long I slept every night so I used variable to start but I have few problmes, this is the script for variable

service: variable.set_variable
data:
  variable: noy_sleep_record
  attributes:
    history_1: "{{states('variable.noy_sleep_record')}}"
    history_2: "{{state_attr('variable.noy_sleep_record','history_1')}}"
    history_3: "{{state_attr('variable.noy_sleep_record','history_2')}}"
    history_4: "{{state_attr('variable.noy_sleep_record','history_3')}}"
    history_5: "{{state_attr('variable.noy_sleep_record','history_4')}}"
    history_6: "{{state_attr('variable.noy_sleep_record','history_5')}}"
    history_7: "{{state_attr('variable.noy_sleep_record','history_6')}}"
data_template:
  value: |+
    {{ states('sensor.sh_vt_shynh_nvy')}}

the first problem its the template show me Integer value and not time value with 60min
like this pic


how can I convert this ?
and I have bigger problem with the script ,
when I run the script if the value its 9 sleep hours so I click run the script and its just put the new value to state but not in to history , like here
here we see what happend after run the script, the new value go to state and not to history
1

for to see the new state in history I need to run 2 times the script but then I have false state for last day,
2

I hope I explained myself properly
Thank you