Python_script for countdown to birthdays/anniversaries/significant dates

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.

have you got

nextOccur = datetime.date(thisYear , dateMonth , dateDay)

in the python script

and did you add to the hass.states.set()

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

you need to add it to the hass.state.set()

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

that should work as it a string but if not

    "original_date" : "{}/{}/{}".format(dateStr.day,dateStr.month,dateStr.year) ,

still get head aound this python

I think the time format could be wrong did you try

'10:00:00'

I did add it to the hass.state.set(), as shown above.
Why wouldn’t it be possible to simply use the dateStr, or date?

I’ ve also tried your bottom suggestion but that won’t work, and renders None-None-None :wink: But, that’s already progress, and the system stays alive.

I’ve changed it into:

    "original_date" : "{}-{}-{}".format(dateDay,dateMonth,dateYear)

and hurray, I see the original dates in the sensors attributes! At last.
Don’t understand why, but it works for now, so thats really nice, thanks for helping me out!

I leaning Python so im wing it

but what I do know
is we are playing with a String and and datetime value which are differance

also
id you did this

"original_date" : "{}".Format(dateStr) ,

mite of fix your problem

good to see you got it working

1 Like

Thanks for the reply StePhan. No I didn’t. The format I put was from the example so figured it was right.

Thanks.

JR

just for reference, this is what I ended up with now:

hass.states.set(sensorName , numberOfDays ,
  {
    #"icon" : "mdi:calendar-star" ,
    "entity_picture": "/local/family/{}.jpg".format(name.lower()),
    "unit_of_measurement": "days",
    "friendly_name": "{} turning {} in:".format(name, years),
    "persoon": name,
    "type": "{}".format(type.title()),
    "years": years,
    "original_date" : "{}-{}-{}".format(dateDay,dateMonth,dateYear)
  }
)

so I can use a decluttering template:

card:
  type: 'custom:secondaryinfo-entity-row'
  entity: '[[entity]]'
  secondary_info: '[[ {entity}.attributes.type ]]: [[ {entity}.attributes.original_date ]]'

and card config:

type: entities
style: |
  ha-card {
    background: url('/local/images/party.png');
    background-size: cover;
    background-color: var(--paper-card-background-color);
  }
title: Celebrations
show_header_toggle: false
entities:
  - type: custom:decluttering-card
    template: event_date
    variables:
      - entity: sensor.event1

  - type: custom:decluttering-card
    template: event_date
    variables:
      - entity: sensor.event2

  - type: custom:decluttering-card
    template: event_date
    variables:
      - entity: sensor.event3

  - type: custom:decluttering-card
    template: event_date
    variables:
      - entity: sensor.event4

etcetc

nice.

1 Like

Version 3 is now in HACS - adds the ability to use a future date and only uses the apostrophe for birthdays.

HI Marc,
do you have it on a GitHub repo also? Don’t use HACS.

Yes sir…

1 Like