2024-09-03 18:08:43 +00:00
|
|
|
#-------------------------------------------
|
|
|
|
# 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
|
2024-09-06 16:29:57 +00:00
|
|
|
# Follow me on https://www.vcloudinfo.com/click-here
|
2024-09-03 18:08:43 +00:00
|
|
|
#-------------------------------------------
|
2018-01-02 00:00:45 +00:00
|
|
|
|
|
|
|
speech_processing:
|
2020-08-02 16:20:08 +00:00
|
|
|
mode: queued
|
2018-01-02 00:00:45 +00:00
|
|
|
sequence:
|
|
|
|
|
2024-07-24 05:48:36 +00:00
|
|
|
- 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-09-25 15:51:00 +00:00
|
|
|
before: '22:00: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
|
2019-03-20 22:03:58 +00:00
|
|
|
entity_id: switch.lr_amp
|
2018-01-12 18:01:51 +00:00
|
|
|
|
2018-01-02 00:00:45 +00:00
|
|
|
- service: media_player.volume_set
|
2020-09-26 14:52:45 +00:00
|
|
|
data:
|
2022-06-23 17:13:36 +00:00
|
|
|
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 %}
|
2024-05-24 14:07:49 +00:00
|
|
|
0.2
|
2018-01-02 00:00:45 +00:00
|
|
|
{% elif now().strftime('%H')|int > 12 and now().strftime('%H')|int < 20 %}
|
2024-05-21 19:55:44 +00:00
|
|
|
0.3
|
2018-01-02 00:00:45 +00:00
|
|
|
{% else %}
|
2024-05-24 14:07:49 +00:00
|
|
|
0.2
|
2018-01-02 00:00:45 +00:00
|
|
|
{% endif %}
|
|
|
|
|
2024-05-24 14:07:49 +00:00
|
|
|
- service: conversation.process
|
|
|
|
data:
|
|
|
|
agent_id: conversation.openai_conversation
|
|
|
|
text: >-
|
|
|
|
{{ speech_message }}
|
|
|
|
response_variable: agent
|
|
|
|
|
2024-05-21 19:55:44 +00:00
|
|
|
- service: tts.cloud_say
|
2020-09-26 14:52:45 +00:00
|
|
|
data:
|
2020-06-03 20:36:46 +00:00
|
|
|
entity_id: media_player.livingroomCC
|
2024-05-21 19:55:44 +00:00
|
|
|
options:
|
|
|
|
voice: JennyNeural
|
2018-01-02 00:00:45 +00:00
|
|
|
message: >-
|
2024-05-24 14:07:49 +00:00
|
|
|
{{ agent.response.speech.plain.speech }}
|
2018-09-24 21:16:10 +00:00
|
|
|
cache: true
|
2018-01-02 00:00:45 +00:00
|
|
|
|
2024-07-26 13:58:13 +00:00
|
|
|
- event: openai_response
|
2024-07-24 05:48:36 +00:00
|
|
|
event_data:
|
2024-07-26 13:58:13 +00:00
|
|
|
response: "{{ now().strftime('%B %d,%Y %-I:%M %p') }} {{ agent.response.speech.plain.speech }}"
|
2024-05-24 14:07:49 +00:00
|
|
|
|
2018-01-02 00:00:45 +00:00
|
|
|
- service: input_boolean.turn_off
|
|
|
|
data:
|
|
|
|
entity_id:
|
|
|
|
- input_boolean.alert_mode
|
|
|
|
- input_boolean.lastmsg
|