Hi all,
I am using the Withings Sleep mat - overall it seems to be working well. However, when add the entity sensors for the sleep metrics, it is adding each nights sleep data. I would rather just see last nights sleep data and log the rest in history. An example…
I swear I did not sleep 16 hours last night! I did however sleep this long over 2 nights. Below is an example of a custom sensor entity where I convert the returned Withings sensor data from seconds to minutes and hours…
sleep_deep:
friendly_name: 'Deep Sleep'
value_template: >-
{% set dstime = states.sensor.withings_sleep_deep_duration_seconds_brad.state | int %}
{% set seconds = dstime % 60 %}
{% set minutes = ((dstime % 3600) / 60) | int %}
{% set hours = ((dstime % 86400) / 3600) | int %}
{% set days = (dstime / 86400) | int %}
{%- if days > 0 -%}
{%- if days == 1 -%}
1 day
{%- else -%}
{{ days }} days
{%- endif -%}
{{ ', ' }}
{%- endif -%}
{%- if hours > 0 -%}
{%- if hours == 1 -%}
1 hour
{%- else -%}
{{ hours }} hours
{%- endif -%}
{{ ', ' }}
{%- endif -%}
{%- if minutes > 0 -%}
{%- if minutes == 1 -%}
1 minute
{%- else -%}
{{ minutes }} minutes
{%- endif -%}
{%- endif -%}
icon_template: mdi:sleep
I am guessing I somehow need to add some logic to limit the sensor date between times (say 8pm to 9am or similar) - but I cannot for the life of me figure out how to do this. I am hoping someone will be kind enough to share their wisdom and point me in the right direction. Thanks in advance.