I have had this idea rolling around my head for a while, but the recent opening of ChatGPT to scripts has let me do this without a lot of work setting up that API myself. I did set up the API for Fake You (I don’t really recommend–the voices are pretty lousy) for more celebrity options.
This script randomly selects a personality, reads my calendar for the day, and gives me my agenda in a fun personality. Getting the prompt for ChatGPT just right can be a bit tricky.
alias: Daily Briefing
sequence:
- variables:
personality: >
{% set forced = 0 %} {% set personalities =
[
{ "name" : "Jarvis from Ironman", "voice_provider" : "microsoft", "language" : "en-gb", "voice" : "RyanNeural" },
{ "name" : "a puppy", "voice_provider" : "microsoft", "language" : "en-us", "voice" : "DavisNeural" },
{ "name" : "an Austrailan man", "voice_provider" : "microsoft", "language" : "en-au", "voice" : "WilliamNeural" },
{ "name" : "an Irish man", "voice_provider" : "microsoft", "language" : "en-ie", "voice" : "ConnorNeural" },
{ "name" : "an New Zealand man", "voice_provider" : "microsoft", "language" : "en-nz", "voice" : "MitchellNeural" },
{ "name" : "Aang, the Last Airbender", "voice_provider" : "fake you", "language" : "", "voice" : "weight_ebd86kqbz09xwfemj4n9e8zy0" },
{ "name" : "Hermione Granger from the Harry Potter world", "voice_provider" : "fake you", "language" : "", "voice" : "weight_z39jrnp1naq1pmvt2hqxt41vg" },
{ "name" : "Bowser (Jack Black) (The Super Mario Bros. Movie)", "voice_provider" : "fake you", "language" : "", "voice" : "weight_2c7vq4s9n7x8t9nf11k6ssb93" }
]
%} {% if forced == 0 %}
{{ personalities[ range(0, (personalities | list | count) ) | random ] }}
{% else %}
{{ personalities[ forced - 1 ] }}
{% endif %}
player: media_player.master_bedroom_museluxe
- action: calendar.get_events
target:
entity_id: |
{% set calendars =
[
"calendar.personal",
"calendar.work",
"calendar.family"
]
%} {% for calendar in calendars %}
{{ calendar }}{%- if not loop.last %},
{%- endif %}
{% endfor %}
data:
start_date_time: "{{ today_at('1:00') }}"
duration:
hours: 24
response_variable: agenda
- variables:
events: |
{% set pattern = '[a-zA-Z\d!@#$%&*-].*' %}
{% for calendar in agenda %}
{% for event in agenda[calendar]["events"] %}
{{ event.start }} - {{ event.end }} : {{ event.summary | regex_findall_index(pattern) }}|
{%- endfor %}
{%- endfor %}
- action: conversation.process
metadata: {}
data:
text: >-
I am male. My name is Andrew. The time is {{ now() }}. Only use 12-hour
time format. Tell me my agenda for the day in chronological order to be
read by a voice generator in the style of {{ personality.name }}. Play
hard into the character. The following are my activities for the day: {{
events }} (If no activities are listed above, assume my day is open and
adjust accordingly; do not make stuff up for my agenda.)
agent_id: conversation.chatgpt
response_variable: briefing
- choose:
- conditions:
- condition: template
value_template: "{{ personality.voice_provider == 'microsoft' }}"
sequence:
- action: tts.microsoft_say
metadata: {}
data:
cache: false
entity_id: "{{ player }}"
message: "{{ briefing.response.speech.plain.speech }}"
language: "{{ personality.language }}"
options:
type: "{{ personality.voice }}"
- conditions:
- condition: template
value_template: "{{ personality.voice_provider == 'fake you' }}"
sequence:
- action: script.fake_you_tts
metadata: {}
data:
entity_id: "{{ player }}"
message: "{{ briefing.response.speech.plain.speech }}"
voice_id: "{{ personality.voice }}"
description: ""
icon: mdi:calendar-today
My next steps:
- Get a better TTS provider for celebrity voices. Suggestions would be appreciated on that–I don’t mind paying a modest fee for quality voices. Play.ht is what I am currently looking at.
- Clone my parents’ voices so they can wake me up. Acknowledged, ChatGPT will not be able to get their personalities perfect, but I am OK will cliche mom & dad.
- Layering music with it, so for example, if HA picks Hermione, Hedwig’s Theme will play in the background. I assume mixing audio is not exceptionally straightforward, so advice would be helpful.
- Use this for an automatic alarm clock–this one I know how to do. I will create a local calendar to use as the trigger for the automated alarm. Every morning, another automation will read my calendars, and figure out what my first event is. Then add a trigger event in the aforementioned local calendar an hour before my first event.