Files
Home-Assistant-Configs/templates/speech/nightly_briefing.yaml

320 lines
18 KiB
YAML

>
{# Nightly Briefing #}
{%- macro getReport() -%}
{% from 'speech.jinja' import greeting, dadjoke, inspirational_quote %}
{% from 'time.jinja' import input_datetime_12hr, read_time_from_calendar, next_twitch_stream %}
{% from 'status.jinja' import emma_sleep %}
{% from 'formatting.jinja' import cleanup %}
{% from 'easy_time.jinja' import count_the_days %}
<p>
{{ greeting() }}
</p>
<p>
{{ [
"Before the day comes to a close, here are my thoughts. Just kidding, I am a computer, I do not think. ",
"The day grows short, let us gather around the campfire for an epic tale of things to come. ",
"I am tired after a long day of doing absolutely nothing, but I am still here to give you the latest and greatest uselessness! ",
"My programmer decided that I should say something interesting here, and then he realized that he is not interesting. ",
] | random }}
</p>
<p>
{% if is_state('input_boolean.tornado_alarm','on') %}
"We are under a tornado warning. If you are not already in shelter, you should be. Get on it! "
{% elif is_state('input_boolean.tornado_watch','on') %}
{{ [
"There is currently a tornado watch active. Please keep an eye on the sky and your local weather reports. ",
"We are currently under a tornado watch. This means the possibility exists for a tornado to form. Be prepared, and be safe! ",
"The National Weather Service has issued a tornado watch for our area. Be prepared to take shelter if a warning is issued! ",
] | random }}
{% endif %}
{% if states('sensor.weatheralerts_active_alerts') > '0' %}
"Currently there are weather alerts active. The total number of alerts is {{ states('sensor.weather_alerts_active_corrected') }}. They are as follows. "
{{ states('sensor.weather_alert_string') }}.
{% endif %}
{% if is_state('binary_sensor.lightning_warning','on') %}
{% set ltgdist = (states('sensor.blitzortung_lightning_distance') | int) / 1.609 | round %}
{{ [
"There are reports of lightning in the area, please stay safe. ",
"My sensors detect the presence of lightning nearby, so you should prepare to take shelter if needed. ",
"A little birdy told me there is lightning nearby. His feathers were all sticking up, I have no idea why. ",
"Please exercise caution, as there is lightning in the area. ",
"That flashing in the sky is not interstellar warfare, it is simply lightning. But you should still be careful outside. ",
] | random }}
"The nearest lightning strike is {{ ltgdist }} miles away. "
{% endif %}
{% if (states('sensor.kdfi_visibility') | int ) < 3 %}
"I know it is night time, but just in case, "
{{ [
"It is foggy outside, please exercise caution when driving. ",
"The visibility outside is quite low. If you will be driving soon, please be cautious. ",
"It is pea soup outside right now, and that is just as awful to drive in as it is to eat. Be careful! ",
"Look out the window. Do you notice that you cannot see anything? Bear that in mind if you intend to drive any time soon. ",
"Be advised, it is very difficult to see outside right now. Drive safely. "
] | random }}
{% endif %}
</p>
<p>
{% if is_state('input_boolean.tony_streaming_today','on') %}
{{ [
"Tony will be pretending to be a real content creator tonight. ",
"Tony will be doing his best to defeat his impostor syndrome tonight. ",
"Tony will be playing video games and yelling into a microphone tonight. ",
"Tony will be scraping out the nickels and dimes tonight for the sake of entertainment. ",
"Tony is not really all that funny, but tonight he will present himself to a crowd of questionable individuals who seem to think that he is. "
] | random }} The studio is scheduled to go online at {{ input_datetime_12hr('input_datetime.tony_streaming_start_time') }}. "
{% else %}
"Tonight the studio will be dormant. Tony does not stream again until {{ next_twitch_stream() }} from now. "
{% endif %}
{% if is_state('binary_sensor.kallen_school_tomorrow','on') %}
{% if is_state('binary_sensor.kallen_band_tomorrow','on') %}
"Collin has school tomorrow, and there will be band practice in the morning at {{ read_time_from_calendar('calendar.kallen_school_days','start_time') }}. "
{% else %}
"Collin has school tomorrow at {{ read_time_from_calendar('calendar.kallen_school_days','start_time') }}. "
{% endif %}
{% else %}
"Collin does not have school tomorrow. "
{% endif %}
{% set start = (state_attr('binary_sensor.tina_work_tomorrow','start_timestamp') | int) // 1000 %}
{% set tmrw = (as_timestamp(states('sensor.date')) + 86400) | int %}
{% set diff = (start - tmrw) %}
{% if is_state('input_boolean.work_today','on') %}
{{ [
"Tina is still at work right now, ",
"Tina has not yet been released from work, ",
"Tina is still at the thankless idiot scape known as work, ",
"Tina is still consumed by the gods of capitalism, ",
] | random }} she will be done at approximately {{ input_datetime_12hr('input_datetime.tina_workday_end') }}.
{% elif is_state('binary_sensor.tina_work_tomorrow','on') %}
{{ [
"Tina must go and please the food gods tomorrow ",
"Tomorrow, Tina must go and entertain the gremlins known as her customers and coworkers ",
"Tomorrow, Tina will be owned by our lovely lord and savior, capitalism, ",
] | random }} at {{ diff | timestamp_custom('%H:%M %p',false) }}. "
{% else %}
{{ [
"Tina seems to have been granted a reprieve from her endless torture tomorrow. ",
"The powers that be have decided that Tina deserves a break from work tomorrow. ",
"Tina has been granted time off from the hellscape of work tomorrow. ",
"Tina will not be attending the gathering of tormented souls known as work tomorrow. ",
"The scheduling gods have decided that Tina's services will not be required tomorrow. "
"Tina gets a break tomorrow from grinding it out for the gods of capitalism. ",
"Tina will not be at the thankless idiot scape known as work tomorrow. ",
] | random }}
{% endif %}
</p>
<p>
{% from 'sports.jinja' import sports_pregame, sports_main %}
{% if is_state('input_boolean.sports_updates','on') %}
{% if is_state('binary_sensor.michigan_wolverines_inhibit','off') %}
{{ sports_pregame('sensor.michigan_wolverines') }}
{% endif %}
{% if is_state('binary_sensor.ohio_state_buckeyes_inhibit','off') %}
{{ sports_pregame('sensor.ohio_state_buckeyes') }}
{% endif %}
{% if is_state('binary_sensor.toledo_rockets_inhibit','off') %}
{{ sports_pregame('sensor.toledo_rockets') }}
{% endif %}
{% if is_state('binary_sensor.minnesota_vikings_inhibit','off') %}
{{ sports_pregame('sensor.minnesota_vikings') }}
{% endif %}
{% if is_state('binary_sensor.san_francisco_49ers_inhibit','off') %}
{{ sports_pregame('sensor.san_francisco_49ers') }}
{% endif %}
{% if is_state('binary_sensor.cleveland_guardians_inhibit','off') %}
{{ sports_pregame('sensor.cleveland_guardians') }}
{% endif %}
{% if is_state('binary_sensor.minnesota_twins_inhibit','off') %}
{{ sports_pregame('sensor.minnesota_twins') }}
{% endif %}
{% if is_state('binary_sensor.los_angeles_dodgers_inhibit','off') %}
{{ sports_pregame('sensor.los_angeles_dodgers') }}
{% endif %}
{% endif %}
</p>
<p>
{% if is_state('input_boolean.sports_updates','on') %}
{% if is_state('binary_sensor.michigan_wolverines_inhibit','off') %}
{{ sports_main('sensor.michigan_wolverines') }}
{% endif %}
{% if is_state('binary_sensor.ohio_state_buckeyes_inhibit','off') %}
{{ sports_main('sensor.ohio_state_buckeyes') }}
{% endif %}
{% if is_state('binary_sensor.toledo_rockets_inhibit','off') %}
{{ sports_main('sensor.toledo_rockets') }}
{% endif %}
{% if is_state('binary_sensor.minnesota_vikings_inhibit','off') %}
{{ sports_main('sensor.minnesota_vikings') }}
{% endif %}
{% if is_state('binary_sensor.san_francisco_49ers_inhibit','off') %}
{{ sports_main('sensor.san_francisco_49ers') }}
{% endif %}
{% if is_state('binary_sensor.cleveland_guardians_inhibit','off') %}
{{ sports_main('sensor.cleveland_guardians') }}
{% endif %}
{% if is_state('binary_sensor.minnesota_twins_inhibit','off') %}
{{ sports_main('sensor.minnesota_twins') }}
{% endif %}
{% if is_state('binary_sensor.los_angeles_dodgers_inhibit','off') %}
{{ sports_main('sensor.los_angeles_dodgers') }}
{% endif %}
{% endif %}
</p>
<p>
{% if states('input_select.scheduled_climate_mode_master_bedroom_aircon') != 'N/A' or states('input_select.scheduled_climate_mode_master_bedroom_fan') != 'N/A' %}
{{ [
"Tonight in master bedroom climate news, ",
"In the master bedroom, we have the following schedule to share. ",
"Bedroom climate scheduling will be as follows. ",
] | random }}
{% if states('input_select.scheduled_climate_mode_master_bedroom_aircon') != 'N/A' %}
{% if is_state('climate.master_bedroom_aircon','fan_only') %}
"The master bedroom air conditioner is already running in fan only mode. "
{% elif states('climate.master_bedroom_aircon') not in ['off','unknown','unavailable'] %}
"The master bedroom air conditioner is already running in {{ states('climate.master_bedroom_aircon') }} mode. "
{% elif is_state('input_select.scheduled_climate_mode_master_bedroom_aircon','AC') and is_state('input_boolean.hot_day','on') %}
"Today was a hot day, so the master bedroom air conditioner will activate cooling mode a bit earlier tonight at {{ input_datetime_12hr('input_datetime.master_bedroom_cooling') }}. "
{% elif is_state('input_select.scheduled_climate_mode_master_bedroom_aircon','AC') %}
"The master bedroom air conditioner will activate cooling mode at {{ input_datetime_12hr('input_datetime.master_bedroom_cooling') }}. "
{% elif is_state('input_select.scheduled_climate_mode_master_bedroom_aircon','Fan') %}
"The master bedroom air conditioner will activate fan only mode at {{ input_datetime_12hr('input_datetime.master_bedroom_cooling') }}. "
{% endif %}
{% endif %}
{% if states('input_select.scheduled_climate_mode_master_bedroom_fan') != 'N/A' %}
{% if is_state('fan.master_bedroom_fan','on') %}
"The master bedroom fan is already running. "
{% else %}
"The master bedroom fan will activate at {{ input_datetime_12hr('input_datetime.master_bedroom_fan') }}. "
{% endif %}
{% endif %}
{% endif %}
{% if is_state('input_boolean.kallen_overnight','off') %}
{% if states('input_select.scheduled_climate_mode_kallen_fan') != 'N/A' %}
{{ [
"In Collin's room, ",
"For Collin's climate schedule, we have the following. "
] | random }}
{% if is_state('fan.kallen_bedroom_fan','on') %}
"Collin's fan is already running. "
{% elif is_state('input_boolean.white_noise_kallen_bedroom','on') %}
"Collin's white noise generator is already running. "
{% elif is_state('input_select.scheduled_climate_mode_kallen_fan','Fan') %}
"Collin's fan will activate at {{ input_datetime_12hr('input_datetime.kallen_fan') }}. "
{% elif is_state('input_select.scheduled_climate_mode_kallen_fan','White Noise') %}
"Collin's white noise generator will activate at {{ input_datetime_12hr('input_datetime.kallen_bedtime') }}. "
{% endif %}
{% endif %}
{% else %}
"Collin's room will be left alone, as he is spending the night elsewhere tonight. "
{% endif %}
{% if states('input_select.scheduled_climate_mode_emma_aircon') != 'N/A' %}
{{ [
"In Emma's bedroom, ",
"For Emma's climate scheduling, "
] | random }}
{% if is_state('fan.emma_air_conditioner','on') and is_state('input_select.scheduled_climate_mode_emma_aircon','AC') %}
"Emma's air conditioner is already running. "
{% elif is_state('input_boolean.white_noise_emma_bedroom','on') and is_state('input_select.scheduled_climate_mode_emma_aircon','White Noise') %}
"Emma's white noise generator is already running. "
{% elif is_state('input_select.scheduled_climate_mode_emma_aircon','AC') %}
"Emma's air conditioner will be activated at {{ input_datetime_12hr('input_datetime.emma_bedtime') }}. "
{% elif is_state('input_select.scheduled_climate_mode_emma_aircon','White Noise') %}
"Emma's white noise generator will activate at {{ input_datetime_12hr('input_datetime.emma_bedtime') }}. "
{% endif %}
{% endif %}
</p>
<p>
{{ cleanup(emma_sleep()) }}
</p>
<p>
{% if (states('sensor.overnight_lowest_temperature') | int) <= (states('input_number.overnight_low_threshold') | int ) %}
"It will be very cold tonight, make sure to use extra blankets, wear more clothes, or whatever else will help you stay warm! Additionally, make sure Emma's heater is set high enough!"
{% endif %}
</p>
<p>
{% set windows = states('sensor.windows_open') %}
{% set doors = states('sensor.doors_open') %}
{% if states('sensor.total_faults') > '0' %}
{% if windows > '0' and doors > '0' %}
"There are currently {{ states('sensor.windows_open') }} {% if windows == '1' %}window {% else %}windows {% endif %}and {{ states('sensor.doors_open') }} {% if doors == '1' %}door {% else %}doors {% endif %}open. "
{% else %}
{% if windows > '0' %}
"There {% if windows == '1' %}is {% else %}are {% endif %}currently {{ states('sensor.windows_open') }} {% if windows == '1' %}window {% else %}windows {% endif %}open. "
{% endif %}
{% if doors > '0' %}
"There {% if doors == '1' %}is {% else %}are {% endif %}currently {{ states('sensor.doors_open') }} {% if doors == '1' %}door {% else %}doors {% endif %}open. "
{% endif %}
{% endif %}
"You will want to close these before the security system is armed for the night. "
{% endif %}
</p>
<p>
{% if state_attr('calendar.garbage_collection','start_time') != none %}
{% if count_the_days('calendar.garbage_collection','start_time') == 1 %}
{% if state_attr('calendar.garbage_collection','message') == 'Large Garbage Pickup' %}
Tomorrow is the monthly unlimited garbage pickup. Make sure to take out all regular trash, as well as any larger items that need to be disposed of.
{% else %}
Tomorrow is regular garbage pickup. Make sure that all trash cans are emptied and the outside bin has been wheeled to the curb.
{% endif %}
{% elif is_state('calendar.garbage_collection','on') %}
Today is garbage day. Please make sure to wheel the garbage bin back to the house.
{% endif %}
{% endif %}
</p>
<p>
{{ [
"For some useless trivia that no one asked for, I present to you the following: ",
"Since the developer who writes my scripts decided that this was somehow interesting, ",
"In case you had a burning desire to know, ",
"Since I know everyone lays awake at night wondering the answer to this question, ",
] | random }}
{% if (states('sensor.front_door_opened_today') | int) > 0 %}
"Today, the front door was opened {{ states('sensor.front_door_opened_today') }} times. "
{% else %}
"Today, the front door was never opened at all. Wow, did you people seriously not go anywhere? "
{% endif %}
{% if (states('sensor.back_door_opened_today') | int) > 0 %}
{% if (states('sensor.back_door_opened_today') | int) == 1 %}
"And in a rare and shocking incident, the back door was also opened today! But only just once. There's no telling what could happen otherwise! "
{% else %}
"In what has to be considered a near catastrophic incident, the back door was opened multiple times today! {{ states('sensor.back_door_opened_today') }} times, to be precise! "
{% endif %}
{% endif %}
</p>
<p>
{{ dadjoke() }}
</p>
<p>
{% if is_state('input_boolean.briefing_extras','on') %}
"And now we have the following extra information to pass along. {{ states('input_text.briefing_extras') }} "
{% endif %}
</p>
<p>
One last thing before I go. {{ inspirational_quote() }}
</p>
{%- 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() -%}
{{ getReport() }}
{%- endmacro -%}
{# Call the macro #}
{{- cleanup(mother_of_all_macros()) -}}