Back Alive!

This commit is contained in:
Mahasri Kalavala
2019-04-17 18:46:06 -04:00
parent 929e0b336e
commit 2a0dd39795
255 changed files with 137143 additions and 0 deletions

111
templates/away_status.yaml Executable file
View File

@@ -0,0 +1,111 @@
>
{% macro weather_update() -%}
Outside temperature is {{ states.sensor.dark_sky_apparent_temperature.state | round(0) }} degrees.
{%- endmacro -%}
{%- macro uv_levels() -%}
{%- set uv = states.sensor.pws_uv.state | int -%}
{%- if uv >= 6 and uv <= 7 -%}
Current UV index is high. Please be careful outdoors.
{%- elif uv >= 8 and uv <= 10 -%}
Current UV index is very high. It is not advised to go out.
{%- elif uv >= 11 -%}
Current UV index is extremely high. It is highly advised to stay indoors.
{%- else -%}
Good UV levels.
{%- endif -%}
{%- endmacro -%}
{%- macro USPS() -%}
USPS is going to deliver {{ states.sensor.usps_mail.state }} mails today.
{%- endmacro -%}
{%- macro alert_battery_levels() %}
{% for item in states if 'battery_level' in item.attributes and item.attributes.battery_level | int > 0 and item.attributes.battery_level | float <= 10.0 -%}{{- item.attributes.friendly_name ~ " battery is less than 10 percent" -}}
{%- if loop.first %}, {% elif loop.last %}, {% else %}, {% endif -%}
{%- endfor -%}
{%- endmacro -%}
{%- macro tesla_status() -%}
{%- if states("sensor.tesla_model_3_5yj3e1ea8jf010610_range_sensor") != "unknown" -%}
Your Tesla car battery is at {{ states.sensor.tesla_model_3_5yj3e1ea8jf010610_battery_sensor.state }} percent ({{ (states.sensor.tesla_model_3_5yj3e1ea8jf010610_range_sensor.state | int) | round(0) }} miles).
{%- endif -%}
{%- endmacro -%}
{%- macro pollen_levels() -%}
Pollen level is {{ states.sensor.pollen_level.state }}.
{%- endmacro -%}
{%- macro humidity_status() -%}
Home humidity is {{ states('sensor.dining_room_thermostat_humidity') }} percent.
{%- endmacro -%}
{%- macro alarm_status() -%}
Your home is {{ "SECURED!" if states('alarm_control_panel.simplisafe') == "armed_away" or states('alarm_control_panel.simplisafe') == "armed_home" else "UNSECURED!" }}
{%- endmacro -%}
{%- macro single_car_garage_door_status() -%}
{%- if states.binary_sensor.single_car_garage_door_tilt_sensor_sensor.state|lower == "on" -%}
{{ states.binary_sensor.single_car_garage_door_tilt_sensor_sensor.attributes.friendly_name }} is OPEN
{%- endif -%}
{%- endmacro -%}
{%- macro two_car_garage_door_status() -%}
{% if states.binary_sensor.two_car_garage_door_tilt_sensor_sensor.state|lower == "on" %}
{{ states.binary_sensor.two_car_garage_door_tilt_sensor_sensor.attributes.friendly_name }} is OPEN
{% endif %}
{%- endmacro -%}
{%- macro garage_status() -%}
{%- set single_car_garage = single_car_garage_door_status() -%}
{%- set two_car_garage = two_car_garage_door_status() -%}
{%- if single_car_garage | trim == "" and two_car_garage | trim == "" -%}
Both the garage doors are CLOSED!
{%- elif single_car_garage | trim != "" and two_car_garage | trim != "" -%}
Warning! Both garage doors are OPEN.
{% else %}
Warning! {{ single_car_garage }} {{ two_car_garage }}
{%- endif -%}
{%- endmacro -%}
{%- macro plural(name) -%}
{{- "true" if name.endswith("s") else "false" -}}
{%- endmacro -%}
{%- macro light_status() -%}
{%- set lights_switches = ["light.family_room",
"light.master_bedroom",
"switch.basement_left",
"switch.basement_right",
"switch.frontyard_light",
"switch.garage",
"switch.guest_bedroom",
"switch.prayer_room",
"switch.kids_bed_accent",
"switch.kids_bedroom",
"switch.kitchen",
"switch.office_room",
"switch.wemobackyardlightswitch",
"switch.zwave_smart_switch_switch"] %}
{% for item in lights_switches -%}
{%- if states[item.split('.')[0]][item.split('.')[1]].state == "on" -%}
{%- set friendly_name = states[item.split('.')[0]][item.split('.')[1]].attributes.friendly_name -%}
{{ friendly_name }} {{ 'are' if plural(friendly_name) == "true" else 'is' }} ON.
{% endif %}
{%- endfor -%}
{%- endmacro -%}
{%- macro mother_of_all_macros() -%}
{{ alarm_status() }}
{{ garage_status() }}
{{ USPS() }}
{{ tesla_status() }}
{{ weather_update() }}
{{ humidity_status() }}
{{ uv_levels() }}
{{ pollen_levels() }}
{{ alert_battery_levels() }}
{{ light_status() }}
{%- endmacro -%}
{{- mother_of_all_macros() -}}

