2019-08-19 00:21:05 +00:00
>
2019-04-17 22:46:06 +00:00
{%- 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 #}
2019-12-20 15:32:28 +00:00
{%- macro birthday_countdown(name, days2go) -%}
{%if days2go != 'unknown' %}
{%- if days2go |int == 0 -%}
Today is {{name}}'s Birthday!. Happy Birthday to you, my dear {{name}}!!!.
{%- elif days2go |int == 1 -%}
Tomorrow is {{name}}'s Birthday! HURRAY!!!
{%- elif days2go |int > 1 and days2go |int <= 10 -%}
{{name}}'s Birthday is in {{days2go}} days! HURRAY!!!
{%- endif -%}
2019-04-17 22:46:06 +00:00
{%- endif -%}
{%- endmacro -%}
{%- macro tesla_status() -%}
2020-02-05 23:28:38 +00:00
{% if states("sensor.tesla_model_3_range_sensor") != "unknown" %}
{%- if (states('sensor.tesla_model_3_range_sensor') | int) | round(0) < 75 and
(states('sensor.tesla_model_3_range_sensor') | int) | round(0) > 0 -%}
Attention!. Your Tesla car battery is at {{ states('sensor.tesla_model_3_battery_sensor') }} percent. and you can only drive about {{ (states('sensor.tesla_model_3_range_sensor') | int) | round(0) }} miles. Please charge your car if you want to go anywhere.
2019-04-17 22:46:06 +00:00
{%- 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 -%}
2019-12-20 15:32:28 +00:00
{% if days2NextEvent <= states('input_number.calendar_remind_before_days') | int %}
2019-04-17 22:46:06 +00:00
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 -%}
2019-12-20 15:32:28 +00:00
{% if days2NextEvent <= (states('input_number.calendar_remind_before_days') | int) %}
2019-04-17 22:46:06 +00:00
{% 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 -%}
2019-12-20 15:32:28 +00:00
{% if days2NextEvent <= (states('input_number.calendar_remind_before_days') | int) %}
2019-04-17 22:46:06 +00:00
{% 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() -%}
2019-05-28 04:30:49 +00:00
{%- 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') |replace("min.", "minutes") -}}.
{%- else -%}
It is going to be {{ states('sensor.dark_sky_minutely_summary') }}.
{%- endif -%}
{%- endif -%}
{%- if states('sensor.dark_sky_apparent_temperature') | lower != "unknown" -%}
2019-04-17 22:46:06 +00:00
Outside temperature is {{ states('sensor.dark_sky_apparent_temperature') | round(0) }} degrees.
2019-05-28 04:30:49 +00:00
{%- endif -%}
{%- if states('sensor.cold_flu_forecasted_average') | float > 8.0 %}
Cold and Flu index is High. Please take extra caution!.
{%- endif -%}
2019-04-17 22:46:06 +00:00
{%- endmacro -%}
{# Only notify pollen levels in spring #}
{%- macro pollen_levels() -%}
2019-05-24 12:28:15 +00:00
{% if states('sensor.season') | lower == "spring" %}
2019-05-25 17:20:56 +00:00
Pollen level for today is {{ state_attr('sensor.allergy_index_today', 'rating') | replace("/", " to " ) -}}.
2019-05-24 12:28:15 +00:00
{%- if states('sensor.allergy_index_tomorrow') | float > 7.0 -%}
Tomorrow's pollen levels are going to be Medium to High.
{%- endif -%}
2019-04-17 22:46:06 +00:00
{% endif %}
{%- endmacro -%}
{# Drone Flying Weather #}
{%- macro drone_weather() -%}
2019-12-20 15:32:28 +00:00
{% if states('binary_sensor.good_weather_to_fly_drones')| lower == "on" and
2022-11-30 01:48:51 +00:00
states('device_tracker.life360_suresh') == "home" and
2019-12-20 15:32:28 +00:00
states('sun.sun') == "above_horizon" %}
2019-04-17 22:46:06 +00:00
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() }}
2019-12-20 15:32:28 +00:00
{{ birthday_countdown("Mallika", states('input_label.mallika_birthday_days2go')) }}
{{ birthday_countdown("Srinika", states('input_label.srinika_birthday_days2go')) }}
{{ birthday_countdown("Hasika", states('input_label.hasika_birthday_days2go')) }}
2019-04-17 22:46:06 +00:00
{%- endmacro -%}
2019-08-19 00:21:05 +00:00
2019-04-17 22:46:06 +00:00
{# Call the macro #}
2019-08-19 00:21:05 +00:00
{{- cleanup(mother_of_all_macros()) -}}