Happy Birthday!

Here is an automation that send out birthday wishes at 8am. Example message: “Happy 61st Birthday Kenobi!”

alias: 'Happy Birthday Kenobi'
trigger:
  platform: template
  value_template: '{{ now.now().strftime("%b") == "Aug" and now.now().strftime("%-d") == "26" and now.now().strftime("%-H") == "8" }}'
action:
  service: notify.telegramgroup
  data:
    message: >
        {% set age = now.now().strftime("%Y") | int - 1955 %}
        Happy {{ age }}{% if age % 10 == 1 %}st{% elif age % 10 == 2 %}nd{% elif age % 10 == 3 %}rd{% else %}th{% endif %} Birthday Kenobi!
    title: ""
10 Likes

Thanks a lot, It’s really good idea and from now I am using it with tts service. By the way here is a more accurate way to calculate the age.

{% set yearDiff = now().strftime("%Y") | int - 1976 %}
{% set monthDiff = now().strftime("%m") | int - 11 %}
{% set dayDiff = now().strftime("%d") | int - 04 %}

{% if dayDiff < 0 or monthDiff < 0 %}
  {% set age = yearDiff - 1 %}
{% else %}
  {% set age = yearDiff %}
{% endif %}
2 Likes

How can I use it in lovelace ui?

It’s just an automation to send notification

Sorry, wrong topic!
By the way: is the code you posted valid? I also tried to implement the notification but with no effect.

Would be neat to have automations with reminder like that for the whole family

Here is how I’ve done it.

A sensor to detect the day.

Which reads this file (could be hosted locally also with some tweaks to the sensor)

https://github.com/SilvrrGIT/HomeAssistant/blob/master/json_data/days.json

And finally the notification

This was originally @CCOSTAN setup that I copied but found it to work extremely well and easy to add new events.

2 Likes

I may be missing something, but is there a way to define a local resource instead of a link to a github resource?
resource: https://raw.githubusercontent.com/SilvrrGIT/HomeAssistant/master/json_data/days.json

For some reason, I am not grasping that part. Also I would like to duplicate it to make a list of Fun & Wacky Holidays.

The value_template isn’t working anymore and throws an error in HA. Has anyone found an effective replacement for this?

Is there a way to send a push message about tomorrows “celebrations”?

@silvrr . Or anyone else that would have this Holiday/Birthday notification working.

Could anyone point me in the right direction to grab from a local file instead? I am surely not doing this right, but haven’t found anything on the board that could help.

Currently I have a file called holidays.json in my www directory under a subdirectory called DataFiles so: www/DataFiles/holidays.json

I’ve tried several ways to reference it:

  - platform: rest
    resource: http://localhost/DataFiles/holidays.json

and

  - platform: rest
    resources:
    - url: /local/DataFiles/holidays.json
      type: json

But nothing is working, I may not even be using the right platform. Any ideas?

Sorry, I meant to reply to you last time you inquired about this but was on my phone and forgot to follow up.

Assuming your json file follows the same format as the one on my github the below should work.

https://github.com/SilvrrGIT/HomeAssistant/tree/master/json_data

The command works for a hassio install. If you used another install method you may need to tweak that path. Put the days.json file in your config directory (same location as configuration.yaml)

sensor:
  - platform: command_line
    name: holiday_birthday
    command: 'cat /config/days.json'
    value_template: >
      {% set today = now().month  ~ '/' ~ now().day  %}
      {% set holiday =  value_json.MAJOR_US.static[ today ] %}
      {% if holiday | trim == "" %}
        {% set today = now().month  ~ '/' ~ now().day ~ '/' ~ now().year %}
        {% set holiday =  value_json.MAJOR_US.dynamic[ today ] %}
      {% endif %}
      {{ holiday }}
    scan_interval: 43200

I just tested that config with a ‘Test Day’ in my dev instance for today and it worked perfectly.

Great … Thank you very much, will give it a shot today!