First attempts at some context-aware announcements

This commit is contained in:
2022-04-04 17:48:50 -04:00
parent f2e0076b7b
commit d1bc612a12
4 changed files with 338 additions and 1 deletions

View File

@ -0,0 +1,4 @@
kallen_school:
name: Kallen at School
good_morning_report:
name: Good Morning Report

View File

@ -61,4 +61,28 @@ automation:
state: 'on'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.audible_notifications
entity_id: input_boolean.audible_notifications
script:
reset_annc_switches:
sequence:
- service: input_boolean.turn_off
entity_id: input_boolean.good_morning_report
morning_briefing:
sequence:
- service: button.press
target:
entity_id: button.good_morning
kallen_nightly_briefing:
sequence:
- service: script.local_audio
data_template:
media: "/media/music/ES_RiserSuction5.mp3"
volume: .5
speaker: 'media_player.basement_echo_dot'
- service: script.text_notify
data_template:
who: "all_ios"
message: "Time for Kallen to get ready for bed."

180
packages/audio.yaml Normal file
View File

@ -0,0 +1,180 @@
################################
# Media Player section for any media players you want to define. Most of these are setup via the integrations flow in the UI,
# but if not you may need to modify the following section.
# For more info on Media Players visit https://www.home-assistant.io/integrations/media_player/
# MODIFY this section as needed or comment it out completely if not needed.
# media_player:
# - platform: yamaha
# host: 192.168.7.152
################################
# Media extractor is used for playing youtube audio. For more info ->https://www.home-assistant.io/integrations/media_extractor/
#
# If you have this enabled in another package or in your configuration.yaml comment out the line below
media_extractor:
############################
# input_datetime (https://www.home-assistant.io/integrations/input_datetime/)
#
# This is simply so we can track last called alexa.
input_datetime:
last_time_alexa_called:
name: Last Time Alexa Called
has_date: true
has_time: true
################################
# Scripts to handle audio
script:
################################
# local_audio is meant to be used to play audio in your media folder. (https://www.home-assistant.io/integrations/media_source/)
#
# Before using make sure you update as needed.
#
# To call this using in the action section of your automation:
#
# - service: script.local_audio
# data:
# speaker: main
# volume: .5
# media: /media/local_audio.mp3
#
local_audio:
sequence:
# Ensure that audible notifications are allowed. Comment out if not needed.
- condition: state
entity_id: input_boolean.audible_notifications
state: 'on'
# Ensure the family is home. If you are using a group to track the family, or a person just update as needed. Comment out if not needed.
- condition: state
entity_id: group.family
state: 'home'
# Update the media player with the one you want to use
- service: media_player.turn_on
data:
entity_id: >
{{ speaker }}
# This sets the voume via a parameter when the script is called, and should be a value between .1 and 1.0
- service: media_player.volume_set
data:
entity_id: >
{{ speaker }}
volume_level: >
{{ volume }}
- delay: 00:00:05
# This tells it to play the media and is set when the script is called.
- service: media_player.play_media
data:
entity_id: >
{{ speaker }}
media_content_type: "music"
media_content_id: >
{{ media }}
################################
# youtube_audio is meant to be used to play audio from well youtube.
# This scrtip requires the media_extractor integration.
#
# Before using make sure you update as needed.
#
# To call this using in the action section of your automation:
#
# - service: script.youtube_audio
# data:
# speaker: main
# volume: .5
# media: https://www.youtube.com/watch?v=pVeX4C9B1Lk
#
youtube_audio:
sequence:
# Ensure that audible notifications are allowed. Comment out if not needed.
- condition: state
entity_id: input_boolean.audible_notifications
state: 'on'
# Ensure the family is home. If you are using a group to track the family, or a person just update as needed. Comment out if not needed.
- condition: state
entity_id: group.family
state: 'home'
# Update the media player with the one you want to use
- service: media_player.turn_on
data:
entity_id: >
{{ speaker }}
# This sets the voume via a parameter when the script is called, and should be a value between .1 and 1.0
- service: media_player.volume_set
data:
entity_id: >
{{ speaker }}
volume_level: >
{{ volume }}
# This tells it to play the media and is set when the script is called.
# media_content_type: video/Youtube
- service: media_extractor.play_media
data:
entity_id: >
{{ speaker }}
media_content_type: music
media_content_id: >
{{ media }}
automation:
- id: e1cb17ea-0423-11eb-adc1-0242ac120002
alias: Set Last Alexa Called Time
initial_state: true
trigger:
- platform: state
entity_id:
- media_player.living_room_echo_dot
- media_player.basement_echo_dot
- media_player.master_bedroom_echo_dot
condition:
- condition: template
value_template: '{{ trigger.to_state.attributes.last_called_timestamp | float > trigger.from_state.attributes.last_called_timestamp | float }}' # Alexa has been triggered
action:
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.last_time_alexa_called
data:
datetime: '{{ now().strftime(''%Y-%m-%d %H:%M:%S'') }}'
- id: e1cb2fdc-0423-11eb-adc1-0242ac120002
alias: Set Room Presence
mode: restart
trigger:
- platform: state
entity_id: sensor.room_audio
action:
- service: input_text.set_value
data_template:
entity_id: input_text.room_presence
value: '{{ states(''sensor.room_audio'') }}'
- service: mqtt.publish
data:
topic: house/presence/current_room
payload: '{{ states(''sensor.room_audio'') }}'
retain: true
sensor:
- platform: mqtt
name: "Room Presence"
state_topic: "house/presence/current_room"
- platform: template
sensors:
alexa_audio:
friendly_name: "Alexa Audio"
value_template: >-
{%- if is_state('sensor.last_alexa', 'media_player.living_room_echo_dot') %}
living_room
{% elif is_state('sensor.last_alexa', 'media_player.basement_echo_dot') %}
basement
{% elif is_state('sensor.last_alexa', 'media_player.master_bedroom_echo_dot') %}
master_bedroom
{% else %}
everywhere
{%- endif %}
last_alexa:
value_template: >
{{ states.media_player | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}

129
packages/presence.yaml Normal file
View File

@ -0,0 +1,129 @@
input_datetime:
last_time_home_tony:
name: Tony Last Seen
has_date: true
has_time: true
last_time_home_tina:
name: Tina Last Seen
has_date: true
has_time: true
last_time_home_kallen:
name: Kallen Last Seen
has_date: true
has_time: true
proximity:
home_tony:
devices:
- device_tracker.tony_s_iphone
zone: home
tolerance: 5
unit_of_measurement: mi
home_tina:
devices:
- device_tracker.tinas_iphone
zone: home
tolerance: 5
unit_of_measurement: mi
home:
devices:
- device_tracker.tony_s_iphone
- device_tracker.tinas_iphone
zone: home
tolerance: 5
unit_of_measurement: mi
sensor:
- platform: mqtt
name: "Family Status"
state_topic: "house/family/status"
payload_available: "online"
payload_not_available: "offline"
- platform: mqtt
name: "Family Arrived"
state_topic: "house/family/arrived"
payload_available: "online"
payload_not_available: "offline"
- platform: template
sensors:
tony_home:
value_template: >-
{{ is_state('device_tracker.tony_s_iphone', 'home') or is_state('device_tracker.tony_s_iphone_app', 'home') }}
- platform: template
sensors:
tina_home:
value_template: >-
{{ is_state('device_tracker.tinas_iphone', 'home') or is_state('device_tracker.tinas_iphone_app', 'home') }}
automation:
- id: kallen_at_school
alias: Kallen is at School
trigger:
- entity_id: person.tony_stork
event: leave
platform: zone
zone: zone.school
- entity_id: person.christina_stork
event: leave
platform: zone
zone: zone.school
- entity_id: person.kallen_stork
event: enter
platform: zone
zone: zone.school
condition:
- condition: time
before: "11:30:00"
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: input_boolean.kallen_school
state: "off"
action:
- service: input_boolean.turn_on
entity_id: input_boolean.kallen_school
- service: script.text_alert
data:
who: parents
message: "Kallen has been dropped off at school."
initial_state: true
- id: kallen_left_school
alias: Kallen left School
trigger:
- entity_id: person.tony_stork
event: leave
platform: zone
zone: zone.school
- entity_id: person.christina_stork
event: leave
platform: zone
zone: zone.school
- entity_id: person.kallen_stork
event: leave
platform: zone
zone: zone.school
condition:
- condition: time
after: "11:30:02"
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: input_boolean.kallen_school
state: "on"
action:
- service: input_boolean.turn_off
entity_id: input_boolean.kallen_school
- service: script.text_alert
data:
who: parents
message: "Kallen has been picked up from school."
initial_state: true