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.
@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.
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
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!
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.
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 ?