#Sleep tracking using owlet sock

1 messages · Page 1 of 1 (latest)

mossy escarp
#

Hi all,
Trying to make a sleep tracking card using my children owlet socks that show ammount time slept and awake.
The images show my current set up and issues I have had trying to set up using history-graph.

Thankyou

I have also research and tried the following Yaml code.

automation:

  • alias: "Start Sleep When Owlet Detects Asleep"
    trigger:

    • platform: state
      entity_id: sensor.owlet_baby_care_sock_sleep_state
      to: "asleep"
      action:
    • service: input_datetime.set_datetime
      data:
      entity_id: input_datetime.sleep_start
      datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
  • alias: "End Sleep When Owlet Detects Awake"
    trigger:

    • platform: state
      entity_id: sensor.owlet_baby_care_sock_sleep_state
      to: "awake"
      action:
    • service: input_datetime.set_datetime
      data:
      entity_id: input_datetime.sleep_end
      datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"

sensor:

  • platform: template
    sensors:
    sleep_duration:
    friendly_name: "Sleep Duration"
    unit_of_measurement: "minutes"
    value_template: >
    {% set start = states('input_datetime.sleep_start') %}
    {% set end = states('input_datetime.sleep_end') %}
    {% if start and end %}
    {{ (end - start).total_seconds() / 60 }}
    {% else %}
    0
    {% endif %}

  • platform: template
    sensors:
    awake_duration:
    friendly_name: "Awake Duration"
    unit_of_measurement: "minutes"
    value_template: >
    {% set end = states('input_datetime.sleep_end') %}
    {% if end %}
    {{ (now() - end).total_seconds() / 60 }}
    {% else %}
    0
    {% endif %}

dashboard:

  • type: entities
    entities:

    • sensor.sleep_duration
    • sensor.awake_duration
  • type: history-graph
    entities:

    • sensor.sleep_duration
    • sensor.awake_duration
exotic scarab
#

When you use states(...) to reference an entity in the value_template:, it returns a string. You can't subtract a string from a string or datetime. Just use states(...) | as_datetime to convert the output of states(...) to datetime.

mossy escarp
#

Sorry just seen this I have progressed it still not working

#

This is were I am at now

mossy escarp
#

type: custom:apexcharts-card
chart_type: donut
header:
show: true
show_states: true
colorize_states: true
title: Harlan sleep
series:

entity: sensor.owlet_baby_care_sock_sleep_state
name: Harlan owlet sock
type: column
color: darkviolet

#

Just can't figure out now how to track the sleep states that's in attributes