Help with birthday automation (optimize code)

Thank you for the code. Very beautiful.
So, should I add all birthdays in a json file?

At the moment, all dates are in a yaml file (using component https://github.com/Miicroo/homeassistant-custom-components/tree/master/birthdays):

birthdays:

  • name: ‘Frodo Baggins’
    date_of_birth: 1921-09-22
  • name: ‘Bilbo Baggins’
    date_of_birth: 1843-09-22
  • name: Elvis
    date_of_birth: 1935-01-08
    icon: ‘mdi:music’

If you choose to use my method than yes. Its up to you.

I started to use this and it works very well for me.
A couple of questions. Is there a database of holidays that you used or a d/l file?
I have attempted to make a card in lovelace but am failing.
Any ideas on how to display a birthday and holiday on my main lovelace page.
Thanks
cwb

I started from someone else’s file and added from there. Most of the holidays I want are in the file. Till 2025 at least.

Thank you for the response.
Would you know or give me a hint on to displaying this in Lovelace?
BTW from your github page looks like you are going to be a father soon.
Congratulations.
cwb

You can add the sensor that is created just the same as any other sensor. On days where there is no birthday, you won’t have anything displayed.

If you are wanting more of a countdown type card, this may be up your alley.

Thanks! We have our second on the way.

Great, worked flawlessly the first time, which says a lot for me and my verrrry poor indentation.
Thanks all
cwb

I followed all the instructions. Created sensor, automation and json file. But sensor.holiday is showing value of unknown. I am running my HassIO under docker of Ubuntu OS VM. Please help

Can you post up your sensor config? and your .json file?


image

What does your error log say?

Im guessing that the file path may be causing the issue.

For hassio /config/data/days.json' works. This means in the main folder where your configuration.yaml file resides, create a data folder and place the days.json file in there.

@silvrr thanks for your help.

Issue was i need to keep it the path as /config/data/days.json and it worked. Now I can see sensor.value = Test Day

Great! Glad you go it working.

Hi all - I have had this up and running for awhile now thanks to @silvrr Github page. My question is can I use {% else %} in some way to have it display None on non holiday/birthday days? I been messing around and cant seem to get it to work. Thank you in advance!

post what you have that’s not working.

I want to do something like this

  - platform: command_line
    name: Holiday
    command: 'cat /config/data/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 ] %}
      {% else %} None
      {% endif %}
      {{ holiday }}
    scan_interval: 14400

Everything but the

      {% else %} None

part is working. Working part of the code is from @silvrr.

try:

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 ] %}
    {% if holiday | trim == "" %}
      {% set holiday =  None %}
    {% endif %}
  {% endif %}
  {{ holiday }}

You might be able to clean up the nested if’s but I have to go do something else right now and can’t do any more with it right now. But this will get you what you want…I think…

has one try the date countdown python script in the HACS

That works great. Thank you.

I havent but I will Google it and check it out. Thanks.