[Custom Component] DISCONTINUED ChatGPT v1.1.1

Edit: This project will no longer be maintained. The responding services feature in Home Assistant’s 2023.7 release enables me to use the OpenAI Conversation integration for all my personal use cases.

Thanks to everyone who responded in this thread and on GitHub with issues and pull requests.
See below or in the GitHub README for my suggested migration option.

Edit: v1.1.0 is out now. The text below is still valid, but you’ll now see an additional feature in the README.

I am happy to share my custom component, ChatGPT Integration v1.0.0 for Home Assistant, with all of you. This integration allows you to interact with OpenAI’s ChatGPT API, and it’s been great for me as announcer/reminder of calendar events the last weeks.

Please note that this is an unofficial integration, not developed by OpenAI or Home Assistant/Nabu Casa.

To start using it, you’ll need an account on platform.openai.com and an API key. When you sign up, you’ll receive $5 in credit for experimenting with the ChatGPT integration during your first 3 months. After that, the ChatGPT integration will incur costs based on the model and usage. The default model gpt-3.5-turbo costs $0.002 per 1K tokens. You can check the OpenAI pricing page for up-to-date information and additional models. For my use cases I spend less than 1 cent per day.

There are two installation methods: HACS for a user-friendly experience, or manual installation for those who prefer a hands-on approach. You can find step-by-step installation instructions in the README on GitHub.

With the ChatGPT integration, you can create automations that generate responses based on input messages and for example send them to TTS devices. To help you get started, I’ve included an example automation in the README that demonstrates how to use the chatgpt.chat service to generate a response and send it to a TTS device.

For more details, including configuration and usage instructions, check out the GitHub repository and the README provided. I’m excited to see the automations you create with this integration.

8 Likes

Well done! I’ll try it out. Having crazy things in mind already :upside_down_face:

@ tnt_larsn
Please share your ideas after you have setup a few. I have not thought of a better reason to try it since it is not free.

@duceduc
For my use-case of writing 20-40 one sentence reminders per day, it’s so cheap that it’s basically free. I estimate that it’s around $0.01 per 3-5 days, but it’s hard to say because it’s so little that the spending overview is kinda difficult to read.

For everyone
The example I give in the readme is of course stripped down a bit for clarity, but I really enjoy getting reminders in different styles. So below is how I actually use it as a script to inject those styles. Note that I have a different script (unified_tts) that combines the different ways to call TTS services on pc and android.

alias: Say With GPT
fields:
  message:
    name: Message
    description: The message you want ChatGPT to respond to.
    required: true
    example: >-
      Write a $style, one line, spoken language reminder for the 'cleaning'
      calendar event.
  target:
    name: Target
    description: The TTS device(s) that should be used.
    required: false
    example: all
    default: all
sequence:
  - variables:
      styles:
        - happy
        - upbeat
        - motivational
        - funny
        - epic
        - poetic
        - dark humor
        - tough love
  - parallel:
      - alias: call chatgpt
        sequence:
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 100
          - service: chatgpt.chat
            data:
              messages:
                - role: user
                  content: "{{message.replace('$style', styles | random)}}"
              callback_id: "{{this.context.id}}"
      - alias: call tts
        sequence:
          - wait_for_trigger:
              - platform: event
                event_type: return_value
                event_data:
                  callback_id: "{{this.context.id}}"
            timeout:
              hours: 0
              minutes: 1
              seconds: 0
              milliseconds: 0
            continue_on_timeout: false
          - service: script.unified_tts
            data:
              target: "{{target}}"
              message: "{{wait.trigger.event.data.content | trim | replace('\"','')}}"
mode: queued
icon: mdi:head-alert
max: 10

I’m still tweaking the styles. The “tough love” and “happy” do pretty much what it says on the tin, “dark humor” and “funny” are not very fun so I’m looking to replace those, “upbeat”, “motivational” and “epic” feel sort of like I would expect with “happy” but using different typical phrasing, and lastly “poetic” feels poetic 20% of the time.

2 Likes

Thanks! great job! This will be a lots of fun! Thinking already about some special welcome salutation for guests entering the house :grinning_face_with_smiling_eyes:

My next project is a calendar/start of the day overview. Unfortunately the default HA calendar doesn’t have a service for getting the events for a time range, even though it can clearly display a range in the interface. So more coding is needed :laughing:

Urgh, you have to pay for it :roll_eyes:

Yep, development cost money and purchasing and running the hardware is not cheap.

I know and appreciate all that but I still begrudge paying for services. Ah well I’ll just have to keep my morning announcements boring for now.

