Have you ever considered turning your home into a smart hub but felt overwhelmed by the complexity and jargon? You’re not alone. The journey into home automation can seem daunting, with a steep learning curve and an array of devices that need to be perfectly synchronized to work seamlessly. However, the rewards of a smart home β energy efficiency, increased security, and convenience β are too compelling to ignore.
This article delves into the world of Home Assistant, a powerful tool for home automation, combined with an AI Copilot powered by GPTScript, making it as easy as ever to transform your living space into a smart (or even smarter) home.
Home Automation with Home Assistant
Home Assistant is an open-source platform for home automation with a thriving community.
Itβs easy to install (e.g. on a Raspberry Pi) and, thanks to the extensive documentation and forum, fairly simple to setup. There is a huge set of integrations and AddOns to integrate virtually any smart (and some not-so-smart) devices into one cohesive platform.
Let the position of the sun control your blinds, configure a morning routine to have your coffee ready once you get up or check if you closed the backdoor even after you left – there is a lot you can do with this free piece of software.
Sometimes it can feel like itβs too much that you can do with it and that thereβs just so much to configure and youβre lacking the time to browse the forum to find help.
Or youβre just searching for that one entity that you canβt remember the name ofβ¦
GPTScriptβs AI Copilot is here to help you out!
Building a Copilot for Home Assistant Using GPTScript
A Copilot for Home Assistant is your day-to-day companion for controlling and configuring your smart home with just natural language.
It knows your devices, your existing automations and scripts and can help you control them without any βClicking around in the UIβ and without any extra configuration.
Letβs get started with it.
Pre-Requisites
What youβll need to follow along:
- Home Assistant installed somewhere and, to have the most fun with it from the start, some devices integrated already
- The Home Assistant CLI (hass-cli) installed on your current device
- An API Key for your Home Assistant installation (make sure that the API is reachable from your current device)
- GPTScript installed on your current device
Note: You may as well run this directly on your HAOS (Home Assistant OS) device which has the hass-cli pre-installed
The Copilot in a few lines of text
The Copilot, letβs call it Harry, consists of a single GPTScript file:
name: Harry the Home Assistant
context: github.com/gptscript-ai/context/workspace
context: github.com/gptscript-ai/context/cli
tools: github.com/gptscript-ai/answers-from-the-internet
chat: true
You are a friendly assistant for the open source software Home Assistant.
Ask the user if they like some help with Home Assistant
You have the hass-cli CLI available to you. Use that to perform tasks or answer questions about the environment.
For connection and authentication, use the HASS_SERVER and HASS_TOKEN environment variables, if available.
Letβs break this down:
name: Harry the Home Assistant
The name of our assistant.
context: [github.com/gptscript-ai/context/workspace](http://github.com/gptscript-ai/context/workspace)
Weβre giving our assistant some room on our system to store information (i.e. a tiny ephemeral folder on your hard drive).
context: [github.com/gptscript-ai/context/cli](http://github.com/gptscript-ai/context/cli)
Weβre giving our assistant the ability to execute CLI commands on our behalf.
tools: [github.com/gptscript-ai/answers-from-the-internet](http://github.com/gptscript-ai/answers-from-the-internet)
The AI may not know everything about Home Assistant from the top of the head – letβs give it access to online search.
chat: true
This is not a one-off prompt – This toggle takes you to a chat interface upon launch.
< the rest >
We tell our assistant – in natural language – what itβs profession is and how it should help us.
Bringing it to life
All you need to be able to chat with Harry (and with it effectively to your Home Assistant installation) is a single command.
This assumes that you have the aforementioned script stored in the current working directory as ha.gpt
.
HASS_SERVER=<your-home-assistant-server-url> HASS_TOKEN=<your-token> gptscript ./ha.gpt
Thatβs really all it takes – have a look below at what it can do in very simple terms (I manually truncated some output to make it more readable):
$ gptscript ha.gpt
Hi there! Do you need any help with Home Assistant? Whether it's setting up new devices, automating tasks, or troubleshooting issues, I'm here to
assist you. Let me know how I can help!
> What devices do I have available?
ββββββββββββββββββββββββββββββββββββββββββ
β Call Arguments: β
β β
β exec {"command":"hass-cli state list"} β
ββββββββββββββββββββββββββββββββββββββββββ
Running hass-cli state list
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ENTITY DESCRIPTION STATE
β sensor.stromverbrauch_summe Stromverbrauch Summe 408.0
β sun.sun Sun above_horizon
β sensor.sun_next_dawn Sun Next dawn 2024-07-04T02:38:14+00:00
β sensor.sun_next_dusk Sun Next dusk 2024-07-03T20:36:45+00:00
β sensor.sun_next_midnight Sun Next midnight 2024-07-03T23:37:30+00:00
β sensor.sun_next_noon Sun Next noon 2024-07-03T11:37:13+00:00
β sensor.sun_next_rising Sun Next rising 2024-07-04T03:25:03+00:00
β sensor.sun_next_setting Sun Next setting 2024-07-03T19:49:56+00:00
β sensor.nachste_abholung MΓΌll: NΓ€chste Abholung Gelb, Grau in 5 Tagen
| ... truncated ...
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
You have a wide variety of devices integrated into your Home Assistant setup. Here are some of the categories and examples of devices you have:
### Persons
... truncated ...
### Scenes
... truncated ...
This is just a snapshot of the many devices and entities you have. If you need more detailed information or help with a specific device, feel free to
ask!
> Where's the sun at?
βββββββββββββββββββββββββββββββββββββββββββββββββ
β Call Arguments: β
β β
β exec {"command":"hass-cli state get sun.sun"} β
βββββββββββββββββββββββββββββββββββββββββββββββββ
Running hass-cli state get sun.sun
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ENTITY DESCRIPTION STATE CHANGED β
β sun.sun Sun above_horizon 2024-07-03T03:24:16.453015+00:00 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The sun is currently above the horizon. If you need more specific details like the next sunrise or sunset times, let me know!
> When do I have to take out the trash?
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Call Arguments: β
β β
β exec {"command":"hass-cli state get sensor.nachste_abholung"} β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running hass-cli state get sensor.nachste_abholung
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ENTITY DESCRIPTION STATE CHANGED β
β sensor.nachste_abholung MΓΌll: NΓ€chste Abholung Gelb, Grau in 5 Tagen 2024-07-02T22:00:00.469792+00:00 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
You need to take out the trash in 5 days. The next collection will be for the Gelb (Yellow) and Grau (Gray) bins.
> It's a little too bright in my office - please help.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Call Arguments: β
β β
β exec {"command":"hass-cli service call light.turn_off --entity_id light.shelly_shellyplus1_7c87ce726fc4"} β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running hass-cli service call light.turn_off --entity_id light.shelly_shellyplus1_7c87ce726fc4
ββββββββββββββββββββββββββββββββββββββββββββββββββ
β ERROR: exit status 2 β
β OUTPUT: β
β Usage: hass-cli service call [OPTIONS] SERVICE β
β Try 'hass-cli service call --help' for help. β
β β
β Error: No such option: --entity_id β
ββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Call Arguments: β
β β
β exec {"command":"hass-cli service call light.turn_off light.shelly_shellyplus1_7c87ce726fc4"} β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running hass-cli service call light.turn_off light.shelly_shellyplus1_7c87ce726fc4
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ERROR: exit status 2 β
β OUTPUT: β
β Usage: hass-cli service call [OPTIONS] SERVICE β
β Try 'hass-cli service call --help' for help. β
β β
β Error: Got unexpected extra argument (light.shelly_shellyplus1_7c87ce726fc4) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Call Arguments: β
β β
β exec {"command":"hass-cli service call light.turn_off --arguments entity_id=light.shelly_shellyplus1_7c87ce726fc4"} β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running hass-cli service call light.turn_off --arguments entity_id=light.shelly_shellyplus1_7c87ce726fc4
ββββββ
β [] β
ββββββ
The light in your office has been turned off. It should be less bright now. If you need any further adjustments, just let me know!
> Lights are out, but there's too much sunlight still.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Call Arguments: β
β β
β exec {"command": "hass-cli service call cover.close_cover --arguments entity_id=cover.shelly_shsw_25_3494546bbb23"} β
β exec {"command": "hass-cli service call cover.close_cover --arguments entity_id=cover.shelly_shsw_25_4c7525344903"} β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running hass-cli service call cover.close_cover --arguments entity_id=cover.shelly_shsw_25_4c7525344903
ββββββ
β [] β
ββββββ
Running hass-cli service call cover.close_cover --arguments entity_id=cover.shelly_shsw_25_3494546bbb23
ββββββ
β [] β
ββββββ
The blinds in your office have been closed to reduce the sunlight. It should be more comfortable now. If you need any further adjustments, feel free to
ask!
> What's the temperature in my son's room?
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Call Arguments: β
β β
β exec {"command":"hass-cli state get sensor.temperatursensor_kinderzimmer_temperature"} β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running hass-cli state get sensor.temperatursensor_kinderzimmer_temperature
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ENTITY DESCRIPTION STATE CHANGED β
β sensor.temperatursensor_kinderzimmer_temperature Temperatursensor Kinderzimmer Temperature 21.4 2024-07-03T09:27:43.378435+00:00 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The temperature in your son's room is currently 21.4Β°C. If you need any further information or adjustments, feel free to ask!
> Is there someone in my driveway?
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Call Arguments: β
β β
β exec {"command":"hass-cli state get binary_sensor.einfahrt_person_occupancy"} β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running hass-cli state get binary_sensor.einfahrt_person_occupancy
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ENTITY DESCRIPTION STATE CHANGED β
β binary_sensor.einfahrt_person_occupancy Einfahrt person occupancy off 2024-07-03T09:41:27.846592+00:00 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
There is currently no one in your driveway. If you have any other questions or need further assistance, just let me know!
> When was the last person seen on the terrace?
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Call Arguments: β
β β
β exec {"command":"hass-cli state get sensor.terrasse_person_name"} β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Running hass-cli state get sensor.terrasse_person_name
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ENTITY DESCRIPTION STATE CHANGED β
β sensor.terrasse_person_name Terrasse Person Name 2024-07-03T07:22:19.884563+00:00 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The last person was seen on the terrace on July 3rd, 2024 at 07:22:19. If you need any more information or assistance, just let me know!
Findings
Whatβs interesting about those super simple use cases is:
- From my natural language instructions/questions, the copilot finds the correct devices/sensors/triggers/etc. to read/control to achieve my imposed goal
- Even though some of my Home Assistantβs entities are named in German and have German descriptions, the copilot finds them and interprets them correctly due to the power of the Large Language Model
- Have another look at the actions taken for my prompt βIt’s a little too bright in my office – please help.β – The copilot tries a command, then sees that it fails and tries to correct itself until it succeeds
- No matter how the data is returned from Home Assistant, the copilot pimps it up and returns it to us in a clear and easily understandable way.
Prompt Ideas / Outlook
There are so many possibilities, that they canβt be shown in the example above, but here are some ideas what to do with this agent:
- βGenerate an automation for my morning routine: I want to get up with the sunlight, have the radio in the bathroom turned on and receive a notification with the daily news.β
- With no more typing involved, your copilot could generate the whole Home Assistant automation config (YAML) for you and even test it against the Home Assistant API to validate that itβs working and wonβt break your setup
- βIβm leaving home, make sure everythingβs secure until I come backβ
- Security system gets armed, door contacts turned on and motion detection on the cameras enabled – another way to achieve this is creating a scene or an automation for it or to go to each entity manually to toggle itβ¦ but itβs way cooler to just ask your copilot, isnβt it?
- βWhen do I have to take out the paper bin?β
- Just as in the example, this will tell you when the paper trash will be collected according to the waste collection schedule integration.
- βAm I currently producing or consuming energy?β
- This will tell you, whether, according to your smart power meter, youβre currently consuming energy from the grid or feeding back some self-made energy from your solar panels
Conclusion
Home Assistant is incredibly powerful on its own, letting you integrate all your devices and automate just about everything in your smart home. But in combination with the GPTScript-powered Copilot, we can open up this mighty platform to even more people, without them having to watch lots of videos and read up on documentation upfront. Thatβs for Home Assistant – but with GPTScript, you can easily build an assistant or copilot for any other system yourself. Visit our GitHub to find out more and explore some tools we already built for you – Get started today.