Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: a sensor that returns ALL birthdays that occur today #162

Open
zivgin opened this issue Aug 3, 2024 · 0 comments
Open

Comments

@zivgin
Copy link

zivgin commented Aug 3, 2024

A sensor that returns a list of all the entities that have birthday today with their age (maybe as attributes?)

That way, we can create an automation that only "listen" to this sensor

I've created my own:

{# Global Parameters #}
{% set debug_mode = False %} {# Set debug mode on (True) or off (False) #}
{% set debug_date = '2023-11-1' %} {# Date to simulate as today's date when debug mode is on #}

{# Find all sensors #}
{% set all_sensors = states.sensor | list %}

{# Filter sensors for Anniversaries integration #}
{% set anniversary_sensors = all_sensors | selectattr('entity_id', 'search', 'anniversary') | list %}

{# Get today's date or simulated date in debug mode #}
{% if debug_mode %}
  {% set today = strptime(debug_date, '%Y-%m-%d').date() %}
{% else %}
  {% set today = now().date() %}
{% endif %}

{# List filtered sensors with their friendly name, birthday, and age if the birthday matches today's date #}
{# Anniversary Sensors: #}
{% for sensor in anniversary_sensors %}
  {% set birthday_date = sensor.attributes.date %}
  {% if birthday_date.month == today.month and birthday_date.day == today.day %}
    {% set friendly_name = sensor.attributes.friendly_name | replace('birthday', '') | replace('Birthday', '') | replace('BIRTHDAY', '') | trim %}
    {% set current_age = sensor.attributes.current_years %}
    Name: {{ friendly_name }}
    Date of Birthday: {{ birthday_date.strftime('%Y-%m-%d') }}
    Age: {{ current_age }}
  {% endif %}
{% endfor %}

but it's not comfortable and i would rather have something from the "inside" of the integration.
(Ignore the top global parameters, it's just for debugging)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant