Improve E's nap info
This commit is contained in:
@ -37,21 +37,37 @@ sensor:
|
|||||||
friendly_name: Emma Nap Info
|
friendly_name: Emma Nap Info
|
||||||
unique_id: 60664690-0eb6-400a-83d5-21e56f029910
|
unique_id: 60664690-0eb6-400a-83d5-21e56f029910
|
||||||
value_template: >
|
value_template: >
|
||||||
{% set asleep = state_attr('input_datetime.emma_down_for_nap','timestamp') | int %}
|
{% macro getReport() %}
|
||||||
{% set wakeup = state_attr('input_datetime.emma_up_from_nap','timestamp') | int %}
|
{% from 'time.jinja' import input_datetime_12hr_with_date %}
|
||||||
{% set diff = (wakeup - asleep) | int %}
|
{% set asleep = state_attr('input_datetime.emma_down_for_nap','timestamp') | int %}
|
||||||
{% set hour = diff | timestamp_custom('%H', false) | int %}
|
{% set wakeup = state_attr('input_datetime.emma_up_from_nap','timestamp') | int %}
|
||||||
{% set minute = diff | timestamp_custom('%M', false) | int %}
|
{% set current = as_timestamp(now()) | int %}
|
||||||
{% set day = now().strftime("%-d") %}
|
{% set diff = (wakeup - asleep) | int %}
|
||||||
{% set asleep_day = asleep | timestamp_custom("%-d") %}
|
{% set nowHour = (current - asleep) | timestamp_custom("%-H", false) %}
|
||||||
{% set wakeup_day = wakeup | timestamp_custom("%-d") %}
|
{% set nowMin = (current - asleep) | timestamp_custom("%-M", false) %}
|
||||||
{% if is_state('input_boolean.emma_has_napped','on') or ((asleep_day == day) and (wakeup_day == day)) %}
|
{% set hour = diff | timestamp_custom('%-H', false) | int %}
|
||||||
Emma napped today for {{ hour }} hours and {{ minute }} minutes.
|
{% set minute = diff | timestamp_custom('%-M', false) | int %}
|
||||||
{% elif is_state('input_boolean.emma_has_napped','off') and ((asleep_day == day) and (wakeup_day != day)) %}
|
{% set day = now().strftime("%-d") %}
|
||||||
Emma appears to be napping currently.
|
{% set asleep_day = asleep | timestamp_custom("%-d") %}
|
||||||
{% else %}
|
{% set wakeup_day = wakeup | timestamp_custom("%-d") %}
|
||||||
Emma does not appear to have napped yet today.
|
{% if is_state('input_boolean.emma_has_napped','on') or ((asleep_day == day) and (wakeup_day == day)) %}
|
||||||
{% endif %}
|
Emma napped today for {{ hour }} hours and {{ minute }} minutes.
|
||||||
|
{% elif is_state('input_boolean.emma_has_napped','off') and ((asleep_day == day) and (wakeup_day != day)) %}
|
||||||
|
Emma appears to be napping currently. 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.
|
||||||
|
{% else %}
|
||||||
|
Emma does not appear to have napped yet today.
|
||||||
|
{% endif %}
|
||||||
|
{% endmacro %}
|
||||||
|
{%- macro cleanup(data) -%}
|
||||||
|
{%- for item in data.split("\n") if item | trim != "" -%}
|
||||||
|
{{ item | trim }} {% endfor -%}
|
||||||
|
{%- endmacro -%}
|
||||||
|
|
||||||
|
{%- macro mother_of_all_macros() -%}
|
||||||
|
{{ getReport() }}
|
||||||
|
{%- endmacro -%}
|
||||||
|
|
||||||
|
{{- cleanup(mother_of_all_macros()) -}}
|
||||||
icon_template: mdi:sleep
|
icon_template: mdi:sleep
|
||||||
|
|
||||||
automation:
|
automation:
|
||||||
|
Reference in New Issue
Block a user