Home-AssistantConfig/config/script/speech_processing.yaml

97 lines
2.7 KiB
YAML
Raw Normal View History

#-------------------------------------------
# Speech Processing Script
# Description: Sends notifications to ChromeCast Audio devices
#
# Features:
# - Operates during specified hours
# - Only activates when family is home or guest mode is on
# - Adjustable volume based on time of day
#
# Usage:
# action:
# service: script.speech_engine
# data:
# media_player: [target_media_player]
# speech_message: [message_to_speak]
#
# Original Repo: https://github.com/CCOSTAN/Home-AssistantConfig
# follow me on X for updates: https://x.com/CCOSTAN
#-------------------------------------------
2018-01-02 00:00:45 +00:00
speech_processing:
mode: queued
2018-01-02 00:00:45 +00:00
sequence:
- event: openai_instructions_sent
event_data:
instructions: "{{ speech_message | striptags }}"
2018-01-02 00:00:45 +00: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: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: group.bed
state: 'off'
- condition: time
after: '08:00:00'
2024-06-03 19:15:01 +00:00
before: '21:30:00'
2018-01-02 00:00:45 +00: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-02 00:00:45 +00:00
- service: media_player.volume_set
data:
entity_id: >
{{ media_player }}
2018-01-02 00:00:45 +00:00
volume_level: >-
{% if now().strftime('%H')|int < 12 and now().strftime('%H')|int > 6 %}
0.2
2018-01-02 00:00:45 +00:00
{% elif now().strftime('%H')|int > 12 and now().strftime('%H')|int < 20 %}
0.3
2018-01-02 00:00:45 +00:00
{% else %}
0.2
2018-01-02 00:00:45 +00:00
{% endif %}
- service: conversation.process
data:
agent_id: conversation.openai_conversation
text: >-
{{ speech_message }}
response_variable: agent
- service: tts.cloud_say
data:
entity_id: media_player.livingroomCC
options:
voice: JennyNeural
2018-01-02 00:00:45 +00:00
message: >-
{{ agent.response.speech.plain.speech }}
cache: true
2018-01-02 00:00:45 +00:00
2024-07-26 13:58:13 +00:00
- event: openai_response
event_data:
2024-07-26 13:58:13 +00:00
response: "{{ now().strftime('%B %d,%Y %-I:%M %p') }} {{ agent.response.speech.plain.speech }}"
2018-01-02 00:00:45 +00:00
- service: input_boolean.turn_off
data:
entity_id:
- input_boolean.alert_mode
- input_boolean.lastmsg