# Calculate break even date as tempalte

Hello,
I would like to calculate the break even point of my solar system using template, so I can (nearly) know when my investment will pay off. I have an input helper that keeps track of how much I have earned with the solar system, another that stores how much I spend on the system.

``````template:
- sensor:
- name: "PV Break Even"
unique_id: pv_break_even
unit_of_measurement: "time"
state: >
{% set income = states('input_number.pv_amortisierung') | int %}
{% set costs = states('input_number.pv_gestehungskosten') | imt %}
{% set dayssinceinstallation= ((as_timestamp(now()) - as_timestamp(strptime("28.06.2023", "%d.%m.%Y")) ) / 86400 ) | round(default=0) %}
{{ (as_timestamp(strptime("28.06.2023", "%d.%m.%Y")) + (states((costs / (income / dayssinceinstallation))) * (24*3600))) | timestamp_custom("%d.%m.%Y") }}

``````

so basically I want to calculate how much I have earned per pay on average and devide how much I spend on the system by this average income per day. This should give me the number of days it will take for my investment to pay off. Next step is to to add this number to the date I have installed the solar system. It seems that this last step does not work.
What am I doing wrong?

after a lot of try and error I got it to work.
In case someone tries the same, here is what worked for me:

``````template:
- trigger:
- platform: time
at: "04:30:00"
sensor:
- name: "PV Break Even"
unique_id: pv_break_even
state: >
{% set income = states('input_number.pv_amortisierung') | float %}
{% set costs = states('input_number.pv_gestehungskosten') | float %}
{% set dayssinceinstallation = ((as_timestamp(now()) - as_timestamp(strptime("28.06.2023", "%d.%m.%Y")) ) / 86400 ) | round(10) %}
{{ (as_timestamp(strptime("28.06.2023", "%d.%m.%Y")) + ((costs  / (income / dayssinceinstallation)) * (24*3600) )) | timestamp_custom("%d.%m.%Y") }}

``````

yes, I know this is a very basic break even calculation and the outcome will change drastically especially in winter and sommer, but itâ€™s ok for me

``````template:
- sensor:
- name: "PV Break Even Date"
unique_id: pv_break_even_date
state: >
{% set income = states('input_number.pv_amortisierung') | int %}
{% set costs = states('input_number.pv_gestehungskosten') | int %}
{% set days = (today_at() - strptime("28.06.2023", "%d.%m.%Y") | as_local).days %}
{% set daily = income / days %}
{% set total_days = (costs / daily)|int %}
{% set remaining_days = total_days - days %}
{{ (today_at() + timedelta(days=remaining_days)).date() }}
``````

this is much cleaner
Thank you