Hi Rodrigo_Baiao,
Your repeat loop is a different scope than your outer variables,.
You lost scope.
You will need a namespace to pull stuff out, or use a helper to store the variable, or something like this:
Trigger based template sensor to store global variables.