###################################################################### # @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. ###################################################################### speech_processing: mode: queued 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 }}" - 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' - condition: or conditions: - condition: and conditions: - condition: state entity_id: group.bed state: 'off' - condition: time after: '08:00:00' before: '22: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 - service: media_player.volume_set data: entity_id: > {{ media_player }} volume_level: >- {% if now().strftime('%H')|int < 12 and now().strftime('%H')|int > 6 %} 0.2 {% elif now().strftime('%H')|int > 12 and now().strftime('%H')|int < 20 %} 0.3 {% else %} 0.2 {% 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 message: >- {{ speech_response }} cache: false - 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 - event: openai_response event_data: response: "{{ now().strftime('%B %d,%Y %-I:%M %p') }} {{ speech_response }}" - service: input_boolean.turn_off data: entity_id: - input_boolean.alert_mode - input_boolean.lastmsg