| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 | # Callback script when anyone presses «Send SMS».script:  birthday_wishes:    mode: parallel    sequence:      - variables:          blang: "{{ lang if lang is defined else none }}"          bname: "{{ name|lower|title }}"          bage: "{{ age|string + {1: 'st', 2: 'nd', 3: 'rd'}.get(4 if 10 <= age|int % 100 < 20 else age|int % 10, 'th') }}"            - service: "{{ notify_device }}"        data:          message: command_activity          data:            intent_action: "android.intent.action.SENDTO"            intent_uri: >-              sms:{{ number }}?body={{-                "🎼 «Hurra for deg som fyller ditt år, ja - deg vil jeg gratulere» 🎶 🎉 \n\n"              }}{%- if blang == 'no_nb' -%}                Gratulere med {{ age|default('') }}årsdagen, {{ bname }}! 🎂🎁 Håpe du får en fin dag 🥳                {%- else -%}                Happy {{ bage ~ ' ' if age else '' }}birthday, {{ bname }}! 🎂🎁 Hope'll get a beautiful day 🥳              {%- endif -%}# Require: https://github.com/jmgiaever/home-assistant-public-config/blob/master/General/notify_device.yamlautomation:  - alias: "Birthday: Notify on birthday!"    trigger:       - platform: calendar        event: start        entity_id: calendar.ical_birthdays        offset:          hours: 10    action:       - variables:          birthdays: >-            {% set birthday = namespace(calendars=[]) %}            {% for ical in integration_entities('ical') if               ical.startswith('sensor.ical_birthdays_event') and not is_state(ical, 'unavailable') and               state_attr(ical, 'start').strftime('%d%m%y') == now().strftime('%d%m%y')             %}               {% set birthday.calendars = birthday.calendars + [ ical ] %}            {% endfor %}            {{ birthday.calendars }}          rexp_phone: '(?:(?<=phone)|(?<=\d,)):?\s?(\+?\d[ \d]+\d)'          rexp_born: '.*?born:?\s*([\d]{2,4})'          rexp_lang: '.*?lang:?\s*([a-zA-Z\_]+)'          langs:            no_nb: '+47'          notify_devices: >-            {{ state_attr('group.owners_notify_devices', 'entity_id')|list }}      - repeat:          for_each: "{{ birthdays }}"          sequence:            - variables:                name: "{{ (states(repeat.item).split('-')[:-1]|join('-')|trim).split(' ')[0]|lower|title }}"                details: '{{ state_attr(repeat.item, "description")|striptags }}'                phones: >-                  {{ details|regex_findall(rexp_phone, ignorecase=true) }}                born: >-                  {{ details|regex_findall_index(rexp_born, ignorecase=true) if                    details is match(rexp_born, ignorecase=true) else                  false }}                lang: >-                  {% set lang = namespace(lang=false) %}                  {% set lang.lang = details|regex_findall_index(rexp_lang, ignorecase=true) if                    details is match(rexp_lang, ignorecase=true) else                    False                  %}                  {% if lang.lang is false %}                    {% for klang in langs.keys() %}                      {% for phone in phones if phone.startswith(langs[klang]) %}                        {% set lang.lang = klang %}                      {% endfor %}                    {% endfor %}                  {% endif %}                  {{ lang.lang if lang.lang else 'eng' }}                age: >-                  {{ false if born is false else                    100 + now().strftime('%y')|int - born if born <= 100 else                    now().strftime('%Y')|int - born|int                  }}                index: "{{ repeat.index }}"                data:                  title: "It is {{ name }}'s birthday. 🎁"                  message: >-                    {% if age is not false %}                      {{ name }} is turning {{ age }} today.                    {% else %}                      {{ name }} is getting one year older today.                    {% endif %}                    Send your congratulations 🎉 to let him/her                    know that you appreciate them. 🥳                  data:                    actions:                      - action: SEND_SMS                        title: Send SMS 💌                      - action: DISMISS                        title: Dismiss 💩                    color: '#ebb1bb'                    group: "birthday-notifications"                    channel: "Birthdays"                    importance: high                    icon_url: /local/icons/notifications/cake.png                    notification_icon: "mdi:cake"                              - repeat:                for_each: "{{ notify_devices }}"                sequence:                  service: script.turn_on                  target:                    entity_id: script.notify_device                  data:                    variables:                      notify_device: "{{ repeat.item }}"                      index: "{{ index }}-{{ repeat.index }}"                      timeout:                        hours: 14                      data: "{{ data }}"                      action_scripts: # Callback handles for «data.actions»                        SEND_SMS:                          script: script.birthday_wishes                          variables:                            lang: "{{ lang }}"                            name: "{{ name }}"                            age: "{{ age }}"                            notify_device: "{{ repeat.item }}"                            number: "{{ phones|join(',') }}"
 |