ChatGPT Integration for Home Assistant: Enhance Your Smart Home with AI

Home Assistant OpenAI Response Sensor

I’m excited to share my latest project, a custom integration that brings the power of OpenAI’s ChatGPT directly into your Home Assistant setup. With this integration, you can harness the potential of AI-driven conversations and automations to make your smart home even more intelligent and versatile. From incorporating ChatGPT into dashboard views to triggering automations based on AI-generated responses, the possibilities are endless.

videothumbnail.PNG

Video Demonstration From My Channel

Checkout the latest version for free GPT4 Access.

23 Likes

Great to see the interest of GPT among the community. I just came in to see if anyone thought about incorporating it into Home Assistant but not just to have chat prompt somewhere in lovelace but to be able to command my system from chat. For example I imagine it would be amazing if i could open my ChatGPT instance and ask it to turn on the lights today if i will not come home before 6pm. Without implementing an automation. I’m not even sure it’s doable at this stage of ChatGPT development but i’m sure some day it will be and it will be great to have it in place.

5 Likes

Not possible to action this without an automation (at the moment).
For a start, chatgpt cant keep track of time.

Home Assistant does have a built in openai tool, this declares certain home assistant entities and allows chatgpt to read the state of certain devices.

I created this so us as a community have a starting point on discovering what is indeed possible.

2 Likes

Works fine. Thanks for your effort :wink:

Two things I would like to see.

After an answer comes in, the text input would clear it self, ready for next question, without me needing to delete.

Even better - scrolling like in the chat it self, so we can go back to previous answers in a session.

But hey, nice start!

1 Like

i feel like this is probably for automations, not a chatgpt replacement

also is this an alt account or just the first thing you made

It’s an alt. Which would be banned if used for sock-puppeting (supporting your own posts with alt accounts), however as the other account makes no attempt to hide that they are the same person I see no reason to suspend it.

This is the first integration I’ve made.
This is by no means a ChatGPT replacement, Including chat history significantly increased the cost of usage due to the current OpenAI pricing model, so I aborted that idea for now.

As mentioned, just a starting point for now.

2 Likes

Yeah im not doing any of what you just said :rofl:
Just my first attempt at a custom component, wanted to share my work so… here it is…

1 Like

OK, so I decided to give it a try and get some practical application of this integration. Here is what I got; ‘roon style’ media dashboard, that pulls information about album from OpenAI:

I’m taking artist and album information from media player and convert it to question understandable by ChatGPT. Response is diplayed in media card.

So it is usefull! Grat contribution @Hassassistant !

8 Likes

Could you share your automation on this please?

Does it just take the output from any question? Or does it know to only display the content when something is playing ?

Here is the code:

automation:
  - id: 'update_media_info'
    alias: Update Media Info
    trigger:
    - platform: state
      entity_id: media_player.marantz_sacd30n
      attribute: media_album_name
    condition: []
    action:
      - service: input_text.set_value
        data_template:
          entity_id: input_text.gpt_input
          value: >-
            Tell me about {{state_attr('media_player.marantz_sacd30n', 'media_artist')}}'s album {{state_attr('media_player.marantz_sacd30n', 'media_album_name')}}"
    initial_state: true

So far I’m using this only for media info, so there is no distinguishing regarding source of question. Not sure if with simple input/output model this would be possible to distinguish what process/automation asked the question and redirect answer to specific destination. This might be possible with asking question/blocking another question/waiting for answer/storing the answer wherever appropriate/ unblocking asking another question sort of flow.
BTW. I checked that you can also use song title to get more detailed info about any specific song. Pretty interesting answer you can get for this!

2 Likes

How can I use this as a voice assistant. I have a mic and speaker using browser mod.

1 Like

After working with the UI for a while, then checking entities, services, documentation and here, then going back and repeating, I was able to determine the only proper docs are on your GitHub. Please improve the docs.

Hmm I just tried to put this together but couldn’t get it to work. I followed all the steps via the GitHub link. Do you need a premium account for the API key to work? As it’s not generating a response

Do you have credits in your OpenAI account?

Looks like mine free credits just expired

Thanks, working perfect in Lovelace UI!
Any Chance to get an Automation working with the Telegram Bot? I just can’t update the input_text.gpt_input entity …
Here is my code:

alias: Telegram-ChatGPT
trigger:
  - platform: event
    event_type: telegram_command
    event_data:
      command: /chatgpt
action:
  - service: input_text.set_value
    data_template:
      entity_id: input_text.gpt_input
            value: "{{ trigger.event.data.text }}"
  - delay: "00:00:05"
  - service: telegram_bot.send_message
    data_template:
      message: "{{ state_attr('sensor.hassio_openai_response', 'response_text') }}"
mode: single

It gets triggered, but doesn’t fill in my text behind the /chatgpt command, the input_text.gpt_input doesn’t update.
I’ve tried nearly everything at the trigger.event.data.text part.
ChatGPT itself said I should try it with trigger.message.text.split(' ', 1)[1] but this still doesn’t work. Dunno whats the correct trigger data.
Maybe someone knows the correct way?

The Part of sending the response_text is working fine standalone!

Why is your indentation like that? (Also you shouldn’t really be asking ChatGPT about automations, as the pinned warning notes)

Just want to advertise that there’s some improvements done. There’s PR that brings service call and support for models gpt-3.5-turbo and gpt-4.
See Multiple enhancements by Olen · Pull Request #6 · Hassassistant/openai_response · GitHub
and openai_response/custom_components/openai_response at gpt-3.5-turbo · Olen/openai_response · GitHub

1 Like