Several improvements to E's bedtime scheduling

This commit is contained in:
2024-05-23 17:07:23 -04:00
parent d29acd787b
commit ee53a35965
3 changed files with 59 additions and 33 deletions

View File

@ -5022,3 +5022,35 @@
tag: emma-climate tag: emma-climate
alias: Send AC notification alias: Send AC notification
mode: restart mode: restart
- id: '1716497196985'
alias: Emma Bedtime Rescheduler
description: Keeps Emma's bedtime up-to-date with reality
trigger:
- platform: state
entity_id:
- input_datetime.emma_awake_at
id: first-wake
alias: First Wake
- platform: state
entity_id:
- input_number.emma_bedtime_hours
id: hours-update
alias: Hours Update
- platform: state
entity_id:
- input_datetime.emma_up_from_nap
id: up-from-nap
alias: Up From Nap
condition:
- condition: state
entity_id: input_boolean.emma_sleeping
state: 'off'
- condition: state
entity_id: input_boolean.emma_scheduling_evening_ran
state: 'on'
action:
- service: script.emma_bedroom_scheduling_evening
metadata: {}
data: {}
alias: Run evening scheduling
mode: restart

View File

@ -37,6 +37,13 @@ input_number:
step: 1 step: 1
unit_of_measurement: hours unit_of_measurement: hours
icon: mdi:medication icon: mdi:medication
emma_bedtime_hours:
name: Emma Bedtime Hours
min: 8
max: 12
step: 1
unit_of_measurement: hours
icon: mdi:bed-clock
input_datetime: input_datetime:
emma_bedtime: emma_bedtime:
@ -189,6 +196,9 @@ automation:
after: "17:30:00" after: "17:30:00"
before: "01:00:00" before: "01:00:00"
then: then:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.emma_has_napped
- service: input_datetime.set_datetime - service: input_datetime.set_datetime
target: target:
entity_id: input_datetime.emma_up_from_nap entity_id: input_datetime.emma_up_from_nap
@ -196,33 +206,6 @@ automation:
datetime: > datetime: >
{% from 'time.jinja' import current_time %} {% from 'time.jinja' import current_time %}
{{ current_time('datetime',24) }} {{ current_time('datetime',24) }}
- delay:
milliseconds: 500
- if:
- condition: template
value_template: >
{% from 'time.jinja' import ct %}
{% set ct = ct() | int %}
{% set proposed = ct + 10800 %}
{{ proposed < 82800 }}
then:
- service: script.emma_bedroom_scheduling_evening
else:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_bedtime
data:
time: "{{ (state_attr('input_datetime.emma_up_from_nap','timestamp') + 14400) | timestamp_custom('%H:%M') }}"
- delay:
milliseconds: 500
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_bedroom_cooling
data:
time: "{{ state_attr('input_datetime.emma_bedtime','timestamp') | int - 3600 }}"
- service: input_boolean.turn_on
target:
entity_id: input_boolean.emma_has_napped
- delay: - delay:
seconds: 1 seconds: 1
- service: script.text_notify - service: script.text_notify
@ -305,7 +288,7 @@ automation:
{% endif %} {% endif %}
- id: 5b45eeb2-171e-4bac-825b-8ac7aa672dab - id: 5b45eeb2-171e-4bac-825b-8ac7aa672dab
alias: Emma Bedtime Update alias: Emma Asleep Update
description: Attempt to make readouts of when Emma went to bed more accurate description: Attempt to make readouts of when Emma went to bed more accurate
mode: restart mode: restart
trigger: trigger:

View File

@ -110,7 +110,7 @@ automation:
at: '04:00:00' at: '04:00:00'
id: morning-scheduling id: morning-scheduling
- platform: time - platform: time
at: '17:00:00' at: '17:05:00'
id: evening-scheduling id: evening-scheduling
action: action:
- choose: - choose:
@ -710,7 +710,17 @@ script:
- service: input_datetime.set_datetime - service: input_datetime.set_datetime
entity_id: input_datetime.emma_bedtime entity_id: input_datetime.emma_bedtime
data: data:
time: 02:00 time: >
{% set awake = state_attr('input_datetime.emma_awake_at','timestamp') | int %}
{% set up_from_nap = state_attr('input_datetime.emma_up_from_nap','timestamp') | int %}
{% set hours = states('input_number.emma_bedtime_hours') | int %}
{% set math = (hours * 60) * 60 %}
{% set math_nap = 14400 %}
{% if is_state('input_boolean.emma_has_napped','on') %}
{{ (up_from_nap + math_nap) | timestamp_custom('%H:%M') }}
{% else %}
{{ (awake + math) | timestamp_custom('%H:%M',false) }}
{% endif %}
- if: - if:
- condition: state - condition: state
entity_id: input_boolean.emma_bedroom_climate_override entity_id: input_boolean.emma_bedroom_climate_override
@ -737,12 +747,13 @@ script:
time: > time: >
{% set high = states('sensor.todays_high_temp') | int %} {% set high = states('sensor.todays_high_temp') | int %}
{% set low = states('sensor.overnight_lowest_temperature') | int %} {% set low = states('sensor.overnight_lowest_temperature') | int %}
{% set bedtime = state_attr('input_datetime.emma_bedtime','timestamp') | int %}
{% if is_state('input_boolean.hot_day','on') %} {% if is_state('input_boolean.hot_day','on') %}
23:00 {{ (bedtime - 7200) | timestamp_custom('%H:%M',false) }}
{% elif high >= 80 or low >= 60 %} {% elif high >= 80 or low >= 60 %}
00:00 {{ (bedtime - 5400) | timestamp_custom('%H:%M',false) }}
{% else %} {% else %}
01:00 {{ (bedtime - 3600) | timestamp_custom('%H:%M',false) }}
{% endif %} {% endif %}
- service: input_boolean.turn_on - service: input_boolean.turn_on
target: target: