Python_script for countdown to birthdays/anniversaries/significant dates

GOT working
log to hard to read. did something thinking

  {
    "icon" : "mdi:calendar-star" ,
    "unit_of_measurement" : "days" ,
    "friendly_name" : "{}'s {}".format(name, type) ,
    "nextoccur" : "{}/{}/{}".format(nextOccur.day,nextOccur.month,nextOccur.year) ,
    "years" : years
  }

had to use the .format()

hay you guys who like the month first just change the format

"nextoccur" : "{}/{}/{}".format(nextOccur.month,nextOccur.day,nextOccur.year) ,

now I can

entities:
  - entity: sensor.anniversary_our_wedding
    secondary_info: ' [[ {entity}.attributes.nextoccur ]]  ( [[ {entity}.attributes.years ]] Years )'
    type: 'custom:secondaryinfo-entity-row'
show_header_toggle: false
title: Our Events
type: entities

image

1 Like

I like that, I’ll update the version on HACS to include it when I get a minute at the laptop. Nice idea, thanks :smiley:

2 Likes

cool thanks

next brain fart

build a custom card so you only have to add the event_id and the sec line just shows up

1 Like

Added the update to HACS with a note about how to add the extra info to a lovelace card (crediting you :slight_smile: )

I wouldn’t know where to start writing a custom card, but if anyone wants to that would be great :smiley:

1 Like

thanks bro

What’s this called in the HACS store? Can’t seem to find it.

Date countdown - should be the first one in the list…

1 Like

Thank you so much for including a picture! My HACS doesn’t show that category. Will need to research.

1 Like

Is this a different store than the Add On store? I do not see this option. Obviously easy enough to manually set this up but does the above if I can find it create the right folders and install the python script in it?

Thanks.

JR

I needed to edit my configuration file to include additional sections

hacs:
  token: !secret github_token
  appdaemon: True
  python_script: True
  theme: True

yes, it’s different.

you have to install it.

Thanks done. Any idea why this shows up twice in the store?

There was a thread on that somewhere but I don’t remember why there are two off the top of my head. But I do remember the bottom line was “just ignore the other one”.

OK good to go. Very cool. So right now I have sensors showing how long until each birthday. In the states and make the changes above so the time until each birthday comes out right, but in states in developer tools the sensor shows the value for nextoccur: M/D/YYYY. Is this OK? Assume it’s still storing it the original way and I need to reformat it on screen?

Thanks.

JR

I don’t think I understand hat exactly you are asking about.

1 Like

been having a related wish, namely to show the original date of the festivities in the sensor’s attributes, so I can set that in the secondary_info:

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,
    "date": dateStr
  }

won’t give me the date though, but errors out on:

which is probably nothing, since it cant run stand alone, and needs a config with a sensor. (errors out without the extra line also, so I noticed now)

2019-11-12 15:23:48 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.2931960368] Unable to serialize to JSON: Object of type date is not JSON serializable

seems to be the true issue… hanging instance again…
Running this though prevents my HA instance from loading at all, so I deleted it quickly :wink:

What would I need to use , simply to get the date from the config in the sensors attributes?
preferably even, using date so I can change the order to day/month/year

tried it with

    "datum" : date

also. No difference, running the updating automation errors out and hangs the full system…

I love this script, just one issue/question. The countdown to people’s events is great. I also setup to be notified of the events in 7 days and left the wait template as:

- wait_template: "{{ states('sensor.time') == '10:00' }}"

Is that supposed to be 10:00 in the morning and what really triggers this? An example entry:

- alias: Reminder - Teresa's birthday is coming up
  trigger:
    - platform: state
      entity_id: sensor.birthday_teresa
      to: '7'
  action:
    - wait_template: "{{ states('sensor.time') == '10:00' }}"
    - service: notify.ios_sueiosapp
      data:
        message: "Teresa's birthday is only a week away!"

Family being family, Sue who is supposed to get this said she didn’t think she received the notice. Not this one, but another one is 7 days today. Everytime I restart HA for various reasons I see a log that

Reminder - Amy’s birthday is coming up has been triggered

Reminder - Refresh date countdown sensors has been triggered

Nothing shows up. If I manually trigger the task she sees it on their phone. I can say nothing in the logbook at 10:00AM.

Thanks.

JR

EDIT: Maybe I missed this but noticed it uses sensor.time which returns unknown as it doesn’t exist. So when I followed https://www.home-assistant.io/integrations/time_date and enabled the sensor it was there. Not sure if it would work still since 10AM is gone but thinking this was needed.

Yeah, it’s just an example, but it uses the 10am wait_template because if you used the previous example of updating your sensors at midnight, then you would also get the notification at midnight. As you say, it requires the time sensor.

anyone on this Python_script for countdown to birthdays/anniversaries/significant dates ?

how to get the original date of the event (which is set in the automation) into the attributes of the sensor?

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,
    "datum": date
  }
)

if I check the main log, it does add the datum to the sensor, but it starts trying serializing the complete HA config… no clue what or why thus is happening at all…

Hi I used your modification but for some reason the nextOcur doesn’t display, in the place of the date i get the text “undefined”. I do get the years in brackets displayed.
As in your example instead of 30/5/2020 i have undefined.
Any idea of what i am missing?
Thanks for your help.