Protect active audio during evening and overnight routines

master
Carlo Costanzo 1 day ago
parent d3745fd838
commit 8a830b7b07

@ -3,8 +3,8 @@
# For more info visit https://www.vcloudinfo.com/click-here
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# Automation for 10:00 PM tasks - This automation handles various actions that need to occur at 10 PM.
# Defines the Automation for 10:00 PM tasks triggers, conditions, and actions.
# 10 p.m. amp shutdown - Wait for quiet before the nightly checks and power-off.
# Leave the amp on if either audio source stays busy or stops reporting.
# -------------------------------------------------------------------
######################################################################
- alias: 'Shut down AMP in Living room'
@ -20,24 +20,27 @@
{{ not is_state('input_boolean.guest_mode', 'on') or is_state('group.bed', 'on') }}
timeout: "08:00:00"
continue_on_timeout: false
- wait_template: >-
{{ not is_state('media_player.livingroomCC', 'playing') }}
timeout: "02:00:00"
continue_on_timeout: true
- wait_template: >-
{{ not is_state('media_player.everywhere', 'playing') }}
- alias: Wait for both audio sources before requesting the briefing
wait_template: &amp_quiet >-
{% from 'amp_playback.jinja' import amp_is_quiet %}
{{ (amp_is_quiet | as_function)() }}
timeout: "02:00:00"
continue_on_timeout: true
continue_on_timeout: false
- service: script.speech_engine
data:
call_no_announcement: 1
call_garage_check: 1
call_window_check: 1
protect_amp_playback: true
- wait_template: >-
{{ not is_state('media_player.livingroomCC', 'playing') }}
# Give Cast time to report the start of a dispatched announcement.
- delay: "00:00:05"
- wait_template: *amp_quiet
timeout: "00:10:00"
continue_on_timeout: true
- service: switch.turn_off
entity_id: switch.lr_amp
continue_on_timeout: false
- condition: template
value_template: *amp_quiet
- action: switch.turn_off
target:
entity_id: switch.lr_amp

@ -3,8 +3,8 @@
# For more info visit https://www.vcloudinfo.com/click-here
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# Stuff that needs to happen after 10pm - Home Assistant automation behavior.
# Defines the Stuff that needs to happen after 10pm triggers, conditions, and actions.
# Night watchdogs - Living-room amplifier and bedroom screensaver.
# Shut off the amp when household conditions allow and both audio sources are quiet.
# -------------------------------------------------------------------
######################################################################
- alias: Automated NIGHT WatchDog!
@ -15,7 +15,7 @@
to: 'on'
for: '00:10:00'
- platform: state
entity_id: media_player.livingroomCC
entity_id: media_player.livingroomcc
to: 'off'
for: '00:02:00'
- platform: state
@ -52,9 +52,17 @@
state: 'on'
action:
- service: switch.turn_off
data:
entity_id: "{{ trigger.entity_id }}"
- alias: Only shut off the amp when both audio sources are off or idle
condition: state
entity_id:
- media_player.livingroomcc
- media_player.everywhere
state:
- 'off'
- 'idle'
- action: switch.turn_off
target:
entity_id: switch.lr_amp
- alias: 'Bedroom Screensaver Watchdog'

@ -8,6 +8,7 @@
# -------------------------------------------------------------------
# Notes: SleepIQ recovery from `unavailable` is not treated as a bed entry;
# amp wake-up requires both bed sensors to report explicit `off`.
# Bedtime shutdown leaves active or unconfirmed amp playback alone.
######################################################################
- alias: 'Good Night Trigger'
@ -65,6 +66,8 @@
- switch.alarm_panel_1_motion_detection
- light.ikea_1 #Upstairs Hallyway switchoutlet.
- service: script.interior_off
data:
protect_amp_playback: true
- service: number.set_value
target:
entity_id: number.alarm_panel_1_screen_brightness
@ -95,9 +98,15 @@
entity_id: group.bed
state: 'on'
sequence:
- service: homeassistant.turn_off
target:
entity_id: switch.lr_amp
- if:
- condition: template
value_template: >-
{% from 'amp_playback.jinja' import amp_is_quiet %}
{{ (amp_is_quiet | as_function)() }}
then:
- action: switch.turn_off
target:
entity_id: switch.lr_amp
- service: homeassistant.turn_off
target:
entity_id:

