mysmarthome/packages/holidays.yaml

120 lines
5.4 KiB
YAML
Raw Permalink Normal View History

2019-04-17 22:46:06 +00:00
###############################################################################
# @author : Mahasri Kalavala
# @date : 10/28/2017
# @package : Holidays
# @description : Retrieves the holiday
###############################################################################
homeassistant:
customize:
sensor.holiday:
hidden: true
icon: mdi:beach
friendly_name: US Holiday
###############################################################################
# Sensor updates once every 4 hours (14400 seconds) & runs 6 times in 24 hours
2019-12-20 15:32:28 +00:00
#
# First it checks for holiday in static section, if that doesn't exist,
2019-04-17 22:46:06 +00:00
# it checks in the dynamic section. If neither exists, the value will be empty
###############################################################################
sensor:
- platform: rest
2019-05-18 20:19:22 +00:00
resource: https://raw.githubusercontent.com/skalavala/mysmarthome/master/holidays.json
2019-04-17 22:46:06 +00:00
name: Holiday
scan_interval: 14400
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 }}
###############################################################################
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:
- alias: Notify Holiday State Change
initial_state: true
trigger:
- platform: state
entity_id: sensor.holiday
condition:
- condition: template
value_template: "{{ states('sensor.holiday') != 'unknown' }}"
2021-03-22 01:56:34 +00:00
- condition: template
value_template: "{{ states('sensor.holiday') != 'unavailable' }}"
2019-04-17 22:46:06 +00:00
- condition: template
2019-12-20 15:32:28 +00:00
value_template: "{{ states('sensor.holiday') | trim != '' }}"
2019-04-17 22:46:06 +00:00
action:
- service: persistent_notification.create
data:
2019-12-20 15:32:28 +00:00
message: "Today is {{ states('sensor.holiday') }}."
title: "{{ states('sensor.holiday') }}"
2022-12-03 16:28:12 +00:00
- service: script.notify_family
2022-12-05 00:02:34 +00:00
data:
2019-12-20 15:32:28 +00:00
message: "Today is: {{states('sensor.holiday') }}"
2022-12-03 16:28:12 +00:00
notify_options:
- telegram
- tv
- led
2019-04-17 22:46:06 +00:00
- alias: Notify Indian Holidays
initial_state: true
trigger:
platform: time
2019-12-20 15:32:28 +00:00
at: "09:00:00"
2019-04-17 22:46:06 +00:00
condition:
- condition: template
value_template: >-
{%- set days2NextEvent = 0 -%}
{%- if now().year == strptime(states.calendar.holidays_in_india.attributes.start_time, '%Y-%m-%d %H:%M:%S').year -%}
{%- set days2NextEvent = strptime(states.calendar.holidays_in_india.attributes.start_time, '%Y-%m-%d %H:%M:%S').strftime('%j') | int - (now().strftime('%j') | int) -%}
{%- else -%}
2019-12-20 15:32:28 +00:00
{% set days2NextEvent = strptime((now().year ~ "-12-31 12:02:05"), '%Y-%m-%d %H:%M:%S').strftime('%j') | int - (now().strftime('%j') | int) + (strptime(states.calendar.holidays_in_india.attributes.start_time, '%Y-%m-%d %H:%M:%S').strftime('%j') | int) -%}
{%- endif -%}
{%- if days2NextEvent <= (states('input_number.calendar_remind_before_days') | int) -%}
2019-04-17 22:46:06 +00:00
{%- if days2NextEvent |int == 0 -%}
true
{%- elif days2NextEvent | int == 1 -%}
true
{%- elif days2NextEvent | int == 2 -%}
true
{%- else -%}
false
{%- endif -%}
{%- else -%}
false
{%- endif -%}
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: >-
2019-12-20 15:32:28 +00:00
{%- set days2NextEvent = 0 -%}
{%- if now().year == strptime(states.calendar.holidays_in_india.attributes.start_time, '%Y-%m-%d %H:%M:%S').year -%}
{%- set days2NextEvent = strptime(states.calendar.holidays_in_india.attributes.start_time, '%Y-%m-%d %H:%M:%S').strftime('%j') | int - (now().strftime('%j') | int) -%}
{%- else -%}
{% set days2NextEvent = strptime((now().year ~ "-12-31 12:02:05"), '%Y-%m-%d %H:%M:%S').strftime('%j') | int - (now().strftime('%j') | int) + (strptime(states.calendar.holidays_in_india.attributes.start_time, '%Y-%m-%d %H:%M:%S').strftime('%j') | int) -%}
{%- endif -%}
{%- if days2NextEvent <= (states('input_number.calendar_remind_before_days') | int) -%}
{%- if days2NextEvent |int == 0 -%}
Today is {{ states.calendar.holidays_in_india.attributes.message | replace(".", "") | title }}.
{%- elif days2NextEvent |int == 1 -%}
Tomorrow is {{ states.calendar.holidays_in_india.attributes.message | replace(".", "") | title }}.
{%- elif days2NextEvent |int == 2 -%}
{{ states.calendar.holidays_in_india.attributes.message | replace(".", "") | title }}. is day after tomorrow.
{%- endif -%}
{%- endif -%}
2022-12-03 16:28:12 +00:00
notify_options:
- telegram
- tv
- led