Handle E's naptime vs bedtime a bit better

This commit is contained in:
2023-04-15 23:48:53 -04:00
parent 7901264a82
commit 53fa5f1101
2 changed files with 96 additions and 72 deletions

View File

@@ -4,6 +4,9 @@ input_boolean:
emma_sleeping: emma_sleeping:
name: Emma Sleeping name: Emma Sleeping
icon: mdi:sleep icon: mdi:sleep
emma_has_napped:
name: Emma Has Napped
icon: mdi:check
input_datetime: input_datetime:
emma_bedtime: emma_bedtime:
@@ -16,6 +19,16 @@ input_datetime:
has_date: false has_date: false
has_time: true has_time: true
icon: mdi:fan-off icon: mdi:fan-off
emma_down_for_nap:
name: Emma Down For Nap
has_date: true
has_time: true
icon: mdi:sleep
emma_up_from_nap:
name: Emma Up From Nap
has_date: true
has_time: true
icon: mdi:eye
automation: automation:
- id: 4f01dff7-be22-4850-a05e-1906e3151441 - id: 4f01dff7-be22-4850-a05e-1906e3151441
@@ -43,11 +56,49 @@ automation:
- condition: trigger - condition: trigger
id: sleep-on id: sleep-on
sequence: sequence:
- if:
- condition: and
conditions:
- condition: state
entity_id: input_boolean.emma_has_napped
state: 'off'
- condition: time
before: "23:00:00"
then:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_down_for_nap
data:
datetime: "{{ as_timestamp(now()) | timestamp_custom('%Y-%m-%d %H:%M:%S') }}"
- service: script.emma_sleep - service: script.emma_sleep
- conditions: - conditions:
- condition: trigger - condition: trigger
id: sleep-off id: sleep-off
sequence: sequence:
- if:
- condition: and
conditions:
- condition: state
entity_id: input_boolean.emma_has_napped
state: 'off'
- condition: time
before: "23:30:00"
then:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_up_from_nap
data:
datetime: "{{ as_timestamp(now()) | timestamp_custom('%Y-%m-%d %H:%M:%S') }}"
- delay:
milliseconds: 500
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_bedtime
data:
time: "{{ (state_attr('input_datetime.emma_up_from_nap','timestamp') + 10800) | timestamp_custom('%H:%M') }}"
- service: input_boolean.turn_on
target:
entity_id: input_boolean.emma_has_napped
- service: script.emma_wakeup - service: script.emma_wakeup
- id: '1655415573165' - id: '1655415573165'
@@ -120,46 +171,18 @@ script:
icon: mdi:lightbulb-night icon: mdi:lightbulb-night
mode: restart mode: restart
sequence: sequence:
- variables: - if:
time: "{{ states('sensor.time') }}" - condition: time
bedtime: "{{ state_attr('input_datetime.emma_bedtime','timestamp') | timestamp_custom('%H:%M', false) }}" before: '16:00:00'
then:
- service: script.emma_bedroom_scheduling_evening
# Lighting
- choose: - choose:
- conditions: - conditions:
- condition: state - condition: state
entity_id: binary_sensor.early_night_mode entity_id: binary_sensor.early_night_mode
state: 'on' state: 'on'
sequence: sequence:
- choose:
- conditions:
- condition: and
conditions:
- condition: template
value_template: "{{ time < bedtime }}"
- condition: state
entity_id: input_boolean.give_me_darkness
state: 'on'
sequence:
- service: light.turn_on
target:
entity_id:
- light.emma_bedroom_light
- delay:
seconds: 1
- service: input_select.select_option
target:
entity_id:
- input_select.emma_bedroom_scenes
data:
option: Adaptive
- conditions:
- condition: and
conditions:
- condition: template
value_template: "{{ time < bedtime }}"
- condition: state
entity_id: input_boolean.give_me_darkness
state: 'off'
sequence:
- service: light.turn_on - service: light.turn_on
target: target:
entity_id: entity_id:
@@ -182,13 +205,16 @@ script:
- service: light.turn_on - service: light.turn_on
target: target:
entity_id: light.emma_bedroom_light entity_id: light.emma_bedroom_light
- service: script.emma_bedroom_scheduling_evening # Climate
- delay:
seconds: 2
- choose: - choose:
- conditions: - conditions:
- condition: template - condition: or
value_template: "{{ time >= bedtime }}" conditions:
- condition: state
entity_id: input_boolean.emma_has_napped
state: 'on'
- condition: time
after: "23:00:00"
sequence: sequence:
- choose: - choose:
- conditions: - conditions:
@@ -230,8 +256,13 @@ script:
type: normal type: normal
tag: emma-climate tag: emma-climate
- conditions: - conditions:
- condition: template - condition: and
value_template: "{{ time < bedtime }}" conditions:
- condition: state
entity_id: input_boolean.emma_has_napped
state: 'off'
- condition: time
before: "23:00:00"
sequence: sequence:
- choose: - choose:
- conditions: - conditions:
@@ -256,13 +287,7 @@ script:
icon: mdi:weather-sunset-up icon: mdi:weather-sunset-up
mode: restart mode: restart
sequence: sequence:
- variables: # Lighting
timestamp: "{{ ((now().hour * 60 + now().minute) * 60 ) }}"
wakeup: "{{ state_attr('input_datetime.emma_wakeup','timestamp') }}"
bedtime: "{{ state_attr('input_datetime.emma_bedtime','timestamp') }}"
- service: script.turn_on
target:
entity_id: script.emma_bedroom_scheduling_evening
- choose: - choose:
- conditions: - conditions:
- condition: state - condition: state
@@ -287,14 +312,9 @@ script:
data: data:
option: Adaptive option: Adaptive
- conditions: - conditions:
- condition: or
conditions:
- condition: state - condition: state
entity_id: binary_sensor.morning entity_id: binary_sensor.early_night_mode
state: 'on' state: 'off'
- condition: state
entity_id: binary_sensor.late_morning
state: 'on'
sequence: sequence:
- service: light.turn_on - service: light.turn_on
target: target:
@@ -304,6 +324,7 @@ script:
entity_id: input_select.emma_bedroom_scenes entity_id: input_select.emma_bedroom_scenes
data: data:
option: Adaptive option: Adaptive
# Climate/White Noise
- delay: - delay:
minutes: 5 minutes: 5
- service: input_boolean.turn_off - service: input_boolean.turn_off
@@ -312,7 +333,7 @@ script:
- if: - if:
- condition: template - condition: template
value_template: >- value_template: >-
{{ is_state('fan.emma_air_conditioner','on') and is_state('input_boolean.hot_day','off') and timestamp < bedtime }} {{ is_state('fan.emma_air_conditioner','on') and is_state('input_boolean.hot_day','off') }}
then: then:
- service: script.turn_on - service: script.turn_on
target: target:
@@ -325,7 +346,7 @@ script:
sequence: sequence:
- wait_template: "{{ is_state('binary_sensor.emma_aircon_compressor','off') }}" - wait_template: "{{ is_state('binary_sensor.emma_aircon_compressor','off') }}"
timeout: timeout:
minutes: 10 minutes: 15
continue_on_timeout: true continue_on_timeout: true
- delay: - delay:
seconds: 5 seconds: 5

View File

@@ -599,6 +599,9 @@ script:
entity_id: input_datetime.emma_wakeup entity_id: input_datetime.emma_wakeup
data: data:
time: "{{ master_bedroom_wakeup }}" time: "{{ master_bedroom_wakeup }}"
- service: input_boolean.turn_off
target:
entity_id: input_boolean.emma_has_napped
- service: input_boolean.turn_on - service: input_boolean.turn_on
target: target:
entity_id: input_boolean.emma_scheduling_morning_ran entity_id: input_boolean.emma_scheduling_morning_ran