looking to know if anyone has found a good sensor or something that can be set to count down to a future date (pref in months and days) untill a future date say 18/24/36 months in the future?
looking to use it to remind me when my subscriptions are due for renewal of things like tv, mobile phone, electricity. etc…
ive had a look around and can find loads that count down in days but nothing in months and days.
sure, some of us use this python script for counting down the days to an anniversary or some other event:
""" This script creates a sensor that a counts down to the next occurrance """
""" of a date, like a birthday or anniversary and gives the number of """
""" years as an attribute """
""" Requires python_script: to be enabled in you configuration """
""" Usage: """
""" """
""" automation: """
""" alias: Refresh John's birthday sensor """
""" trigger: """
""" platform: time """
""" at: '00:00:01' """
""" action: """
""" service: python_script.date_countdown """
""" data: """
""" name: John """
""" type: birthday """
""" date: 17/08/1971 #DD/MM/YYYY """
""" This will create a sensor with entity_id sensor.birthday_john and a """
""" friendly name of 'John's birthday' . The sensors value will be the """
""" number of days until the birthday, and the attribute 'years' will """
""" show how old John will be on his next birthday """
"""https://community.home-assistant.io/t/python-script-for-countdown-to-birthdays-anniversaries-significant-dates/87597"""
today = datetime.datetime.now().date()
name = data.get('name')
type = data.get('type')
sensorName = "sensor.{}_{}".format(type , name.replace(" " , "_"))
dateStr = data.get('date')
dateSplit = dateStr.split("/")
dateDay = int(dateSplit[0])
dateMonth = int(dateSplit[1])
dateYear = int(dateSplit[2])
date = datetime.date(dateYear,dateMonth,dateDay)
thisYear = today.year
nextOccur = datetime.date(thisYear , dateMonth , dateDay)
numberOfDays = 0
years = int(thisYear) - dateYear
if today < nextOccur:
numberOfDays = (nextOccur - today).days
elif today > nextOccur:
nextOccur = datetime.date(thisYear+1 , dateMonth , dateDay)
numberOfDays = int((nextOccur - today).days)
years = years+1
hass.states.set(sensorName , numberOfDays ,
{
#"icon" : "mdi:calendar-star" ,
"entity_picture" : "/local/family/{}.jpg".format(name.lower()),
"unit_of_measurement" : "days" ,
"friendly_name" : "{}'s {} turning ({}) in:".format(name, type, years) ,
"persoon": name,
"type": type,
"years" : years
}
)
If you are using HACS (Home assistant community store) then there are two options. An integration called anniversaries and a python script called countdown. They may fulfill your needs.
thankyou for your comments, I have HACS and use the anniversaries but it counts down in days for a max of a year, and I was hoping to be able to count down in months and days for periods over a year…
IE. I have a 18 month contract that i want to keep track of so i can get a reminder when its due up. I also have 24 month contracts, 16 month contracts … etc… the ideal output would be say “14months and 5 days untill end of contract”.
I have no idea about coding though I have started an online course on python (been told its a good language to learn) in the hope I can figure it out… but also thought i’d ask incase anyone had already found something that would already to what i was looking for .
from the above, i guess it is possible, i just need to work out how… lol
I have a 18 month contract that i want to keep track of
I’m a little curious what the use case would be for this type of information in your home automation platform rather than say something that might be perhaps more suited to this purpose like a personal assistant or calendar program?
After noon on a day it will show as one less day left however. I beleive its due to their being less than 24 hours left in the calculation and it therefore moves to the next lowest number. Works for general tracking though.
i’m terrible for having a reminder pop up on my phone and being busy at that time so swiping it away and then forgetting about it. if I can set up a sensor or something in this then i can have my alexa device remind me on a regular basis (on multiple devices) without having to set multiple instances in a calendar and have it continue ultill i reset the counter for the new contract.
Interesting. I’m often surprised by the things people are using HA for. I actually have a sort of similar thing now that I think about it. I have a cat that needs medication twice a day and I also am terrible for remembering these things. I HA set up to send me notification and TTS announcements when the pill is due and it will keep sending the notifications even if I swipe them away until I actually click the 'Medication Done" button.
It’s pretty simple but it works great and there might be something in here that will help you along with what you are trying to do.
If you roll up your sleeves and study the HACS solution for the python script called countdown, you can accomplish this with 20-25 lines of code. @anon43302295 did a great job of documenting his small python script and if you follow how he did it, then you can create your own script to accomplish exactly what you want/need. Don’t be afraid to play!
Thank you all for your help and direction, I greatly appreciate it.
I think this is going to take me a while… Been trying to learn python, but it’s a slow progress for me… So I’ll work away using what I can find online and the direction in this chat and I know that eventually I’ll work it out. Nothing better that having a goal in mind that you don’t know if it’s even possible… Then having the finished result working in front of you after you’ve put alot of thought in for yourself .
Now that I know it’s possible I can justify to myself the time in trying to learn the basics of coding.
When I get it working I’ll post my results back here for future use.