2025/12/21

TTS 알림 스크립트


TTS 알림을 메세지 등급에 따라 분기되도록 스크립트 수정.
자동화에서 message, type, voice를 선택할 수 있고 type에 따라 tts만 실행하거나 캠패니언앱 또는 텔레그램에 알림이 가도록 분기.

configuration.yaml
automations: !include automations.yaml
script: !include script.yaml

script.yaml
tts_notify:
  fields:
    message:
      required: true
      selector:
        text:
    type:
      required: true
      selector:
        select:
          options:
            - info
            - alarm
            - danger
    voice:
      required: false
      selector:
        select:
          options:
            - ko-KR-Chirp3-HD-Achernar
            - ko-KR-Chirp3-HD-Gacrux
            - ko-KR-Chirp3-HD-Orus
  sequence:
    - choose:
        - conditions: "{{ type == 'info' }}"
          sequence:
            - action: media_player.play_media
              target:
                entity_id: media_player.notify
              data:
                media_content_id: media-source://media_source/local/sound/noti3.mp3
                media_content_type: audio/mpeg
            - delay: '00:00:03'
            - action: tts.speak
              target:
                entity_id: tts.google_cloud
              data:
                media_player_entity_id: media_player.notify
                message: '{{ message }}'
                options:
                  voice: '{{ voice | default("ko-KR-Chirp3-HD-Vindemiatrix") }}'
        - conditions: "{{ type == 'alarm' }}"
          sequence:
            - action: media_player.play_media
              target:
                entity_id: media_player.notify
              data:
                media_content_id: media-source://media_source/local/sound/noti3.mp3
                media_content_type: audio/mpeg
            - delay: '00:00:03'
            - action: tts.speak
              target:
                entity_id: tts.google_cloud
              data:
                media_player_entity_id: media_player.notify
                message: '{{ message }}'
                options:
                  voice: '{{ voice | default("ko-KR-Chirp3-HD-Vindemiatrix") }}'
            - delay: '00:00:10'
            - action: notify.mobile_app_phone
              continue_on_error: true
              data:
                message: '{{ message }}'
                data:
                  priority: high
                  channel: alarm
        - conditions: "{{ type == 'danger' }}"
          sequence:
            - action: media_player.play_media
              target:
                entity_id: media_player.notify
              data:
                media_content_id: media-source://media_source/local/sound/noti3.mp3
                media_content_type: audio/mpeg
            - delay: '00:00:03'
            - action: tts.speak
              target:
                entity_id: tts.google_cloud
              data:
                media_player_entity_id: media_player.notify
                message: '{{ message }}'
                options:
                  voice: '{{ voice | default("ko-KR-Chirp3-HD-Vindemiatrix") }}'
            - delay: '00:00:10'
            - action: notify.telegram
              continue_on_error: true
              data:
                message: '{{ message }}'


automations.yaml
- id: 알림-가습기물부족
  alias: 알림-가습기물부족 
  mode: restart
  triggers:
    - trigger: state
      entity_id: binary_sensor.water_levels
      from: 'off'
      to: 'on'
      for: '00:00:30'
  conditions:
    - "{{ is_state('binary_sensor.winter_season', 'on') }}"
    - "{{ now().hour >= 7 and now().hour < 23 }}"
  actions:
    - action: script.tts_notify
      data:
        message: 가습기 물보충 해주세요.
        type: alarm


** 구글 TTS AI 음성 사용: https://ntxlds.blogspot.com/2025/09/tts-ai.html