Files
Home-Assistant-Configs/custom_templates/status.jinja

279 lines
14 KiB
Django/Jinja

{% macro emma_sleep() %}
{% from 'time.jinja' import input_datetime_12hr_with_date, input_datetime_12hr %}
{% from 'easy_time.jinja' import custom_time, custom_time_between %}
{% set asleep = state_attr('input_datetime.emma_down_for_nap','timestamp') | int %}
{% set wakeup = state_attr('input_datetime.emma_up_from_nap','timestamp') | int %}
{% set day = now().strftime("%-d") %}
{% set asleep_day = asleep | timestamp_custom("%-d") %}
{% set wakeup_day = wakeup | timestamp_custom("%-d") %}
{% if is_state('input_boolean.emma_sleeping','off') and is_state('input_boolean.emma_has_napped','on') or ((asleep_day == day) and (wakeup_day == day)) %}
Emma napped today for {{ custom_time_between('input_datetime.emma_down_for_nap','input_datetime.emma_up_from_nap','hour,minute') }}. She was retrieved from her room at {{ input_datetime_12hr_with_date('input_datetime.emma_up_from_nap') }} approximately.
{% elif is_state('input_boolean.emma_has_napped','off') and ((asleep_day == day) and (wakeup_day != day)) and is_state('input_boolean.emma_sleeping','on') %}
Emma is down for nap. She was put down at {{ input_datetime_12hr_with_date('input_datetime.emma_down_for_nap') }} approximately. She has been asleep for {{ custom_time('input_datetime.emma_down_for_nap','hour,minute') }}.
{% elif is_state('input_boolean.emma_sleeping','on') %}
{% if is_state('binary_sensor.early_night_mode','on') %}
Emma is asleep for the night.
{% else %}
Emma has not yet awoken for the day.
{% endif %}
{% else %}
Emma is awake, and does not appear to have napped yet. She woke up at {{ input_datetime_12hr('input_datetime.emma_wakeup') }} today.
{% endif %}
{% endmacro %}
{% macro emma_sleep_notification() %}
{% from 'easy_time.jinja' import clock, custom_time_between %}
{% set asleep = state_attr('input_datetime.emma_down_for_nap','timestamp') | int %}
{% set wakeup = state_attr('input_datetime.emma_up_from_nap','timestamp') | int %}
{% set day = now().strftime("%-d") %}
{% set asleep_day = asleep | timestamp_custom("%-d") %}
{% set wakeup_day = wakeup | timestamp_custom("%-d") %}
{% if is_state('input_boolean.emma_sleeping','off') and is_state('input_boolean.emma_has_napped','on') or ((asleep_day == day) and (wakeup_day == day)) %}
Emma has awoken. She napped today for {{ custom_time_between('input_datetime.emma_down_for_nap','input_datetime.emma_up_from_nap','hour,minute') }}. She was retrieved from her room at {{ clock('12-hr') }}
{% elif is_state('input_boolean.emma_has_napped','off') and is_state('input_boolean.emma_sleeping','off') and ((asleep_day != day) or (wakeup_day != day)) %}
Emma has awoken for the day at {{ clock('12-hr') }}
{% elif is_state('input_boolean.emma_has_napped','off') and ((asleep_day == day) and (wakeup_day != day)) and is_state('input_boolean.emma_sleeping','on') %}
Emma is being put down for nap. She was put down at {{ clock('12-hr') }}
{% elif is_state('input_boolean.emma_sleeping','on') %}
Emma is asleep for the night (or at least, her sleep switch is active) at {{ clock('12-hr') }}
{% else %}
This notification is confused and should not be here. Blame Tony.
{% endif %}
{% endmacro %}
{% macro tony_morning_meds() %}
{% from 'time.jinja' import input_datetime_12hr, input_datetime_12hr_with_date, ct %}
{% set ct = ct() | int %}
{% if is_state('input_boolean.tony_morning_meds_taken','on') %}
Tony took his morning meds at {{ input_datetime_12hr_with_date('input_datetime.tony_morning_meds_taken') }} today.
{% elif is_state('input_boolean.tony_morning_meds_taken','off') and ct >= 21600 %}
Tony has not taken his morning meds.
{% if ct < state_attr('input_datetime.tony_morning_meds_notify','timestamp') | int %}
{{ ['He has a reminder scheduled for',
'Rest assured that I will pester him mercilessly about this, starting at',
'This is absolutely essential, and I will remind him to do it at',
'Since nobody including Tony himself likes him without his meds, I will remind him at',
] | random }} {{ input_datetime_12hr('input_datetime.tony_morning_meds_notify') }} today.
{% endif %}
{% endif %}
{% endmacro %}
{% macro tony_night_meds() %}
{% from 'time.jinja' import input_datetime_12hr, input_datetime_12hr_with_date, ct %}
{% set ct = ct() | int %}
{% if is_state('input_boolean.tony_night_meds_taken','on') and ct < 43200 %}
Tony took his night meds at {{ input_datetime_12hr_with_date('input_datetime.tony_night_meds_taken') }} today.
{% elif is_state('input_boolean.tony_night_meds_taken','off') and (ct >= 82800 or ct <= 21600) %}
Tony has not taken his night meds.
{{ ['He will be reminded when he goes to bed.',
'I will make sure he is reminded when it is time.',
'This will be rectified whenever he drags his ass to bed.',
'All in due time, of course.'
] | random }}
{% endif %}
{% endmacro %}
{% macro medReportTony() %}
{{ tony_morning_meds() }}
{{ tony_night_meds() }}
{% endmacro %}
{% macro kallen_morning_meds() %}
{% from 'time.jinja' import input_datetime_12hr, input_datetime_12hr_with_date, ct %}
{% set ct = ct() | int %}
{% set wakeup = state_attr('input_datetime.kallen_wakeup_time','timestamp') | int %}
{% set bedtime = state_attr('input_datetime.kallen_bedtime','timestamp') | int %}
{% if wakeup <= ct <= bedtime %}
{% if is_state('input_boolean.kallen_morning_meds_taken','on') %}
Kallen took his morning meds at {{ input_datetime_12hr_with_date('input_datetime.kallen_morning_meds_taken') }} today.
{% else %}
Kallen has not taken his morning meds.
{% if ct < state_attr('input_datetime.kallen_morning_meds_notify','timestamp') | int %}
{{ ['He has a reminder scheduled for',
'Rest assured that I will pester him mercilessly about this, starting at',
'This is absolutely essential, and I will remind him to do it at',
] | random }} {{ input_datetime_12hr('input_datetime.kallen_morning_meds_notify') }} today.
{% endif %}
{% endif %}
{% endif %}
{% endmacro %}
{% macro kallen_night_meds() %}
{% from 'time.jinja' import input_datetime_12hr, input_datetime_12hr_with_date, ct %}
{% set ct = ct() | int %}
{% set diff = state_attr('input_datetime.kallen_bedtime','timestamp') | int - ct %}
{% set wakeup = state_attr('input_datetime.kallen_wakeup_time','timestamp') | int %}
{% set bedtime = state_attr('input_datetime.kallen_bedtime','timestamp') | int - 900 %}
{% if is_state('input_boolean.kallen_night_meds_taken','on') %}
{% if (ct >= bedtime) or (ct < wakeup) %}
Kallen took his night meds at {{ input_datetime_12hr_with_date('input_datetime.kallen_night_meds_taken') }} today.
{% endif %}
{% else %}
{% if diff <= 3600 %}
Kallen has not taken his night meds.
{{ ['He will be reminded when he goes to bed.',
'I will make sure he is reminded when it is time.',
'All in due time, of course.'
] | random }}
{% endif %}
{% endif %}
{% endmacro %}
{% macro medReportKallen() %}
{% if is_state('input_boolean.kallen_overnight','on') %}
Kallen is staying elsewhere overnight.
{% else %}
{{ kallen_morning_meds() }}
{{ kallen_night_meds() }}
{% endif %}
{% endmacro %}
{% macro twitchStreamInfo(method) %}
{% from 'time.jinja' import next_twitch_stream %}
{% set streamstart = state_attr('input_datetime.tony_streaming_start_time','timestamp') | timestamp_custom('%-I:%M %p',false) %}
{% set game = state_attr('sensor.twitch_ironnerd24','game') %}
{% set viewers = state_attr('sensor.twitch_ironnerd24','viewers') %}
{% if is_state('sensor.twitch_ironnerd24','streaming') %}
Tony is currently streaming. The current stream category is {{ game }}. The current viewer count is {{ viewers }}.
{% elif is_state('input_boolean.tony_streaming_today','on') %}
{% if method == 'tts' %}
{{ [
"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 {{ streamstart }}. "
{% elif method == 'text' %}
Tony will be streaming today. Stream starts at {{ streamstart }}.
{% endif %}
{% elif state_attr('calendar.tony_s_twitch_schedule','start_time') != none %}
Tony does not have a stream scheduled today. The next scheduled stream is in {{ next_twitch_stream() }} approximately.
{% endif %}
{% endmacro %}
{% macro tonyStatusReport(type,method) %}
{% from 'status.jinja' import medReportTony, twitchStreamInfo %}
{% if type == 'meds' %}
{{ medReportTony() }}
{% endif %}
{% if type == 'stream' %}
{{ twitchStreamInfo(method) }}
{% endif %}
{% if type == 'full' %}
{{ medReportTony() }}
{{ twitchStreamInfo(method) }}
{% endif %}
{% endmacro %}
{% macro schoolReportKallen(method) %}
{% from 'time.jinja' import input_datetime_12hr, ct %}
{% from 'easy_time.jinja' import custom_time, count_the_days %}
{% set wakeup = state_attr('input_datetime.kallen_wakeup_time','timestamp') %}
{% set bedtime = state_attr('input_datetime.kallen_bedtime','timestamp') %}
{% set ct = ct() | int %}
{% if method == 'tts' %}
{% if is_state('input_boolean.kallen_school_today', 'on') %}
{% if is_state('sensor.school_start_days2go', '0') %}
Today is the first day of school! The last day is in {{ custom_time('input_datetime.school_last_day','month,week,day') }}.
{% else %}
{{ [ 'Today is a school day.',
'Collin has school today.',
'It is a school day. '
] | random }}
{% if is_state('input_boolean.two_hour_delay','on') %}
'But there was a two hour delay. '
{% endif %}
{% endif %}
{% if is_state('input_boolean.kallen_alternate_pickup','on') %}
{{ states('input_text.kallen_pickup') }} will be picking Collin up from school today.
{% else %}
Pickup today will be at {{ input_datetime_12hr('input_datetime.kallen_school_day_end') }}.
{% if is_state('input_boolean.kallen_school_early_release','on') %}
And It is early release!
{% endif %}
{% endif %}
{% if states('sensor.windows_open') | int > 0 %}
'I detect that there are windows open. Make sure you close them before you leave, or else the security system will not arm. '
{% endif %}
{% endif %}
{% if is_state('input_boolean.school_cancelled','on') %}
'School has been cancelled for today. '
{% endif %}
{% if (count_the_days('input_datetime.thanksgiving_break_start') | int <= 14) and (count_the_days('input_datetime.thanksgiving_break_start') | int > 0) %}
{{ [ 'Oh, and look at that.',
'For those trying to keep count. ',
'In case you were wondering.',
'Also, did you know.'
] | random }}
'Thanksgiving break starts in {{ custom_time('input_datetime.thanksgiving_break_start','week,day') }}!'
{% endif %}
{% if (count_the_days('input_datetime.christmas_break_start') | int <= 14) and (count_the_days('input_datetime.christmas_break_start') | int > 0) %}
{{ [ 'Oh, and look at that.',
'For those trying to keep count. ',
'In case you were wondering.',
'Also, did you know.'
] | random }}
'Christmas break starts in {{ custom_time('input_datetime.christmas_break_start','week,day') }}!'
{% endif %}
{% if (count_the_days('input_datetime.spring_break_start') | int <= 14) and (count_the_days('input_datetime.spring_break_start') | int > 0) %}
{{ [ 'Oh, and look at that.',
'For those trying to keep count. ',
'In case you were wondering.',
'Also, did you know.'
] | random }}
'Spring break starts in {{ custom_time('input_datetime.spring_break_start','week,day') }}!'
{% endif %}
{% if (count_the_days('input_datetime.school_last_day') | int <= 35) and (count_the_days('input_datetime.school_last_day') | int > 0) %}
{{ [ 'Oh, and look at that.',
'For those trying to keep count. ',
'In case you were wondering.',
'Also, did you know.'
] | random }}
The school year ends in {{ custom_time('input_datetime.school_last_day','week,day') }}.
{% endif %}
{% if count_the_days('input_datetime.school_last_day') | int == 0 %}
Congratulations, today is the last day of school! Have an awesome day!
{% endif %}
{% if count_the_days('input_datetime.school_last_day') | int == -1 -%}
Today is the first day of Summer Break!
{%- endif %}
{% elif method == 'text' %}
{% if is_state('input_boolean.kallen_school_today','on') %}
{% if is_state('input_boolean.two_hour_delay','on') %}
School is currently under a two hour delay for Kallen.
{% elif is_state('input_boolean.kallen_at_school','on') %}
Kallen is at school right now.
{% if is_state('input_boolean.kallen_alternate_pickup','on') %}
{{ states('input_text.kallen_pickup') }} will be picking him up from school today.
{% elif is_state('input_boolean.kallen_school_early_release','on') %}
The school is on an early release schedule, pickup is at {{ input_datetime_12hr('input_datetime.kallen_school_day_end') }} today.
{% else %}
His pickup time is {{ input_datetime_12hr('input_datetime.kallen_school_day_end') }} today.
{% endif %}
{% else %}
Kallen has school at {{ input_datetime_12hr('input_datetime.kallen_school_day_start') }} today.
{% endif %}
{% elif is_state('input_boolean.school_cancelled','on') %}
School is cancelled today for Kallen.
{% elif is_state('input_boolean.kallen_school_today_extended','on') and is_state('input_boolean.kallen_school_today','off') %}
{% if (ct > wakeup) and (ct < bedtime) %}
Kallen has finished his school day.
{% endif %}
{% else %}
Kallen does not have school today.
{% endif %}
{% endif %}
{% endmacro %}
{% macro kallenStatusReport(type,method) %}
{% from 'status.jinja' import medReportKallen %}
{% if type == 'meds' %}
{{ medReportKallen() }}
{% elif type == 'school' %}
{{ schoolReportKallen(method) }}
{% elif type == 'full' %}
{{ medReportKallen() }}
{{ schoolReportKallen(method) }}
{% endif %}
{% endmacro %}