Decided to use a jinja template instead of a sensor for E's sleep info

This commit is contained in:
2023-05-02 00:55:50 -04:00
parent 75192d44fc
commit 44709dd759
7 changed files with 36 additions and 45 deletions

View File

@ -0,0 +1,23 @@
{% macro emma_sleep() %}
{% from 'time.jinja' import input_datetime_12hr_with_date %}
{% 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_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.
{% elif is_state('input_boolean.emma_sleeping','on') %}
Emma is asleep for the night.
{% else %}
Emma is awake, and does not appear to have napped yet today.
{% endif %}
{% endmacro %}