58
templates/birthday_wishes.yaml Executable file
View File

@@ -0,0 +1,58 @@
>
{# Birthday Wishes #}
{%- macro getRandomBirthdayWish() -%}
{{- [
"Celebrate your birthday today. Celebrate being Happy every day.",
"Well, you are another year older and you haven't changed a bit. That's great because you are perfect just the way you are. Happy Birthday.",
"You are special and I hope that you float through the day with a big smile on your face. Happy Birthday!",
"Happy Birthday!!! I hope this is the begining of your greatest, most wonderful year ever!",
"Wishing you a day that is as special in every way as you are. Happy Birthday.",
"You have to get older, but you don't have to grow up!",
"Set the world on fire with your dreams and use the flame to light a birthday candle. HAPPY BIRTHDAY!",
"Thinking of you on your birthday, and wishing you all the best! I hope it is as fantastic as you are, you deserve the best and nothing less.",
"I hope that you have the greatest birthday ever from the moment you open your eyes in the morning until they close late at night.",
"Hope your birthday is totally cool, really funtastic, wonderful, exciting, majorly awesome, rocking and HAPPY. Happy Birthday wishes.",
"Be your own light. Find your own way. It should be easy with all those candles.",
"Your birthday should be a national holiday. I need a day off. Happy Birthday.",
"You are a gift to the world. How is that for a reverse birthday wish. Happy Birthday.",
"I hope that today is the beginning of a great year for you. Happy Birthday.",
"Happy Birthday !! Have a wonderful happy, healthy birthday and many more to come.",
"I hope you have a beautiful day and get at least half of what you want! Happy Birthday!",
"Happy Birthday. Just one more year and you will be perfect. Yes, I did say that last year.",
"You have a birthday twinkle in your eye so have fun and know we love you fairy, fairy much. Happy Birthday.",
"Live today like it is a special gift, because it is the best birthday gift. Happy Birthday.",
"May your heart naturally beat with the happiness and laughter that you give others. Happy Birthday.",
"Happy Birthday. Hope it's one of the best ever!!!!... a lovely birthday for a lovely person!",
"Wishing you health, love, wealth, happiness and just everything your heart desires. Happy Birthday.",
"Happy Birthday to a friend who means more to me than chocolate.",
"Things I like about you: humor, looks, everything. Happy Birthday.",
"Watch out world. You are old enough to know what to do and how to do it. Happy Birthday.",
"When I paint my masterpiece, I am pretty sure there will be a spot for you. Happy Birthday.",
"Happy Birthday. I hope that you will have a truly marvelous and joyous day with family and friends.",
"Enjoy your birthday and every day to the fullest. A Happy Birthday is just part of a Happy Life.",
"No matter how hard you try to fit in, you were born to stand out. Now celebrate that fact.",
"Hope your day is simply terrific! Happy Birthday.",
"I wish you a wonderfulBirthday!! I hope you have an amazing day and lots of fun! Enjoy this day, you deserve it!",
"Time waits for no one but that doesn't matter if you don't wait for it! Happy Birthday.",
"Today is not the end of another year, but the start of a new one. Happy Birthday.",
"Being young is a privilege. Being attractive a genetic gift. Being cool, that is all you. Happy Birthday.",
"Wishing you love and happiness on your birthday. Happy Birthday",
"You aren't getting older, you are getting better. Happy Birthday.",
"May your day be beautiful and may your heart be happy and may you celebrate birthdays for many years to come.",
"I wish you happiness, health and so many good things in your life. Happy Birthday!",
"Work hard. Play hard. Eat lots of cake. That's a good motto for your birthday and for life.",
"I wish you happiness, health and so many good things in your life. Happy Birthday!",
"What should we celebrate first: your accomplishments or your birthday?",
"Out of the 19,178,082 people having a birthday today, you rank solidly in my top 10 list.",
"Happy Birthday to a lovely & vibrant individual!",
"You remind me of you at your age. Young and good looking! Happy Birthday!",
"I wish you the best birthday ever! I hope you get lots of kisses and hugs. Happy Birthday!",
"Hope you have wonderful birthday filled with fun, excitement and joy. Happy Birthday.",
"I hope your BIG BRIGHT STAR keeps on shining. HAPPY BIRTHDAY !",
"Happy Birthday. Hope it's one of the best ever!!! A lovely birthday for a lovely person!",
"Happy moments. Happy thoughts. Happy Dreams. Happy feelings. Happy Birthday.",
"Happy Birthday to you!, Happy Birthday to you!, Happy Birthday to you!"
] | random -}}
{%- endmacro -%}
{{- getRandomBirthdayWish() -}}

191
templates/goodnight.yaml Executable file
View File

@@ -0,0 +1,191 @@
>
{#- returns "true" if the name ends with 's' -#}
{%- macro plural(name) -%}
{{- "true" if name.endswith("s") else "false" -}}
{%- endmacro -%}
{#- Alerts low battery (below 30%), ONLY when the phone is not already pluggedin -#}
{%- macro low_battery_check() -%}
{%- set level = 30 -%}
{%- for item in states.device_tracker if '_' in item.entity_id.split('.')[1] and state_attr(item.entity_id, "battery") |lower != "none" -%}
{%- if item.attributes.battery|int < level -%}
{%- if states("sensor." ~ item.friendly_name |lower ~"s_iphone_battery_state") | lower != "charging" %}
{{- item.attributes.friendly_name}}s iPhone battery is at {{ item.attributes.battery }} percent.
{%- endif %}
{%- endif %}
{%- endfor -%}
{%- endmacro -%}
{#- Provides Light Status -#}
{%- macro light_status() -%}
{%- set lights_switches = ["light.family_room",
"light.master_bedroom",
"switch.basement_left",
"switch.basement_right",
"switch.frontyard_light",
"switch.garage",
"switch.guest_bedroom",
"switch.prayer_room",
"switch.kids_bed_accent",
"switch.kids_bedroom",
"switch.kitchen",
"switch.office_room",
"switch.wemobackyardlightswitch",
"switch.zwave_smart_switch_switch"] %}
{%- for item in lights_switches -%}
{%- if states[item.split('.')[0]][item.split('.')[1]].state == "on" -%}
{%- set friendly_name = states[item.split('.')[0]][item.split('.')[1]].attributes.friendly_name %}
{%- if plural(friendly_name) == "true" %}
{{- friendly_name }} are ON.
{%- else -%}
{{- friendly_name }} is ON.
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{#- Provides Home Security System Status -#}
{%- macro alarm_status() -%}
{%- if states.alarm_control_panel.simplisafe.state | lower == "disarmed" -%}
Your home security system is switched OFF. You may want to turn it ON.
{%- elif states.alarm_control_panel.simplisafe.state | lower == "armed_away" -%}
Your home security system is set to away mode.
{%- elif states.alarm_control_panel.simplisafe.state | lower == "armed_home" -%}
Your home security system is ON, and your home is secured.
{%- endif %}
{%- endmacro -%}
{#- Provides Trash and Recycle Reminder -#}
{%- macro trash_recycle_status() -%}
{%- set flag = false -%}
{%- if states.sensor.trash_day.state | lower == "yes" -%}
Your trash will be picked up tomorrow. Did you leave the trash bin outside?.
{%- set flag = true -%}
{%- endif %}
{%- if states.sensor.recycle_day.state | lower == "yes" -%}
{%- if flag -%}
Also, your recycle stuff will be picked up tomorrow as well! Please leave both recycle bin and trash cans outside if you haven't!.
{%- else -%}
Your recycle stuff will be picked up tomorrow. Please leave the recycle bin outside if you haven't done so!.
{%- endif -%}
{%- endif %}
{%- endmacro -%}
{%- macro outside_weather() -%}
{%- if states('sensor.dark_sky_minutely_summary') != "unknown" -%}
Outside, it is going to be {{states('sensor.dark_sky_minutely_summary')}}.
{%- endif -%}
{%- if states('sensor.dark_sky_apparent_temperature') != "unknown" %}
The temperature outside is around {{ states.sensor.dark_sky_apparent_temperature.state | round(0)}} degrees.
{%- endif -%}
{%- endmacro -%}
{%- macro pihole() -%}
{%- if states.sensor.ads_blocked_today.state|int > 100 -%}
Our internet blocking system has blocked {{states.sensor.ads_blocked_today.state}} ads today.
{%- endif -%}
{%- endmacro -%}
{%- macro charging_status() -%}
{%- for item in states if "iphone_battery_state" in item.entity_id and item.state != "Charging" %}
{%- if loop.first %}{% elif loop.last %} and {% else %}, {% endif -%}{{- item.name.split(' ')[0] -}}
{%- endfor -%}
{%- endmacro -%}
{%- macro battery_status() -%}
{% set value = charging_status() %}
{% if ' and ' in value or ',' in value %}
{{ value }}'s phones are not plugged in.
{% elif value != '' %}
{{ value }}'s phone is not plugged in.
{% endif %}
{%- endmacro -%}
{#- Provides Garage Doors Status -#}
{%- macro single_car_garage_door_status() -%}
{% if states.binary_sensor.single_car_garage_door_tilt_sensor_sensor.state|lower == "on" %}
{{ states.binary_sensor.single_car_garage_door_tilt_sensor_sensor.attributes.friendly_name }} is OPEN
{% endif %}
{%- endmacro -%}
{%- macro two_car_garage_door_status() -%}
{% if states.binary_sensor.two_car_garage_door_tilt_sensor_sensor.state|lower == "on" %}
{{ states.binary_sensor.two_car_garage_door_tilt_sensor_sensor.attributes.friendly_name }} is OPEN
{% endif %}
{%- endmacro -%}
{%- macro tesla_status() %}
{%- if states("binary_sensor.tesla_model_3_5yj3e1ea8jf010610_charger_sensor") != "unknown" -%}
Your Tesla Car is {{ 'not' if states.binary_sensor.tesla_model_3_5yj3e1ea8jf010610_charger_sensor.state == "off" }} plugged in.
{% endif %}
{%- if states("sensor.tesla_model_3_5yj3e1ea8jf010610_battery_sensor") != "unknown" and states("sensor.tesla_model_3_5yj3e1ea8jf010610_range_sensor") != "unknown" -%}
Tesla Car battery is at {{ states.sensor.tesla_model_3_5yj3e1ea8jf010610_battery_sensor.state }}%, and you can drive about {{ (states.sensor.tesla_model_3_5yj3e1ea8jf010610_range_sensor.state | int) | round(0) }} miles.
{% endif %}
{%- endmacro %}
{#- Check for low humidity levels in autumn, winter and high levels during rest of the year -#}
{%- macro humidity_status() -%}
{%- if states.sensor.season.state| lower == "autumn" or states.sensor.season.state| lower == "winter" %}
{%- if states.sensor.dining_room_thermostat_humidity.state | int < 30 -%}
Home humidity is less than 30%.
{%- endif -%}
{% else %}
{%- if states.sensor.dining_room_thermostat_humidity.state | default(0) | int > 60 -%}
Home humidity is more than 60%.
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
{%- macro clean_up(data) -%}
{%- for item in data.split("\n") if item | trim != "" -%}
{{ item | trim }} {% endfor -%}
{%- endmacro -%}
{%- macro getGreeting() -%}
{%- if greeting | default('yes', true ) == "yes" -%}
{% if now().hour|int < 12 %}
Have a great day!
{% elif now().hour|int < 18 %}
Enjoy your afternoon!
{% elif now().hour|int < 20 %}
Enjoy your evening!
{% else %}
Have a good night!
{% endif %}
{%- endif -%}
{%- endmacro -%}
{#- Main macro that runs all other macros and combines the information -#}
{%- macro run_script() -%}
It is {% if now().hour > 12 %}{{ now().hour | int - 12 }}: {{- now().minute }} PM{% else %}{{ now().hour }}: {{- now().minute }} PM{% endif %}. Here is the status of your home.{{- alarm_status() -}}
{%- set battery_output = low_battery_check() -%}
{%- if battery_output | trim != "" -%}
{{- battery_output -}} Please make sure you put the phones to charge.
{%- endif -%}
{%- set light_output = light_status() -%}
{%- if light_output | trim == "" -%}
All the lights in the house are OFF.
{%- else -%}
{{- light_output -}}
{%- endif -%}
{%- set single_car_garage = single_car_garage_door_status() -%}
{%- set two_car_garage = two_car_garage_door_status() -%}
{%- if single_car_garage | trim == "" and two_car_garage | trim == "" -%}
The garage doors are closed.
{%- elif single_car_garage | trim != "" and two_car_garage | trim != "" -%}
Warning! Both garage doors are OPEN.
{% else %}
Warning! {{ single_car_garage }} {{ two_car_garage }}
{%- endif -%}
{%- set trash_output = trash_recycle_status() -%}{{- trash_recycle_status() -}}
{{- battery_status() -}}
{{- tesla_status() -}}
{{- humidity_status() -}}
{{- outside_weather() }} Everything else looks good. {{ getGreeting() }}
{%- endmacro -%}
{{- clean_up(run_script()) -}}

206
templates/home_status.yaml Executable file
View File

@@ -0,0 +1,206 @@
>
{%- macro alert_battery_levels() -%}
{%- for item in states if 'battery_level' in item.attributes and item.attributes.battery_level | int > 0 and item.attributes.battery_level | float <= 10.0 %}
{{- item.attributes.friendly_name}} battery is less than 10 percent.
{%- endfor %}
{%- endmacro %}
{# Birthday notifications #}
{%- macro birthday_countdown( name, days2go ) -%}
{%- if days2go == 0 -%}
Today is {{name}}'s Birthday!. Happy Birthday to you, my dear {{name}}!!!.
{%- elif days2go == 1 -%}
Tomorrow is {{name}}'s Birthday! HURRAY!!!
{%- elif days2go > 1 and days2go <= 10 -%}
{{name}}'s Birthday is in {{days2go}} days! HURRAY!!!
{%- endif -%}
{%- endmacro -%}
{%- macro tesla_status() -%}
{% if states("sensor.tesla_model_3_5yj3e1ea8jf010610_range_sensor") != "unknown" %}
{%- if (states('sensor.tesla_model_3_5yj3e1ea8jf010610_range_sensor') | int) | round(0) < 75 -%}
Attention!. Your Tesla car battery is at {{ states('sensor.tesla_model_3_5yj3e1ea8jf010610_battery_sensor') }} percent. and you can only drive about {{ (states('sensor.tesla_model_3_5yj3e1ea8jf010610_range_sensor') | int) | round(0) }} miles. Please charge your car if you want to go anywhere.
{%- endif -%}
{% endif %}
{%- endmacro -%}
{# USPS mail notifications - only when I have 1 or more mails #}
{%- macro USPS() -%}
{% if now().hour | int <= 16 %}
{%- if states("sensor.usps_mail") != "unknown" -%}
{% if states('sensor.usps_mail') | int > 0 -%}
{%- if states('sensor.usps_mail') | int == 1 -%}
USPS is going to deliver {{ states('sensor.usps_mail') }} mail today.
{%- else -%}
USPS is going to deliver {{ states('sensor.usps_mail') }} mails today.
{%- endif -%}
{%- endif -%}
{%- endif -%}
{%- if states("sensor.usps_packages") != "unknown" -%}
{%- if states('sensor.usps_packages') | int > 0 -%}
{%- if states('sensor.usps_packages') | int == 1 -%}
USPS is going to deliver {{ states('sensor.usps_packages') }} package today.
{%- else -%}
USPS is going to deliver {{ states('sensor.usps_packages') }} packages today.
{%- endif -%}
{%- endif -%}
{%- endif -%}
{% endif %}
{%- endmacro -%}
{# Calendar notifications #}
{%- macro calendar_reminder() -%}
{% set days2NextEvent = 0 %}
{% if state_attr('calendar.suresh_kalavala', 'start_time') != None and state_attr('calendar.suresh_kalavala', 'message') != None %}
{% if now().year == strptime(states.calendar.suresh_kalavala.attributes.start_time, '%Y-%m-%d %H:%M:%S').year %}
{% set days2NextEvent = strptime(states.calendar.suresh_kalavala.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.suresh_kalavala.attributes.start_time, '%Y-%m-%d %H:%M:%S').strftime('%j') | int) -%}
{% endif -%}
{% if days2NextEvent <= (states.input_number.calendar_remind_before_days.state | int) %}
Your next event. {{ states.calendar.suresh_kalavala.attributes.message }} . starts
{% if days2NextEvent == 0 | int %}
today at {{ strptime(states.calendar.suresh_kalavala.attributes.start_time, '%Y-%m-%d %H:%M:%S').strftime('%I:%M %p') }}.
{% elif days2NextEvent == 1 %}
tomorrow at {{ strptime(states.calendar.suresh_kalavala.attributes.start_time, '%Y-%m-%d %H:%M:%S').strftime('%I:%M %p') }}.
{% elif days2NextEvent == 2 %}
day after tomorrow {{ strptime(states.calendar.suresh_kalavala.attributes.start_time, '%Y-%m-%d %H:%M:%S').strftime('%A') }}
at {{ strptime(states.calendar.suresh_kalavala.attributes.start_time, '%Y-%m-%d %H:%M:%S').strftime('%I:%M %p') }}.
{% else %}
in {{ days2NextEvent }} days.
{% endif %}
{% endif %}
{% endif %}
{%- endmacro -%}
{# Indian Holidays notifications #}
{%- macro IndianHolidays() -%}
{% set days2NextEvent = 0 %}
{% if state_attr('calendar.holidays_in_india', 'start_time') != None and state_attr('calendar.holidays_in_india', 'message') != None %}
{% 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.state | int) %}
{% if days2NextEvent == 0 | int %}
Today is {{ states.calendar.holidays_in_india.attributes.message | replace(".", "")}}.
{%- elif days2NextEvent == 1 %}
Tomorrow is {{ states.calendar.holidays_in_india.attributes.message | replace(".", "")}}.
{%- elif days2NextEvent == 2 -%}
{{ states.calendar.holidays_in_india.attributes.message | replace(".", "") }}. is day after tomorrow.
{%- else -%}
{{ states.calendar.holidays_in_india.attributes.message | replace(".", "") }}. is in {{ days2NextEvent }} days.
{%- endif -%}
{%- endif %}
{%- endif %}
{%- endmacro -%}
{# USA Holidays notifications #}
{%- macro USHolidays() -%}
{% set days2NextEvent = 0 %}
{% if state_attr('calendar.holidays_in_united_states', 'start_time') != None and state_attr('calendar.holidays_in_united_states', 'message') != None %}
{% if now().year == strptime(states.calendar.holidays_in_united_states.attributes.start_time, '%Y-%m-%d %H:%M:%S').year %}
{% set days2NextEvent = strptime(states.calendar.holidays_in_united_states.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_united_states.attributes.start_time, '%Y-%m-%d %H:%M:%S').strftime('%j') | int) -%}
{% endif -%}
{% if days2NextEvent <= (states.input_number.calendar_remind_before_days.state | int) %}
{% if days2NextEvent == 0 | int %}
Today is {{ states.calendar.holidays_in_united_states.attributes.message | replace(".", "")}}.
{%- elif days2NextEvent == 1 %}
Tomorrow is {{ states.calendar.holidays_in_united_states.attributes.message | replace(".", "")}}.
{%- elif days2NextEvent == 2 -%}
{{ states.calendar.holidays_in_united_states.attributes.message | replace(".", "")}} is day after tomorrow.
{%- else -%}
{{ states.calendar.holidays_in_united_states.attributes.message | replace(".", "")}} is in {{ days2NextEvent }} days.
{%- endif -%}
{%- endif %}
{%- endif %}
{%- endmacro -%}
{# Only notify when high levels of UV #}
{%- macro uv_levels() -%}
{%- set uv = states('sensor.current_uv_index') | int -%}
{%- if uv >= 6 and uv <= 7 -%}
Current UV index is high. Please be careful outdoors.
{%- elif uv >= 8 and uv <= 10 -%}
Current UV index is very high. It is not advised to go out.
{%- elif uv >= 11 -%}
Current UV index is extremely high. It is highly advised to stay indoors.
{%- endif -%}
{%- endmacro -%}
{# weather summary #}
{%- macro weather_update() -%}
{% if states('sensor.dark_sky_minutely_summary') |lower != "unknown" %}
{% if '.' in states('sensor.dark_sky_minutely_summary') %}
It is going to be {{ states('sensor.dark_sky_minutely_summary') }}
{% else %}
It is going to be {{ states('sensor.dark_sky_minutely_summary') }}.
{% endif %}
{% endif %}
{% if states('sensor.dark_sky_apparent_temperature') | lower != "unknown" %}
Outside temperature is {{ states('sensor.dark_sky_apparent_temperature') | round(0) }} degrees.
{% endif %}
{%- endmacro -%}
{# Only notify pollen levels in spring #}
{%- macro pollen_levels() -%}
{% if states('sensor.season') | lower == "spring" %}
{% if states('sensor.pollen_level') | lower != "low" %}
Pollen level is {{ states('sensor.pollen_level') }}.
{% endif %}
{% endif %}
{%- endmacro -%}
{# Drone Flying Weather #}
{%- macro drone_weather() -%}
{% if states.binary_sensor.good_weather_to_fly_drones.state| lower == "on" and
states.device_tracker.suresh_suresh.state == "home" and
states.sun.sun.state == "above_horizon" %}
It is now a great weather to fly drone outside.
{% endif %}
{%- endmacro -%}
{# Check for low humidity levels in autumn, winter and high levels during rest of the year #}
{# exclude weather service humidity sensors 'pws' from the loop #}
{%- macro humidity_status() -%}
{%- if states('sensor.season') | lower == "autumn" or states('sensor.season') | lower == "winter" %}
{%- if states('sensor.dining_room_thermostat_humidity') | int < 30 -%}
Home humidity is less than 30%.
{%- endif -%}
{% else %}
{%- if states('sensor.dining_room_thermostat_humidity') | default(0) | int > 60 -%}
Home humidity is more than 60%.
{%- endif -%}
{%- endif -%}
{%- endmacro -%}
{# a macro that removes all newline characters, empty spaces, and returns formatted text #}
{%- macro cleanup(data) -%}
{%- for item in data.split("\n") if item | trim != "" -%}
{{ item | trim }} {% endfor -%}
{%- endmacro -%}
{# a macro to call all macros :) #}
{%- macro mother_of_all_macros() -%}
It is {{ now().strftime("%I:%M %p") }}.
{{ USHolidays() }}
{{ weather_update() }}
{{ pollen_levels() }}
{{ uv_levels() }}
{{ humidity_status() }}
{{ calendar_reminder() }}
{{ IndianHolidays() }}
{{ alert_battery_levels() }}
{{ USPS() }}
{{ tesla_status() }}
{{ drone_weather() }}
{{ birthday_countdown("Mallika", states.input_label.mallika_birthday_days2go.state | int ) }}
{{ birthday_countdown("Srinika", states.input_label.srinika_birthday_days2go.state | int ) }}
{{ birthday_countdown("Hasika", states.input_label.hasika_birthday_days2go.state | int ) }}
{%- endmacro -%}
{# Call the macro #}
{{- cleanup(mother_of_all_macros()) -}}