Guide on how to use a Custom GPT to interact with Home Assistant via REST API

I’ve successfully managed to set up a Custom GPT which can query entities and call services in your home.

Current issues:

  • GPTs don’t work in the Android App yet when you add a custom API
  • The Custom GPT seems to have an issue with saving and publishing changes to API specs, current workaround is deleting the GPT and recreating a new one if you want to add additional services.

Pre-reqs:

  • You will need a Plus account
  • You will need an internet facing address for your Home Assistant.

Steps:

  1. GPT Initialization:
  • Create a new GPT named ‘Home Assistant’.
  • Use the following prompt, updating it with your entity list: Prompt Link
  1. Action Integration:
  • Add Actions using the provided OpenAPI Spec. Ensure to replace the URL with your public address: API Spec Link
  1. Authentication:
  • Add an API Bearer Token for authentication. This token should be a long-lived token generated from your user page in the Home Assistant API.
  1. Finalizing GPT Setup:
  • In your GPT settings, turn off “Use conversation data in your GPT to improve our models” for privacy.
  • Test the setup in the preview.
  1. Publication:
  • When ready, publish the GPT. It’s recommended to set it as Private for security.

And now if all has gone well, you should be able to ask to turn lights on and off, ask for weather report, or run automations, depending which entities you added in the list in the prompt. I’m going to add more entities/services over time as I think of them and test them. Wanted to try the Todo list but I’m having trouble querying the current state of the list, so that’s one for the later Todo list :wink:

I went down the route of making a specific OpenAPI spec and adding individual service calls rather than using the /domain/service endpoint so that the specific parameters for each service can be described, so the GPT knows what it can send in. Planning on adding a lot more services in the future, and I’ll make a GitHub repo for this at some point.

I hope this is useful to someone, and that the current limitations can be overcome.

The GitHub repo is here:

7 Likes

Hello, thank you for your guide!

I cannot connect to api…

Any idea, where is problem?

[debug] Calling HTTP endpoint
{
  "domain": "my_nabusa_url.ui.nabu.casa",
  "method": "get",
  "path": "/api/",
  "operation": "CheckAPI",
  "operation_hash": "1964dd43622ffd1b01256870ac91d3be022bc586",
  "is_consequential": false,
  "params": {}
}

response:

{
  "response_data": "404: Not Found",
  "status_code": 404,
  "action_id": "g-7e965ca8b34bf0988d9af6271d228d6bbdb6d25e"
}

my_nabusa_url.ui.nabu.casa - I have the correct url in the code. When I copy and paste it into the browser, the HA loads.

Thank you.

Ah, just noticed in the developer docs it mentions enabling the REST API in configuration.yaml by adding api:, which I probably a long time ago and forgot.

I’ll update the pre-reqs on the github readme, but let me know if you try it and it makes a difference.

One of the things that it does really well that I’ve discovered is that even though I only told it about my light groups, it’s able to infer the other lights from the result of the first call to the group of lights and set them all to different colours without specifically listing the entity names.

You could try adding the /api/entities endpoint or giving a knowledge base item with the list in for a wider list, but I found on my system there’s too many and it gets a request too large to query them, and by putting the limited list in the prompt it avoided an extra step checking the knowledge base when you give a command.

I was running into a similar problem and getting a 404, and just solved it for me.

In the GPT schema, check the URL you pasted in from nabu.casa. Mine had a trailing ‘/’ at the end of the URL by default. I had to remove that slash to get it to work.

1 Like

Thank you.

Thank you for your guide!

{
“response_data”: “An error occurred while executing the plugin.”
}

I’ve posted over on GitHub on the issue raised, it’s still working for me at the moment, however it has just broken again for me in the Android app. Although only broken for some calls but not others (light and automation calls work, but check API doesn’t).

The check API called is saying “Stopped talking to …” and clicking that pops up a review privacy action. I didn’t set up a privacy statement, being a private GPT, but perhaps the android app is stopping messages due to that. I will try adding one tomorrow and see that gets it working there again.

There have been a fair few ChatGPT outages and issues recently, so it might be worth giving it a try later, FSZJ. Is it just check API, or do the other service calls also break for you?