@ -0,0 +1,5 @@
{# Both Cast and the Everywhere group can feed the living-room amplifier. #}
{% macro amp_is_quiet(returns) -%}
{% do returns(is_state('media_player.livingroomcc', ['off', 'idle'])
and is_state('media_player.everywhere', ['off', 'idle'])) %}
{%- endmacro %}

@ -11,11 +11,16 @@
######################################################################
interior_off:
sequence:
- service: homeassistant.turn_off
entity_id:
- group.interior_lights
- group.interior_switches
- switch.lr_amp
- group.tvs
- action: homeassistant.turn_off
target:
entity_id: >-
{% from 'amp_playback.jinja' import amp_is_quiet %}
{% if protect_amp_playback | default(false) and not (amp_is_quiet | as_function)() %}
{% set media_power = ['switch.lr_amp', 'switch.living_room_tv_outlet'] %}
{{ ['group.interior_lights'] + (expand('group.interior_switches')
| map(attribute='entity_id') | reject('in', media_power) | list) }}
{% else %}
{{ ['group.interior_lights', 'group.interior_switches', 'switch.lr_amp', 'group.tvs'] }}
{% endif %}
- service: script.paige_lights_off # C by GE Lights (https://amzn.to/30w3UWy)
# - service: script.noon_lights_off # Noon Home Smart Lights (https://amzn.to/3fOIPx6)

@ -42,6 +42,7 @@ speech_engine:
# Run the "script.speech_processing" service with the specified media player and speech message
- service: script.speech_processing
data:
protect_amp_playback: "{{ protect_amp_playback | default(false) }}"
# Set the entity ID for the media players to be controlled
# If the "media_player" variable is not defined, set it to a list of media player entities
# If the "media_player" variable is a list, convert it to a comma-separated string

@ -57,9 +57,17 @@ speech_processing:
entity_id: input_boolean.speech_notifications
state: 'on'
- alias: Check for playback after the speech queue
condition: template
value_template: &playback_allowed >-
{% from 'amp_playback.jinja' import amp_is_quiet %}
{{ not (protect_amp_playback | default(false)) or (amp_is_quiet | as_function)() }}
- service: switch.turn_on
entity_id: switch.lr_amp
- alias: Check again before changing the volume
condition: template
value_template: *playback_allowed
- service: media_player.volume_set
data:
entity_id: >
@ -88,6 +96,9 @@ speech_processing:
- variables:
speech_response: "{{ agent.response.speech.plain.speech }}"
- alias: Recheck playback after generating the announcement
condition: template
value_template: *playback_allowed
- service: tts.cloud_say
data:
entity_id: >
@ -102,6 +113,8 @@ speech_processing:
- conditions:
- condition: template
value_template: "{{ 'media_player.garage' not in routed_media_players }}"
- condition: template
value_template: "{{ not (protect_amp_playback | default(false)) or is_state('media_player.garage', ['off', 'idle', 'standby']) }}"
sequence:
- service: notify.alexa_media_garage
continue_on_error: true
@ -117,6 +130,8 @@ speech_processing:
state: 'on'
- condition: template
value_template: "{{ 'media_player.office' not in routed_media_players }}"
- condition: template
value_template: "{{ not (protect_amp_playback | default(false)) or is_state('media_player.office', ['off', 'idle', 'standby']) }}"
sequence:
- service: notify.alexa_media_office
continue_on_error: true

Loading…
Cancel
Save

Powered by TurnKey Linux.