Just came here to say thanks!
Set this up last night and have replaced a number of my announcements/alerts. :+1:

2 Likes

Thank You for your work
Any chance you can make a video tutorial?
I was able to install and got the automation working but this script thing is confusing me as im not sure how to use it.

This is so great! If you don’t mind please share some user cases for using this so we can share some inspiration. My first thought is to send a message when a person in the family is leaving work with the ETA!

What is it with the automation you don’t understand, maybe I can help

OMG Thanks so much for this!!! It works really well.

Here is a funny example I made. Every time the relative humidity goes above 75%, it tells a joke about the fact it may be raining soon!

alias: Rain is coming
trigger:
  - type: humidity
    platform: device
    device_id: <<your fav weather station>>
    entity_id: sensor.<<put your relative humidity from your fav station>>
    domain: sensor
    above: 75
condition: []
action:
  - parallel:
      - alias: call chatgpt
        sequence:
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 100
          - service: chatgpt.chat
            data:
              messages:
                - role: user
                  content: >-
                    explain in a short 3 line story that the humidity is above
                    75% and that it means it may rain soon. Use humour.  
              callback_id: "{{this.context.id}}"
      - alias: call tts
        sequence:
          - wait_for_trigger:
              - platform: event
                event_type: return_value
                event_data:
                  callback_id: "{{this.context.id}}"
            timeout:
              hours: 0
              minutes: 0
              seconds: 30
              milliseconds: 0
            continue_on_timeout: false
          - service: tts.google_translate_say
            data:
              language: en
              entity_id: media_player.kitchen_display
              message: "{{wait.trigger.event.data.content | trim | replace('\"','')}}"
mode: single

2 Likes

I just released v1.1.0 which makes it possible to configure the response event type. The default is still return_value for backwards compatibility.

@teitelbot This should be easier to work with now if you look at the example with 2 automations:

1 Like

Besides the calendar reminders that are in the example, I also have a separate reminder for bedtime. It includes the current time which is surprisingly helpful for someone who loses track of time constantly.

Oh and also I get custom messages when my laundry is done.

1 Like

Is it possible to give the content some context like “give me a professional weather report. for your information the current temprature is <<sensor.weather.temprature>> etc etc…” something like that ?

@jeroen.nijssen


  - parallel:
      - alias: call chatgpt
        sequence:
          - delay:
              hours: 0
              minutes: 0
              seconds: 0
              milliseconds: 100
          - service: chatgpt.chat
            data:
              messages:
                - role: user
                  content: "{{message.replace('$style', styles | random)}}"
              callback_id: "{{this.context.id}}"
      - alias: call tts
        sequence:
          - wait_for_trigger:
              - platform: event
                event_type: return_value
                event_data:
                  callback_id: "{{this.context.id}}"
            timeout:
              hours: 0
              minutes: 0
              seconds: 60
              milliseconds: 0
            continue_on_timeout: false
          - service: tts.google_translate_say
            data:
              language: en-au
              entity_id: media_player.living_room
              message: "{{wait.trigger.event.data.content | trim | replace('\"','')}}"


variables:
  styles:
    - happy
    - upbeat
    - motivational
    - funny
    - epic
    - dark humor
    - polite
  message: Give me a $style weatherforecast for today based on: Condition {{states("weather.knmi_spijkenisse")}} Temperature min:{{state_attr("weather.knmi_spijkenisse","forecast")[1].templow|round}}. Temperature max:{{state_attr("weather.knmi_spijkenisse","forecast")[1].temperature|round}} degrees. Percent change on sun {{state_attr("weather.knmi_spijkenisse","forecast")[1].sun_chance|round}} Percent change on rain {{state_attr("weather.knmi_spijkenisse","forecast")[1].precipitation_probability|round}} {% if state_attr("weather.knmi_spijkenisse","forecast")[1].wind_bearing == "null" -%} Wind bearing {{state_attr("weather.knmi_spijkenisse","forecast")[1].wind_bearing|round}} {%- else -%} Wind bearing: 0 {%- endif %} Wind speed {{state_attr("weather.knmi_spijkenisse","forecast")[1].wind_speed|round}} km/hr. Visibility {{state_attr("weather.knmi_spijkenisse","visibility")|round}} km. Start with goodmorning/day/afternoon/evening when it is now {{now().strftime('%H:%M')}}

Gives me 7 different styles randomly based on the context provided by knmi for today’s forecast :wink:

Thanks go to @jjbankert for the random idea :grin:

2 Likes

wow thanks!! :smiley: exactly what i needed

@jeroen.nijssen Looking at your name i figured it would :grin: