2019-04-17 22:46:06 +00:00
|
|
|
###############################################################################
|
|
|
|
# @author : Mahasri Kalavala
|
|
|
|
# @date : 04/28/2017
|
|
|
|
# @package : Birthday
|
|
|
|
# @description : Birthday reminders, greetings/wishes - all good stuff!
|
|
|
|
#
|
|
|
|
# THREE IMPORTANT THINGS YOU NEED:
|
|
|
|
# 1. Copy birtday_wishes.yaml file from templates folder to your templates folder
|
|
|
|
# 2. Copy this file to Packages folder & add following to configuration.yaml
|
|
|
|
# packages: !include_dir_named packages
|
|
|
|
# 3. Add the following to your secrets.yaml file, change name and date
|
|
|
|
# name_birthday: "MM-DD". See below for example:
|
|
|
|
#
|
|
|
|
# srinika_birthday: "04-01"
|
|
|
|
# hasika_birthday: "07-25"
|
|
|
|
# mallika_birthday: "12-31"
|
|
|
|
#
|
|
|
|
# Update: I added mqtt code to refresh the sensor values dynamically.
|
|
|
|
# The sensor values update on hourly basis.
|
|
|
|
#
|
2019-12-20 15:32:28 +00:00
|
|
|
# PLEASE NOTE THAT THIS PACKAGE USES "DATE" SENSOR. IF YOU SEE THE BIRTHDAY
|
2019-04-17 22:46:06 +00:00
|
|
|
# VALUES AS "NOT SET", YOU NEED TO ADD THE FOLLOWING TO YOUR CONFIGURATION FILE
|
|
|
|
#
|
|
|
|
# sensor:
|
|
|
|
# - platform: time_date
|
|
|
|
# display_options:
|
|
|
|
# - 'time'
|
|
|
|
# - 'date'
|
|
|
|
# - 'date_time'
|
2019-12-20 15:32:28 +00:00
|
|
|
# - 'time_date'
|
2019-04-17 22:46:06 +00:00
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
homeassistant:
|
|
|
|
|
|
|
|
input_label:
|
|
|
|
srinika_birthday:
|
|
|
|
value: !secret srinika_birthday
|
|
|
|
hasika_birthday:
|
|
|
|
value: !secret hasika_birthday
|
|
|
|
mallika_birthday:
|
|
|
|
value: !secret mallika_birthday
|
|
|
|
|
|
|
|
srinika_birthday_days2go:
|
|
|
|
icon: mdi:cake-variant
|
|
|
|
name: Srinika's Birthday
|
|
|
|
hasika_birthday_days2go:
|
|
|
|
icon: mdi:cake-variant
|
|
|
|
name: Hasika's Birthday
|
|
|
|
mallika_birthday_days2go:
|
|
|
|
icon: mdi:cake-variant
|
|
|
|
name: Mallika's Birthday
|
|
|
|
|
|
|
|
###############################################################################
|
2019-12-20 15:32:28 +00:00
|
|
|
# _ _ _
|
|
|
|
# /\ | | | | (_)
|
|
|
|
# / \ _ _| |_ ___ _ __ ___ __ _| |_ _ ___ _ __ ___
|
2019-04-17 22:46:06 +00:00
|
|
|
# / /\ \| | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
|
|
|
|
# / ____ \ |_| | || (_) | | | | | | (_| | |_| | (_) | | | \__ \
|
|
|
|
# /_/ \_\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/
|
2019-12-20 15:32:28 +00:00
|
|
|
#
|
2019-04-17 22:46:06 +00:00
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
automation:
|
2019-12-20 15:32:28 +00:00
|
|
|
###############################################################################
|
|
|
|
# Build the excitement
|
|
|
|
###############################################################################
|
2019-04-17 22:46:06 +00:00
|
|
|
- alias: Birthday Countdown 30 Days
|
|
|
|
initial_state: true
|
|
|
|
trigger:
|
|
|
|
platform: state
|
2019-12-20 15:32:28 +00:00
|
|
|
entity_id:
|
2019-04-17 22:46:06 +00:00
|
|
|
- input_label.srinika_birthday_days2go
|
|
|
|
- input_label.hasika_birthday_days2go
|
|
|
|
- input_label.mallika_birthday_days2go
|
|
|
|
condition:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ trigger.to_state.state | int > 0 and trigger.to_state.state | int < 30 }}"
|
|
|
|
action:
|
2022-12-03 16:28:12 +00:00
|
|
|
- service: script.notify_family
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
message: "{{ trigger.entity_id.split('.')[1].split('_')[0] | title }}'s Birthday is only {{ trigger.to_state.state }} days to go!"
|
2022-12-03 16:28:12 +00:00
|
|
|
notify_options:
|
|
|
|
- telegram
|
|
|
|
- tv
|
|
|
|
- led
|
2019-04-17 22:46:06 +00:00
|
|
|
|
2019-12-20 15:32:28 +00:00
|
|
|
###############################################################################
|
|
|
|
# Celebrate Birthday!!!
|
|
|
|
###############################################################################
|
2019-04-17 22:46:06 +00:00
|
|
|
- alias: Today is the Birthday
|
|
|
|
initial_state: true
|
|
|
|
trigger:
|
|
|
|
platform: state
|
2019-12-20 15:32:28 +00:00
|
|
|
entity_id:
|
2019-04-17 22:46:06 +00:00
|
|
|
- input_label.srinika_birthday_days2go
|
|
|
|
- input_label.hasika_birthday_days2go
|
|
|
|
- input_label.mallika_birthday_days2go
|
|
|
|
condition:
|
|
|
|
- condition: template
|
|
|
|
value_template: "{{ trigger.to_state.state | int == 0 }}"
|
|
|
|
action:
|
2022-12-03 16:28:12 +00:00
|
|
|
- service: script.notify_family
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
message: "Hurray! Today is {{ trigger.entity_id.split('.')[1].split('_')[0] | title }}'s Birthday!"
|
2022-12-03 16:28:12 +00:00
|
|
|
notify_options:
|
|
|
|
- telegram
|
|
|
|
- tv
|
|
|
|
- led
|
|
|
|
- voice
|
2019-04-17 22:46:06 +00:00
|
|
|
|
2019-12-20 15:32:28 +00:00
|
|
|
###############################################################################
|
|
|
|
# Announce Happy Birthday message every hour starting 7 am until 9 PM
|
|
|
|
###############################################################################
|
2019-04-17 22:46:06 +00:00
|
|
|
- alias: Random Birthday Wishes
|
|
|
|
initial_state: true
|
|
|
|
trigger:
|
|
|
|
platform: time_pattern
|
2019-12-20 15:32:28 +00:00
|
|
|
hours: "/1"
|
2019-04-17 22:46:06 +00:00
|
|
|
minutes: 3
|
|
|
|
seconds: 00
|
|
|
|
condition:
|
|
|
|
condition: and
|
|
|
|
conditions:
|
|
|
|
- condition: time
|
2019-12-20 15:32:28 +00:00
|
|
|
after: "07:00:00"
|
|
|
|
before: "21:00:00"
|
2019-04-17 22:46:06 +00:00
|
|
|
- condition: or
|
|
|
|
conditions:
|
|
|
|
- condition: template
|
2019-12-20 15:32:28 +00:00
|
|
|
value_template: "{{ states('input_label.srinika_birthday_days2go') | int == 0 }}"
|
2019-04-17 22:46:06 +00:00
|
|
|
- condition: template
|
2019-12-20 15:32:28 +00:00
|
|
|
value_template: "{{ states('input_label.hasika_birthday_days2go') | int == 0 }}"
|
2019-04-17 22:46:06 +00:00
|
|
|
- condition: template
|
2019-12-20 15:32:28 +00:00
|
|
|
value_template: "{{ states('input_label.mallika_birthday_days2go') | int == 0 }}"
|
2019-04-17 22:46:06 +00:00
|
|
|
action:
|
2022-12-03 16:28:12 +00:00
|
|
|
- service: script.notify_family
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
message: !include ../templates/birthday_wishes.yaml
|
2022-12-03 16:28:12 +00:00
|
|
|
notify_options:
|
|
|
|
- voice
|
|
|
|
- tv
|
|
|
|
- led
|
2019-04-17 22:46:06 +00:00
|
|
|
|
|
|
|
- alias: Update Birthdays
|
|
|
|
initial_state: true
|
|
|
|
trigger:
|
|
|
|
- platform: time_pattern
|
2019-12-20 15:32:28 +00:00
|
|
|
minutes: "/5"
|
2019-04-17 22:46:06 +00:00
|
|
|
seconds: 00
|
|
|
|
- platform: homeassistant
|
|
|
|
event: start
|
|
|
|
condition:
|
|
|
|
- condition: template
|
2019-12-20 15:32:28 +00:00
|
|
|
value_template: "{{ states('input_label.srinika_birthday').split('-') | length > 0 }}"
|
2019-04-17 22:46:06 +00:00
|
|
|
- condition: template
|
2019-12-20 15:32:28 +00:00
|
|
|
value_template: "{{ states('input_label.hasika_birthday').split('-') | length > 0 }}"
|
2019-04-17 22:46:06 +00:00
|
|
|
- condition: template
|
2019-12-20 15:32:28 +00:00
|
|
|
value_template: "{{ states('input_label.mallika_birthday').split('-') | length > 0 }}"
|
2019-04-17 22:46:06 +00:00
|
|
|
action:
|
|
|
|
- service: input_label.set_value
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
entity_id: input_label.srinika_birthday_days2go
|
|
|
|
value: >
|
2019-12-20 15:32:28 +00:00
|
|
|
{% set year = states('sensor.date').split('-')[0] %}
|
|
|
|
{% set month = states('sensor.date').split('-')[1] %}
|
|
|
|
{% set date = states('sensor.date').split('-')[2] %}
|
2019-04-17 22:46:06 +00:00
|
|
|
{% if states('input_label.srinika_birthday') != "unknown" %}
|
2019-12-20 15:32:28 +00:00
|
|
|
{%- set bDayMonth = states('input_label.srinika_birthday').split('-')[0] -%}
|
|
|
|
{%- set bDayDate = states('input_label.srinika_birthday').split('-')[1] -%}
|
2019-04-17 22:46:06 +00:00
|
|
|
{%- set numOfDays = ((as_timestamp(strptime(year ~ '-' ~ bDayMonth ~ '-' ~ bDayDate , '%Y-%m-%d')) | timestamp_custom('%j', true) | int ) - (as_timestamp(strptime(year ~ '-' ~ month~ '-' ~ date , '%Y-%m-%d')) | timestamp_custom('%j', true) | int)) -%}
|
|
|
|
{%- if numOfDays < 0 -%}
|
|
|
|
{{ numOfDays + 365 }}
|
|
|
|
{%- else -%}
|
|
|
|
{{ numOfDays }}
|
|
|
|
{%- endif -%}
|
|
|
|
{% else %}
|
|
|
|
-
|
|
|
|
{% endif %}
|
|
|
|
- service: input_label.set_value
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
entity_id: input_label.hasika_birthday_days2go
|
|
|
|
value: >
|
2019-12-20 15:32:28 +00:00
|
|
|
{% set year = states('sensor.date').split('-')[0] %}
|
|
|
|
{% set month = states('sensor.date').split('-')[1] %}
|
|
|
|
{% set date = states('sensor.date').split('-')[2] %}
|
2019-04-17 22:46:06 +00:00
|
|
|
{% if states('input_label.hasika_birthday') != "unknown" %}
|
2019-12-20 15:32:28 +00:00
|
|
|
{%- set bDayMonth = states('input_label.hasika_birthday').split('-')[0] -%}
|
|
|
|
{%- set bDayDate = states('input_label.hasika_birthday').split('-')[1] -%}
|
2019-04-17 22:46:06 +00:00
|
|
|
{%- set numOfDays = ((as_timestamp(strptime(year ~ '-' ~ bDayMonth ~ '-' ~ bDayDate , '%Y-%m-%d')) | timestamp_custom('%j', true) | int ) - (as_timestamp(strptime(year ~ '-' ~ month~ '-' ~ date , '%Y-%m-%d')) | timestamp_custom('%j', true) | int)) -%}
|
|
|
|
{%- if numOfDays < 0 -%}
|
|
|
|
{{ numOfDays + 365 }}
|
|
|
|
{%- else -%}
|
|
|
|
{{ numOfDays }}
|
|
|
|
{%- endif -%}
|
|
|
|
{% else %}
|
|
|
|
-
|
|
|
|
{% endif %}
|
|
|
|
- service: input_label.set_value
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
entity_id: input_label.mallika_birthday_days2go
|
|
|
|
value: >
|
2019-12-20 15:32:28 +00:00
|
|
|
{% set year = states('sensor.date').split('-')[0] %}
|
|
|
|
{% set month = states('sensor.date').split('-')[1] %}
|
|
|
|
{% set date = states('sensor.date').split('-')[2] %}
|
2019-04-17 22:46:06 +00:00
|
|
|
{% if states('input_label.mallika_birthday') != "unknown" %}
|
2019-12-20 15:32:28 +00:00
|
|
|
{%- set bDayMonth = states('input_label.mallika_birthday').split('-')[0] -%}
|
|
|
|
{%- set bDayDate = states('input_label.mallika_birthday').split('-')[1] -%}
|
2019-04-17 22:46:06 +00:00
|
|
|
{%- set numOfDays = ((as_timestamp(strptime(year ~ '-' ~ bDayMonth ~ '-' ~ bDayDate , '%Y-%m-%d')) | timestamp_custom('%j', true) | int ) - (as_timestamp(strptime(year ~ '-' ~ month~ '-' ~ date , '%Y-%m-%d')) | timestamp_custom('%j', true) | int)) -%}
|
|
|
|
{%- if numOfDays < 0 -%}
|
|
|
|
{{ numOfDays + 365 }}
|
|
|
|
{%- else -%}
|
|
|
|
{{ numOfDays }}
|
|
|
|
{%- endif -%}
|
|
|
|
{% else %}
|
|
|
|
-
|
2019-12-20 15:32:28 +00:00
|
|
|
{% endif %}
|