Decided to use a jinja template instead of a sensor for E's sleep info
This commit is contained in:
@ -112,7 +112,6 @@ recorder:
|
|||||||
- sensor.time_utc
|
- sensor.time_utc
|
||||||
- sensor.hacs
|
- sensor.hacs
|
||||||
- sensor.mariadb_database_size
|
- sensor.mariadb_database_size
|
||||||
- sensor.emma_nap_info
|
|
||||||
include:
|
include:
|
||||||
entities:
|
entities:
|
||||||
- media_player.living_room_tv
|
- media_player.living_room_tv
|
||||||
@ -167,7 +166,6 @@ influxdb:
|
|||||||
- sensor.xr500_gateway_kib_s_sent
|
- sensor.xr500_gateway_kib_s_sent
|
||||||
- light.all_lights
|
- light.all_lights
|
||||||
- fan.all_fans
|
- fan.all_fans
|
||||||
- sensor.emma_nap_info
|
|
||||||
include:
|
include:
|
||||||
domains:
|
domains:
|
||||||
- sun
|
- sun
|
||||||
|
4
custom_templates/formatting.jinja
Normal file
4
custom_templates/formatting.jinja
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{%- macro cleanup(data) -%}
|
||||||
|
{%- for item in data.split("\n") if item | trim != "" -%}
|
||||||
|
{{ item | trim }} {% endfor -%}
|
||||||
|
{%- endmacro -%}
|
23
custom_templates/status.jinja
Normal file
23
custom_templates/status.jinja
Normal 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 %}
|
@ -30,46 +30,6 @@ input_datetime:
|
|||||||
has_time: true
|
has_time: true
|
||||||
icon: mdi:eye
|
icon: mdi:eye
|
||||||
|
|
||||||
sensor:
|
|
||||||
- platform: template
|
|
||||||
sensors:
|
|
||||||
emma_nap_info:
|
|
||||||
friendly_name: Emma Nap Info
|
|
||||||
unique_id: 60664690-0eb6-400a-83d5-21e56f029910
|
|
||||||
value_template: >
|
|
||||||
{% macro getReport() %}
|
|
||||||
{% 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.
|
|
||||||
{% 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
|
|
||||||
|
|
||||||
automation:
|
automation:
|
||||||
- id: 4f01dff7-be22-4850-a05e-1906e3151441
|
- id: 4f01dff7-be22-4850-a05e-1906e3151441
|
||||||
alias: 'Emma Sleeping'
|
alias: 'Emma Sleeping'
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
{%- macro getReport() -%}
|
{%- macro getReport() -%}
|
||||||
{% from 'speech.jinja' import greeting, dadjoke, inspirational_quote %}
|
{% from 'speech.jinja' import greeting, dadjoke, inspirational_quote %}
|
||||||
{% from 'time.jinja' import input_datetime_12hr %}
|
{% from 'time.jinja' import input_datetime_12hr %}
|
||||||
|
{% from 'status.jinja' import emma_sleep %}
|
||||||
|
{% from 'formatting.jinja' import cleanup %}
|
||||||
<p>
|
<p>
|
||||||
{{ greeting() }}
|
{{ greeting() }}
|
||||||
</p>
|
</p>
|
||||||
@ -359,7 +361,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{{ states('sensor.emma_nap_info') }}
|
{{ cleanup(emma_sleep()) }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
{%- macro getReport() -%}
|
{%- macro getReport() -%}
|
||||||
{% from 'speech.jinja' import greeting, dadjoke, inspirational_quote %}
|
{% from 'speech.jinja' import greeting, dadjoke, inspirational_quote %}
|
||||||
{% from 'time.jinja' import input_datetime_12hr, read_time_from_calendar %}
|
{% from 'time.jinja' import input_datetime_12hr, read_time_from_calendar %}
|
||||||
|
{% from 'status.jinja' import emma_sleep %}
|
||||||
|
{% from 'formatting.jinja' import cleanup %}
|
||||||
<p>
|
<p>
|
||||||
{{ greeting() }}
|
{{ greeting() }}
|
||||||
</p>
|
</p>
|
||||||
@ -222,7 +224,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{{ states('sensor.emma_nap_info') }}
|
{{ cleanup(emma_sleep()) }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
{%- macro getReport() -%}
|
{%- macro getReport() -%}
|
||||||
{% from 'speech.jinja' import dadjoke %}
|
{% from 'speech.jinja' import dadjoke %}
|
||||||
{% from 'time.jinja' import input_datetime_12hr %}
|
{% from 'time.jinja' import input_datetime_12hr %}
|
||||||
|
{% from 'status.jinja' import emma_sleep %}
|
||||||
|
{% from 'formatting.jinja' import cleanup %}
|
||||||
<p>
|
<p>
|
||||||
"Welcome home, "
|
"Welcome home, "
|
||||||
{% if is_state('person.tony_stork','home') and is_state('person.christina_stork','home') %}
|
{% if is_state('person.tony_stork','home') and is_state('person.christina_stork','home') %}
|
||||||
@ -149,7 +151,7 @@
|
|||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{{ states('sensor.emma_nap_info') }}
|
{{ cleanup(emma_sleep()) }}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
Reference in New Issue
Block a user