Hi, I found this repository on github: GitHub - qui3xote/OpenAIConversationEnhanced: An implementation of ChatGPT as a conversation agent that can actually control your home.
It is basically a hacs replacement for the default openai chat integration in home assistant. The difference is, this one can really do something with your lights and so on.
So the prompt send to chatgpt by this integration describes a few things. At first, it tells chatgpt to generate only json formated answers. The answers are descriped in a way, that the integration can send the answer of chatgpt to the home assistant service handler.
Chatgpt gets an idea of the home and its structure by a description of the rooms and their devices.
With this knowledge it is possible to control the home in nearly natural speaking. And you can ask everything else.
In my case, the integration didn’t work, because i have to many devices to create an automatic description for chatgpt of my home.
So i have changed some things manually and it worked.
I removed in the file const.py the content of home_info_template. I wrote the information of my house and the room into the template, that you can edit within home assistant, where you also set the chatgpt model and so on.
I only experimented with one room of my house (Arbeitszimmer/Office).
So i added the following description at the end of the template, that explains chatgpt, what to do:
Properties of the smart home:
Office:
Temperature is {{ states(‘sensor.temperatur_arbeitszimmer’)}}°C
Printer Switch is {{states(‘switch.drucker’) }}, use “switch.drucker” as entity_id in the JSON.
Light is {{states(‘light.0x588e81fffeef3214’) }}, use “light.0x588e81fffeef3214” as entity in the JSON.
With these informations chatgpt was able to answer question about the states of the switch, Light or the temperature, but also able to generate a json command, that was valid to use it with the service handler from home assistant. Within this integration the service handler is called, if the answer from chatgpt contains a JSON command. And the content of the field comment is returned as answer. It contains for example a short acknolegde, of the things, chatgpt has done. Something like “I have turned the switch off” or “OK” only. If you ak for the temperature, there is a full answer in there.
The smart thing is, that chatgpt was able to create JSON to change the light color, light color temperature, and on and off, the switch too.
And there was no need to build a specific sentence to tell chatgpt what to do. Just natural speaking, in my case in german, but described the home and so on in english. I gave the rule, to answer in german only in the comment.
The next step should the transfer the result of a speech2text part like rhasspy maybe to the conversation/process endpoint of home assistant. And then convert the result to speech.
It is a really greate base work of the creator of the repository and i hope there is way to complete the whole workflow of this someday
Add: I created a fork of the repository with all changes i needed to get this work with my installation.