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') }}"
- platform: state
-
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') }}"
- platform: state
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