diff --git a/custom_templates/status.jinja b/custom_templates/status.jinja index 70ba779..d239645 100644 --- a/custom_templates/status.jinja +++ b/custom_templates/status.jinja @@ -11,7 +11,7 @@ {% 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_has_napped','on') or ((asleep_day == day) and (wakeup_day == day)) %} +{% 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 {{ hour }} hours and {{ minute }} minutes. 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 {{ nowHour }} hours and {{ nowMin }} minutes. @@ -20,4 +20,30 @@ {% else %} Emma is awake, and does not appear to have napped yet today. {% endif %} +{% endmacro %} + +{% macro emma_sleep_notification() %} +{% from 'time.jinja' import input_datetime_12hr_with_date, current_time_12hr %} +{% 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 current = as_timestamp(now()) | int %} +{% set diff = (wakeup - asleep) | int %} +{% set nowHour = (current - asleep) | timestamp_custom("%-H", false) %} +{% set nowMin = (current - asleep) | timestamp_custom("%-M", false) %} +{% set hour = diff | timestamp_custom('%-H', false) | int %} +{% set minute = diff | timestamp_custom('%-M', false) | 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 {{ hour }} hours and {{ minute }} minutes. She was retrieved from her room at {{ input_datetime_12hr_with_date('input_datetime.emma_up_from_nap') }} +{% 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 {{ current_time_12hr }} +{% 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 {{ input_datetime_12hr_with_date('input_datetime.emma_down_for_nap') }} +{% elif is_state('input_boolean.emma_sleeping','on') %} + Emma is asleep for the night at {{ current_time_12hr() }} +{% else %} + Emma is awake, and does not appear to have napped yet today, and I am not sure why you are being notified of this. +{% endif %} {% endmacro %} \ No newline at end of file diff --git a/packages/emmalynn.yaml b/packages/emmalynn.yaml index 097267f..c36949a 100644 --- a/packages/emmalynn.yaml +++ b/packages/emmalynn.yaml @@ -56,6 +56,7 @@ automation: - condition: trigger id: sleep-on sequence: + - service: script.emma_sleep - if: - condition: and conditions: @@ -71,7 +72,18 @@ automation: entity_id: input_datetime.emma_down_for_nap data: datetime: "{{ as_timestamp(now()) | timestamp_custom('%Y-%m-%d %H:%M:%S') }}" - - service: script.emma_sleep + - delay: + seconds: 1 + - service: script.text_notify + data: + who: parents + type: alert + title: Emma Sleeping + message: > + {% from 'status.jinja' import emma_sleep_notification %} + {% from 'formatting.jinja' import cleanup %} + {{ cleanup(emma_sleep_notification()) }} + tag: emma-sleep - conditions: - condition: trigger id: sleep-off @@ -111,6 +123,18 @@ automation: - service: input_boolean.turn_on target: entity_id: input_boolean.emma_has_napped + - delay: + seconds: 1 + - service: script.text_notify + data: + who: parents + type: alert + title: Emma Awakens + message: > + {% from 'status.jinja' import emma_sleep_notification %} + {% from 'formatting.jinja' import cleanup %} + {{ cleanup(emma_sleep_notification()) }} + tag: emma-wake - service: script.emma_wakeup - id: '1655415573165'