Total newbie looking for help with python counter

Hi all.

i don’t know if I am asking for to much here so please excuse me if I am.

i’m looking to create a way to keep track of my various contracts in home assistant (mobile phone, car insurance, house insurance, etc). So I have been trying to learn python to do it.

its taken me 2 months i think but here is what I have so far :

import datetime
from dateutil.relativedelta import relativedelta
import math

contract_duration = 36
starting_date =, 10, 15)
days_count = 0
year = 0
month = 0
day = 0
ending_date = starting_date + relativedelta(months=contract_duration)
today =
today1 = today

while ending_date > today1:
    today1 += relativedelta(days=1)
    days_count += 1

if ending_date < today:
    print(f"Your contract was over on {ending_date}")
elif days_count < 31:
    day = days_count
    print(f" Your contract ends in  {day} Days")
elif days_count < 365:
    month = math.floor(days_count / 30)
    day = (days_count - (30 * month))
    print(f"Your contract ends in {month} months and {day} Days")
elif days_count > 365:
    year = math.floor(days_count / 365)
    month = math.floor((days_count - (365 * year)) / 30)
    day = (days_count - ((365 * year) + (30 * month)))
    print(f"Your contract ends in {year} years {month} months and {day} days")

my question,

how do I get Home assistant to see it and how do I get it to read from something I would type into my configuration.yaml file to get the start date data, contract duration data and a name?

I added the print to each part so I could see it working.

can anyone help me? even pointing me in the direction of the info I need to accomplish my goal?

thank you for your help and time

Have you looked at this project? Home Assistant Community Add-on: Grocy Maybe building from some of the entities inside could be a good starting point?

I haven’t, but I’ll give it a look and see how I get on.

Thank you :grin::grin: