Files
Home-Assistant-Configs/packages/emmalynn.yaml

907 lines
29 KiB
YAML

# This file is for entities/automations that are specific to Emmalynn
input_boolean:
emma_sleeping:
name: Emma Sleeping
icon: mdi:sleep
emma_alternating_meds_active:
name: Emma Alternating Meds Active
icon: mdi:medication
emma_cough_meds_active:
name: Emma Cough Meds Active
icon: mdi:medication
emma_ibuprofen:
name: Emma Ibuprofen
icon: mdi:medication
emma_tylenol:
name: Emma Tylenol
icon: mdi:medication
emma_cough_meds:
name: Emma Cough Meds
icon: mdi:medication
emma_alarm_clock:
name: Emma Alarm Clock
icon: mdi:alarm
emma_awake:
name: Emma Awake
icon: mdi:eye-check
input_number:
emma_cough_meds_interval:
name: Emma Cough Meds Interval
min: 2
max: 12
step: 1
unit_of_measurement: hours
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:
emma_bedtime:
name: Emma Bedtime
has_date: false
has_time: true
icon: mdi:fan-auto
emma_bedroom_cooling:
name: Emma Bedroom Cooling
has_date: false
has_time: true
icon: mdi:fan-auto
emma_wakeup:
name: Emma Wakeup
has_date: false
has_time: true
icon: mdi:fan-off
emma_asleep_at:
name: Emma Asleep At
has_date: false
has_time: true
icon: mdi:weather-night
emma_awake_at:
name: Emma Awake At
has_date: false
has_time: true
icon: mdi:weather-sunset-up
# These are for use in remembering which medications she has had when she is sick, and when to safely give them again
emma_ibuprofen:
name: Emma Ibuprofen
has_date: true
has_time: true
icon: mdi:medication
emma_ibuprofen_notify:
name: Emma Ibuprofen Notify
has_date: false
has_time: true
icon: mdi:medication
emma_tylenol:
name: Emma Tylenol
has_date: true
has_time: true
icon: mdi:medication
emma_tylenol_notify:
name: Emma Tylenol Notify
has_date: false
has_time: true
icon: mdi:medication
emma_cough_meds:
name: Emma Cough Meds
has_date: true
has_time: true
icon: mdi:medication
emma_cough_meds_notify:
name: Emma Cough Meds Notify
has_date: false
has_time: true
icon: mdi:medication
emma_alarm_clock:
name: Emma Alarm Clock
has_date: false
has_time: true
icon: mdi:alarm
automation:
- id: 4f01dff7-be22-4850-a05e-1906e3151441
alias: 'Emma Sleeping'
description: "Handles the response to the Emma Sleeping toggle"
mode: restart
trigger:
- platform: state
entity_id: input_boolean.emma_sleeping
from: 'off'
to: 'on'
id: sleep-on
- platform: state
entity_id: input_boolean.emma_sleeping
from: 'on'
to: 'off'
id: sleep-off
condition:
- condition: state
entity_id: binary_sensor.parents_home
state: 'on'
action:
- choose:
- conditions:
- condition: trigger
id: sleep-on
sequence:
- service: script.emma_sleep
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_asleep_at
data:
time: >
{% from 'time.jinja' import current_time %}
{{ current_time('time',24) }}
- delay:
seconds: 1
- service: script.text_notify
data:
who: parents
type: alert
title: Emma Sleeping
message: >
{% from 'status.jinja' import emma_sleep_notification %}
{% from 'formatting.jinja' import cleanup %}
{{ cleanup(emma_sleep_notification()) }}
tag: emma-sleep
- conditions:
- condition: trigger
id: sleep-off
sequence:
- if:
- condition: state
entity_id: input_boolean.emma_scheduling_evening_ran
state: 'on'
then:
- service: script.turn_on
target:
entity_id: script.emma_bedroom_scheduling_evening
- service: script.text_notify
data:
who: parents
type: alert
title: Emma Awakens
message: >
{% from 'status.jinja' import emma_sleep_notification %}
{% from 'formatting.jinja' import cleanup %}
{{ cleanup(emma_sleep_notification()) }}
tag: emma-wake
- service: script.emma_wakeup
- id: '1655415573165'
alias: Emma Bedroom Handling
description: "For scheduled operations in Emma's bedroom"
mode: restart
trigger:
- platform: time
at: input_datetime.emma_wakeup
id: emma-wakeup
- platform: time
at: input_datetime.emma_bedtime
id: emma-bedtime
condition:
- condition: state
entity_id: input_boolean.vacation_mode
state: 'off'
action:
- choose:
- conditions:
- condition: trigger
id: emma-wakeup
sequence:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.emma_sleeping
- conditions:
- condition: trigger
id: emma-bedtime
sequence:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.emma_sleeping
- id: 5b45eeb2-171e-4bac-825b-8ac7aa672dab
alias: Emma Asleep Update
description: Attempt to make readouts of when Emma went to bed more accurate
mode: restart
trigger:
- platform: state
entity_id: input_boolean.emma_sleeping
from: 'off'
to: 'on'
id: initial
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.emma_bedtime_update
id: bedtime-timer-finished
- platform: state
entity_id: light.emma_bedroom_light
to: 'off'
id: lights-off
action:
- choose:
- conditions:
- condition: trigger
id: initial
sequence:
- service: timer.start
target:
entity_id: timer.emma_bedtime_update
data:
duration: "01:00:00"
- conditions:
- condition: trigger
id: lights-off
sequence:
- service: timer.cancel
target:
entity_id:
- timer.emma_bedtime_update
- if:
- condition: state
entity_id: input_boolean.emma_sleeping
state: 'on'
then:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_asleep_at
data:
time: >
{% from 'time.jinja' import current_time %}
{{ current_time('time',24) }}
- service: input_boolean.turn_off
target:
entity_id: input_boolean.emma_awake
- conditions:
- condition: trigger
id: bedtime-timer-finished
sequence:
- if:
- condition: state
entity_id: light.emma_bedroom_light
state: 'on'
then:
- delay:
seconds: 1
- service: timer.start
target:
entity_id: timer.emma_bedtime_update
data:
duration: "01:00:00"
else:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_asleep_at
data:
datetime: >
{% from 'time.jinja' import current_time %}
{{ current_time('time',24) }}
- service: input_boolean.turn_off
target:
entity_id: input_boolean.emma_awake
- id: e59f638a-519f-4619-bf7d-b13251b3a374
alias: Emma Meds Handler
description: Handles reminders for Emma taking her meds when sick or teething
mode: parallel
max: 30
trigger:
- platform: state
entity_id: input_boolean.emma_alternating_meds_active
from: 'off'
to: 'on'
id: alt-active
- platform: state
entity_id: input_boolean.emma_alternating_meds_active
from: 'on'
to: 'off'
id: alt-inactive
- platform: state
entity_id: input_boolean.emma_cough_meds_active
from: 'off'
to: 'on'
id: cough-active
- platform: state
entity_id: input_boolean.emma_cough_meds_active
from: 'on'
to: 'off'
id: cough-inactive
- platform: time
at: input_datetime.emma_ibuprofen_notify
id: ibuprofen-notify
- platform: time
at: input_datetime.emma_tylenol_notify
id: tylenol-notify
- platform: time
at: input_datetime.emma_cough_meds_notify
id: cough-notify
- platform: state
entity_id: input_boolean.emma_ibuprofen
from: 'off'
to: 'on'
id: ibuprofen-on
- platform: state
entity_id: input_boolean.emma_tylenol
from: 'off'
to: 'on'
id: tylenol-on
- platform: state
entity_id: input_boolean.emma_cough_meds
from: 'off'
to: 'on'
id: cough-on
action:
- choose:
- conditions:
- condition: trigger
id:
- alt-active
- alt-inactive
sequence:
- service: input_boolean.turn_off
target:
entity_id:
- input_boolean.emma_tylenol
- input_boolean.emma_ibuprofen
- conditions:
- condition: trigger
id:
- cough-active
- cough-inactive
sequence:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.emma_cough_meds
- conditions:
- condition: and
conditions:
- condition: trigger
id:
- ibuprofen-notify
- ibuprofen-on
- condition: state
entity_id: input_boolean.emma_alternating_meds_active
state: 'on'
sequence:
- service: script.emma_ibuprofen
data:
reason: "{{ trigger.id }}"
- conditions:
- condition: and
conditions:
- condition: trigger
id:
- tylenol-notify
- tylenol-on
- condition: state
entity_id: input_boolean.emma_alternating_meds_active
state: 'on'
sequence:
- service: script.emma_tylenol
data:
reason: "{{ trigger.id }}"
- conditions:
- condition: and
conditions:
- condition: trigger
id:
- cough-notify
- cough-on
- condition: state
entity_id: input_boolean.emma_cough_meds_active
state: 'on'
sequence:
- service: script.emma_cough_meds
data:
reason: "{{ trigger.id }}"
script:
emma_ibuprofen:
alias: Emma Ibuprofen
icon: mdi:medication
mode: queued
max: 10
sequence:
- if:
- condition: template
value_template: "{{ reason != 'ibuprofen-on' }}"
then:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.emma_ibuprofen
- choose:
- conditions: "{{ reason == 'ibuprofen-notify' and is_state('input_boolean.emma_sleeping','off') }}"
sequence:
- service: script.text_notify
data:
who: >
{% if is_state('input_boolean.work_today','on') and states('person.christina_stork') in ['Bob Evans','BobEvans'] %}
tony
{% else %}
parents
{% endif %}
type: alert
title: Emma Ibuprofen Time
message: It is time to give Emma her next dose of ibuprofen
tag: emma-ibuprofen
actions:
- action: "EMMA_IBUPROFEN_GIVEN"
title: Given
- action: "EMMA_IBUPROFEN_SKIPPED"
title: Skipped
- action: "EMMA_IBUPROFEN_ASK_LATER"
title: Ask Later
- wait_for_trigger:
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: "EMMA_IBUPROFEN_GIVEN"
id: ibuprofen-given
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: "EMMA_IBUPROFEN_SKIPPED"
id: ibuprofen-skipped
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: "EMMA_IBUPROFEN_ASK_LATER"
id: ibuprofen-ask-later
- platform: state
entity_id: input_boolean.emma_ibuprofen
from: 'off'
to: 'on'
id: ibuprofen-manual
- platform: state
entity_id: input_boolean.emma_alternating_meds_active
to: 'off'
id: cancel
timeout: "00:30:00"
continue_on_timeout: true
- choose:
- conditions: "{{ wait.trigger.id == 'ibuprofen-given' }}"
sequence:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.emma_ibuprofen
- conditions: "{{ wait.trigger.id == 'ibuprofen-skipped' }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_ibuprofen_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(8) }}
- conditions: "{{ wait.trigger.id == 'ibuprofen-ask-later' }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_ibuprofen_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(0,30) }}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_tylenol_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(4,30) }}
- conditions: "{{ wait.trigger == 'none' or wait.trigger.idx is undefined }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_ibuprofen_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(0,30) }}
- service: script.text_notify
data:
who: parents
type: alert
message: clear_notification
tag: emma-ibuprofen
- conditions: "{{ reason == 'ibuprofen-on' }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_ibuprofen
data:
datetime: >
{% from 'time.jinja' import current_time %}
{{ current_time('datetime',24) }}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_ibuprofen_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(8) }}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_tylenol_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(4) }}
emma_tylenol:
alias: Emma Tylenol
icon: mdi:medication
mode: queued
max: 10
sequence:
- if:
- condition: template
value_template: "{{ reason != 'tylenol-on' }}"
then:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.emma_tylenol
- choose:
- conditions: "{{ reason == 'tylenol-notify' and is_state('input_boolean.emma_sleeping','off') }}"
sequence:
- service: script.text_notify
data:
who: >
{% if is_state('input_boolean.work_today','on') and states('person.christina_stork') in ['Bob Evans','BobEvans'] %}
tony
{% else %}
parents
{% endif %}
type: alert
title: Emma Tylenol Time
message: It is time to give Emma her next dose of tylenol
tag: emma-tylenol
actions:
- action: "EMMA_TYLENOL_GIVEN"
title: Given
- action: "EMMA_TYLENOL_SKIPPED"
title: Skipped
- action: "EMMA_TYLENOL_ASK_LATER"
title: Ask Later
- wait_for_trigger:
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: "EMMA_TYLENOL_GIVEN"
id: tylenol-given
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: "EMMA_TYLENOL_SKIPPED"
id: tylenol-skipped
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: "EMMA_TYLENOL_ASK_LATER"
id: tylenol-ask-later
- platform: state
entity_id: input_boolean.emma_tylenol
from: 'off'
to: 'on'
id: tylenol-manual
- platform: state
entity_id: input_boolean.emma_alternating_meds_active
to: 'off'
id: cancel
timeout: "00:30:00"
continue_on_timeout: true
- choose:
- conditions: "{{ wait.trigger.id == 'tylenol-given' }}"
sequence:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.emma_tylenol
- conditions: "{{ wait.trigger.id == 'tylenol-skipped' }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_tylenol_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(8) }}
- conditions: "{{ wait.trigger.id == 'tylenol-ask-later' }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_tylenol_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(0,30) }}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_tylenol_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(4,30) }}
- conditions: "{{ wait.trigger == 'none' or wait.trigger.idx is undefined }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_tylenol_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(0,30) }}
- service: script.text_notify
data:
who: parents
type: alert
message: clear_notification
tag: emma-tylenol
- conditions: "{{ reason == 'tylenol-on' }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_tylenol
data:
datetime: >
{% from 'time.jinja' import current_time %}
{{ current_time('datetime',24) }}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_tylenol_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(8) }}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_ibuprofen_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(4) }}
emma_cough_meds:
alias: Emma Cough Meds
icon: mdi:medication
mode: queued
max: 10
sequence:
- if:
- condition: template
value_template: "{{ reason != 'cough-on' }}"
then:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.emma_cough_meds
- choose:
- conditions: "{{ reason == 'cough-notify' and is_state('input_boolean.emma_sleeping','off') }}"
sequence:
- service: script.text_notify
data:
who: >
{% if is_state('input_boolean.work_today','on') and states('person.christina_stork') in ['Bob Evans','BobEvans'] %}
tony
{% else %}
parents
{% endif %}
type: alert
title: Emma Cough Meds Time
message: It is time to give Emma her next dose of cough meds
tag: emma-cough
actions:
- action: "EMMA_COUGH_GIVEN"
title: Given
- action: "EMMA_COUGH_SKIPPED"
title: Skipped
- action: "EMMA_COUGH_ASK_LATER"
title: Ask Later
- wait_for_trigger:
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: "EMMA_COUGH_GIVEN"
id: cough-given
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: "EMMA_COUGH_SKIPPED"
id: cough-skipped
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: "EMMA_COUGH_ASK_LATER"
id: cough-ask-later
- platform: state
entity_id: input_boolean.emma_cough_meds
from: 'off'
to: 'on'
id: cough-manual
- platform: state
entity_id: input_boolean.emma_cough_meds_active
to: 'off'
id: cancel
timeout: "00:30:00"
continue_on_timeout: true
- choose:
- conditions: "{{ wait.trigger.id == 'cough-given' }}"
sequence:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.emma_cough_meds
- conditions: "{{ wait.trigger.id == 'cough-skipped' }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_cough_meds_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(4) }}
- conditions: "{{ wait.trigger.id == 'cough-ask-later' }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_cough_meds_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(0,30) }}
- conditions: "{{ wait.trigger == 'none' or wait.trigger.idx is undefined }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_cough_meds_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(0,30) }}
- service: script.text_notify
data:
who: parents
type: alert
message: clear_notification
tag: emma-cough
- conditions: "{{ reason == 'cough-on' }}"
sequence:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_cough_meds
data:
datetime: >
{% from 'time.jinja' import current_time %}
{{ current_time('datetime',24) }}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_cough_meds_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{% set interval = states('input_number.emma_cough_meds_interval') | int %}
{{ set_datetime(interval) }}
emma_wakeup:
alias: 'Emma Wakeup'
icon: mdi:weather-sunset-up
mode: restart
sequence:
# Lighting
- variables:
brightness: "{{ state_attr('switch.adaptive_lighting_emma_bedroom','brightness_pct') | int }}"
- if:
- condition: template
value_template: >
{% set current = as_timestamp(now()) | int %}
{% set lastdose = state_attr('input_datetime.emma_cough_meds','timestamp') | int %}
{% set diff = current - lastdose %}
{{ is_state('input_boolean.emma_cough_meds_active','on') and diff > 14400 }}
then:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_cough_meds_notify
data:
datetime: >
{% from 'time.jinja' import set_datetime %}
{{ set_datetime(0,5) }}
- if:
- condition: state
entity_id: binary_sensor.basement_occupied
state: 'on'
then:
- service: script.speech_engine
data:
who: basement
type: normal
message: Emma has awoken, so it is time to make your way upstairs now
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.emma_awake_at
data:
time: >
{% from 'time.jinja' import current_time %}
{{ current_time('time',24) }}
- service: switch.turn_off
target:
entity_id:
- switch.adaptive_lighting_emma_bedroom
- switch.emma_bedroom_motion_lighting
- delay:
seconds: 1
- service: light.turn_on
target:
entity_id: light.emma_bedroom_light
data:
brightness_pct: "{{ brightness|default(40) }}"
transition: >
{% from 'time.jinja' import timer_duration %}
{% if is_state('binary_sensor.early_night_mode','on') %}
{{ timer_duration('input_number.wakeup_lights_fade_night') }}
{% else %}
{{ timer_duration('input_number.wakeup_lights_fade_day') }}
{% endif %}
- wait_for_trigger:
- platform: state
entity_id: light.emma_bedroom_light
to: 'off'
id: lights-off
- platform: state
entity_id: input_select.emma_bedroom_scenes
to: 'Adaptive'
id: adaptive
timeout:
minutes: >
{% if is_state('binary_sensor.early_night_mode','on') %}
{{ states('input_number.wakeup_lights_fade_night') }}
{% else %}
5
{% endif %}
- choose:
- conditions: "{{ wait.trigger.id == 'adaptive' }}"
sequence:
- service: adaptive_lighting.set_manual_control
data:
manual_control: false
entity_id: switch.adaptive_lighting_emma_bedroom
- conditions: "{{ wait.trigger == 'none' or wait.trigger.idx is undefined }}"
sequence:
- service: input_select.select_option
target:
entity_id: input_select.emma_bedroom_scenes
data:
option: Adaptive
- service: adaptive_lighting.set_manual_control
data:
manual_control: false
entity_id: switch.adaptive_lighting_emma_bedroom
- conditions: "{{ wait.trigger.id == 'lights-off' }}"
sequence:
- service: switch.turn_on
target:
entity_id: switch.adaptive_lighting_emma_bedroom
- service: switch.turn_off
target:
entity_id: switch.adaptive_lighting_sleep_mode_emma_bedroom
- service: input_text.set_value
target:
entity_id: input_text.emma_bedroom_selected_scene
data:
value: Adaptive
- service: adaptive_lighting.set_manual_control
data:
manual_control: false
entity_id: switch.adaptive_lighting_emma_bedroom
- service: switch.turn_on
target:
entity_id: switch.emma_bedroom_motion_lighting
# Climate/White Noise
- service: input_boolean.turn_off
target:
entity_id: input_boolean.white_noise_emma_bedroom