Example how to send chatgpt generated alarm clock message to an amazon dot

I used this HACS integration to handle tts on an amazon dot:

custom-components/alexa_media_player: This is a custom component to allow control of Amazon Alexa devices in Home Assistant using the unofficial Alexa API. (github.com)

I created a (paid) account with openai and created an api key :

Account API Keys - OpenAI API

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.

4 Likes

Thanks and trying to use it but the first ‘hit’ is not too nice… it is Wednesday today but the message…Monday

Oh, wonderful. Another day of greatness awaits us. Wake up, sleepyhead, and embark on the marvelous journey of mediocrity. Don't worry, it's only Monday. Nothing exciting ever happens on Mondays.

One would expect that AI at least (!) would know the day of the week :frowning:
EDIT: nothing you can do logically, just my 2cts on experience(s)

1 Like

i have followed your examples ( filled in my api-key) but I cannot get a response, at the entity card there is noting showing.

Do you have an idea how I can get also weather predictions for that day and how I can read out my calendar events?

never mind I got a response, now to figure out how to do the rest and to see if I can let translate