Files
Home-AssistantConfig/config/script/speech_processing.yaml

137 lines
4.5 KiB
YAML
Raw Permalink Normal View History

######################################################################
# @CCOSTAN - Follow Me on X
# For more info visit https://www.vcloudinfo.com/click-here
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# Speech Processing Script - shared spoken announcement delivery
# Sends OpenAI-polished speech to Chromecast targets and routed Echo announcements.
# -------------------------------------------------------------------
# Related Issue: 798
# Notes: Operates only when family/guest/vacation and speech notification
# guards allow it, with time-aware volume.
# Notes: Set `speech_direct: true` for exact visitor-facing announcements that should not be rewritten by the LLM.
# Notes: Garage Echo is an always-on announcement target. Office Echo is
# added when switch.office_lamp_switch is on, which tracks active PC work.
######################################################################
2018-01-01 19:00:45 -05:00
speech_processing:
mode: queued
2018-01-01 19:00:45 -05:00
sequence:
- event: openai_instructions_sent
event_data:
instructions: "{{ speech_message | striptags }}"
- variables:
direct_speech: "{{ speech_direct | default(false) | bool }}"
routed_media_players: "{{ media_player | string | lower }}"
speech_response: "{{ speech_message | striptags | trim }}"
2018-01-01 19:00:45 -05:00
- condition: and
conditions:
- condition: or
conditions:
- condition: state
entity_id: group.family
state: 'home'
- condition: state
entity_id: input_boolean.guest_mode
state: 'on'
- condition: state
entity_id: input_boolean.vacation_mode
state: 'on'
2018-01-01 19:00:45 -05:00
- condition: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: group.bed
state: 'off'
- condition: time
after: '08:00:00'
2024-09-25 15:51:00 +00:00
before: '22:00:00'
2018-01-01 19:00:45 -05:00
- condition: state
entity_id: input_boolean.alert_mode
state: 'on'
- condition: state
entity_id: input_boolean.speech_notifications
state: 'on'
- service: switch.turn_on
entity_id: switch.lr_amp
2018-01-01 19:00:45 -05:00
- service: media_player.volume_set
data:
entity_id: >
{{ media_player }}
2018-01-01 19:00:45 -05:00
volume_level: >-
{% if now().strftime('%H')|int < 12 and now().strftime('%H')|int > 6 %}
0.2
2018-01-01 19:00:45 -05:00
{% elif now().strftime('%H')|int > 12 and now().strftime('%H')|int < 20 %}
0.3
2018-01-01 19:00:45 -05:00
{% else %}
0.2
2018-01-01 19:00:45 -05:00
{% endif %}
- choose:
- conditions:
- condition: template
value_template: "{{ not direct_speech }}"
sequence:
- service: conversation.process
data:
agent_id: conversation.openai_conversation
text: >-
{{ speech_message }}
response_variable: agent
- variables:
speech_response: "{{ agent.response.speech.plain.speech }}"
- service: tts.cloud_say
data:
entity_id: >
{{ media_player }}
options:
voice: JennyNeural
2018-01-01 19:00:45 -05:00
message: >-
{{ speech_response }}
cache: false
2018-01-01 19:00:45 -05:00
- choose:
- conditions:
- condition: template
value_template: "{{ 'media_player.garage' not in routed_media_players }}"
sequence:
- service: notify.alexa_media_garage
continue_on_error: true
data:
message: "{{ speech_response }}"
data:
type: announce
- choose:
- conditions:
- condition: state
entity_id: switch.office_lamp_switch
state: 'on'
- condition: template
value_template: "{{ 'media_player.office' not in routed_media_players }}"
sequence:
- service: notify.alexa_media_office
continue_on_error: true
data:
message: "{{ speech_response }}"
data:
type: announce
2024-07-26 13:58:13 +00:00
- event: openai_response
event_data:
response: "{{ now().strftime('%B %d,%Y %-I:%M %p') }} {{ speech_response }}"
2018-01-01 19:00:45 -05:00
- service: input_boolean.turn_off
data:
entity_id:
- input_boolean.alert_mode
- input_boolean.lastmsg