I used this HACS integration to handle tts on an amazon dot:
I created a (paid) account with openai and created an api key :
You can set monthly spending limits in your openai account.
I called the openai API 7 times in one day and was billed $0.23
I created a rest api sensor, that is updated once a day.
(or you can use the homeassistant.update_entity service, to update any time):
After Authorization: Bearer
comes the openai api key
sensor:
- platform: rest
name: chatgptalarm
unique_id: chatgptalarm
scan_interval: 86400
resource_template: https://api.openai.com/v1/chat/completions
method: POST
payload: '{"model": "gpt-4o-mini","messages": [{"role": "user", "content": "sarcastic alarm message. Answer in plain text. Keep it simple and to the point."}]}'
json_attributes_path: "$['choices'][0]['message']"
json_attributes:
- content
headers:
Content-Type: application/json
Authorization: Bearer xxxxxxxxdxyyyyyyyyyzzzzzz
value_template: "OK"
The chatgpt prompt ‘sarcastic alarm message’ results in something like this:
“Oh, wonderful. Another day of productivity and excitement lies ahead. Can’t wait to jump out of bed and start tackling those thrilling tasks. Beep beep.”
or another example:
“Oh no, it’s not like we have to wake up and face the same monotonous routine all over again. Yippee, another day of meaningless existence! Rise and shine, because life is just so incredibly exciting! eye roll”
or another example:
“Good morning sunshine! Time to wake up and enjoy another fabulous day in paradise. Don’t worry about the fact that it’s already 10 am and you’ve wasted half your day sleeping. It’s not like there’s anything important you needed to do today, right?”
You can show the last reply from openai on a ‘dashboard entities card’ like this:
type: entities
entities:
- entity: sensor.chatgptalarm
type: attribute
attribute: content
title: Chatgpt
I then have a script that sends the last chatgpt reply to the amazon dot:
alias: Amazon Dot Wakeup
sequence:
- service: notify.alexa_media
data:
data:
type: tts
target:
- media_player.bedroom_dot
message: >-
<audio
src="soundbank://soundlibrary/scifi/amzn_sfx_scifi_timer_beep_01"/> {{
state_attr('sensor.chatgptalarm','content') }}
mode: queued
max: 10
Then there is an automation, that calls the script at the appropriate time.
So, using this method, the chatgpt API is called once a day and not at the alarm time.