2018-01-02 00:00:45 +00:00
###############################################################################
# @author : Mahasri Kalavala
# @date : 10/28/2017
# @package : Holidays
# @description : Retrieves the holiday
###############################################################################
2019-02-22 19:55:09 +00:00
#-------------------------------------------
# Holiday Package
# @CCOSTAN
# Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# Video Breakdown - https://www.vcloudinfo.com/2019/02/breaking-down-the-flag-sensor-in-home-assistant.html
#-------------------------------------------
2018-01-02 00:00:45 +00:00
## Modified for my own fun stuff!
homeassistant :
customize :
sensor.holiday :
hidden : true
icon : mdi:beach
friendly_name : US Holiday
sensor.flag :
hidden : true
icon : mdi:flag
friendly_name : Flag Day
###############################################################################
# Sensor updates once every 4 hours (14400 seconds) & runs 6 times in 24 hours
#
# First it checks for holiday in static section, if that doesn't exist,
# it checks in the dynamic section. If neither exists, the value will be empty
###############################################################################
sensor :
- platform : rest
2018-03-01 01:00:44 +00:00
resource : https://raw.githubusercontent.com/CCOSTAN/Home-AssistantConfig/master/config/json_data/holidays.json
2018-01-02 00:00:45 +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-02-22 19:55:09 +00:00
################################################################################
# Sensor Uses Flag data from this calendar - http://www.webcal.fi/en-US/flag_days.php
################################################################################
2019-01-10 20:32:07 +00:00
- platform : rest
2019-10-10 04:39:10 +00:00
resource : https://www.webcal.fi/cal.php?id=335&format=json&start_year=current_year&end_year=current_year&tz=America%2FNew_York
2019-01-10 20:32:07 +00:00
name : Flag
scan_interval : 14400
value_template : >-
{%- set now_string = now().strftime('%Y-%m-%d') %}
{% for day_val in value_json if day_val.date == now_string %}
True
{% else %}
False
{% endfor -%}
2018-01-02 00:00:45 +00:00
2019-10-06 18:00:44 +00:00
################################################################################
# Countdown Sesor using WolfRam Alpha Natural language queries
################################################################################
2019-10-21 22:17:21 +00:00
#
# - platform: command_line
# name: Halloween Countdown
# command: "HALLOWEEN=`date -d 'Oct 31' +%j | awk '{print $1 + 0}'`; TODAY=`date +%j | awk '{print $1 + 0}'`; DAYS=$(($HALLOWEEN - $TODAY)); echo $DAYS"
# scan_interval: 43200
#
# - platform: command_line
# command: "XMAS=`date -d 'Dec 25' +%j | awk '{print $1 + 0}'`; TODAY=`date +%j | awk '{print $1 + 0}'`; DAYS=$(($XMAS - $TODAY)); echo $DAYS"
# name: Christmas Countdown
# scan_interval: 43200
2019-10-06 18:00:44 +00:00
2019-10-21 22:17:21 +00:00
- platform : rest
2019-10-06 18:00:44 +00:00
name : Halloween Countdown
2019-10-21 22:17:21 +00:00
resource : !secret wolframalpha_halloween_api
value_template : "{{ (value|replace(' days', '')) | int }}"
2019-10-06 18:00:44 +00:00
unit_of_measurement : Days
scan_interval : 43200
2019-10-21 22:17:21 +00:00
- platform : rest
2019-11-16 00:16:23 +00:00
name : Christmas Countdown
2019-10-21 22:17:21 +00:00
resource : !secret wolframalpha_xmas_api
value_template : "{{ (value|replace(' days', '')) | int }}"
unit_of_measurement : Days
2019-10-06 18:00:44 +00:00
scan_interval : 43200
- platform : rest
name : Easter Countdown
resource : !secret wolframalpha_easter_api
value_template : "{{ (value|replace(' days', '')) | int }}"
unit_of_measurement : Days
scan_interval : 43200
- platform : rest
name : Mother's Day Countdown
resource : !secret wolframalpha_mothersday_api
value_template : "{{ (value|replace(' days', '')) | int }}"
2019-10-06 18:18:00 +00:00
unit_of_measurement : Days
scan_interval : 43200
- platform : rest
name : Father's Day Countdown
resource : !secret wolframalpha_fathersday_api
value_template : "{{ (value|replace(' days', '')) | int }}"
2019-10-21 21:33:31 +00:00
unit_of_measurement : Days
scan_interval : 43200
- platform : rest
name : Chanukkah Countdown
resource : !secret wolframalpha_chanukkah_api
value_template : "{{ (value|replace(' days', '')) | int }}"
2019-10-06 18:00:44 +00:00
unit_of_measurement : Days
scan_interval : 43200
2020-02-15 23:52:58 +00:00
- platform : rest
name : Labor Day Countdown
resource : !secret wolframalpha_labor_api
value_template : "{{ (value|replace(' days', '')) | int }}"
unit_of_measurement : Days
scan_interval : 43200
- platform : rest
name : Memorial Day Countdown
resource : !secret wolframalpha_memorial_api
value_template : "{{ (value|replace(' days', '')) | int }}"
unit_of_measurement : Days
scan_interval : 43200
- platform : rest
name : Thanksgiving Day Countdown
resource : !secret wolframalpha_thanksgiving_api
value_template : "{{ (value|replace(' days', '')) | int }}"
unit_of_measurement : Days
scan_interval : 43200
2018-01-02 00:00:45 +00:00
###############################################################################
# Automation that notifies of a Holiday "state" change
###############################################################################
automation :
- alias : Notify Holiday State Change
2020-02-15 23:52:58 +00:00
2018-01-02 00:00:45 +00:00
initial_state : true
trigger :
- platform : state
entity_id :
- sensor.holiday
condition :
- condition : template
value_template : "{{ states('sensor.holiday') != 'unknown' }}"
- condition : template
value_template : "{{ states.sensor.holiday.state | trim != '' }}"
action :
- service : persistent_notification.create
data :
message : 'Today is {{ states.sensor.holiday.state }}.'
title : '{{ states.sensor.holiday.state }}'
2018-06-14 19:33:39 +00:00
- delay : '0{{ (range(4, 8)|random|int) }}:{{ range(0,5) | random | int }}{{ range(0,9) | random | int }}:{{ range(0,5) | random | int }}{{ range(0,9) | random | int }}'
2018-03-18 01:14:50 +00:00
- service : script.tweet_engine_image
2018-01-02 00:00:45 +00:00
data_template :
tweet : >
{{ [
"Today is {{ states.sensor.holiday.state }}. Time to adjust the outside light colors!" ,
"Today is {{ states.sensor.holiday.state }}." ,
"Is today {{ states.sensor.holiday.state }}?" ,
"Just checked with Alexa & today is {{ states.sensor.holiday.state }}."
] | random + [
" #DayOff" ,
2019-10-10 04:39:10 +00:00
"(https://www.vmwareinfo.com/2017/07/my-smart-home-look-at-parts-that-make.html)" ,
"(https://www.vmwareinfo.com/2017/08/diy-outdoor-smart-home-led-strips.html)" ,
2019-02-19 06:17:07 +00:00
"https://www.vcloudinfo.com/2019/02/everyday-holiday-smart-lights-valentines-day-edition.html)" ,
2018-01-02 00:00:45 +00:00
"#{{ states.sensor.holiday.state }}"
] | random }}
2018-03-18 01:14:50 +00:00
image : >-
{{ [
"/config/www/custom_ui/floorplan/images/branding/light4.png"
] | random }}