How to use ChatGPT for your DIY smart home

Published by Oliver on

Is AI overhyped? Pretty sure! Can it do amazing things anyways? Yes! Can you use it for your smart home? Definitely! Here I will describe how I use ChatGPT for my DIY smart home and how it might be used in the future.

I am living under a stone or: what is ChatGPT?

If you for some reason missed the last 6 month you might not have heard about this new hype called LLM (large language models) or terms like ChatGPT, Bard and the Bing chatbot. All of them are pretty new “bots” able to hold, in most cases, pretty human like conversations with you via chat. They are also great at writing any kind of texts, from emails to code, if you are very careful to double and tripple check everything they tell you.

ChatGPT is the first of the bunch to be released in November 2022 by OpenAI and quickly becoming the fastest growing consumer software application to this day. Let me cite chatGPT itself (“what is chatgpt?”):

ChatGPT is an artificial intelligence language model developed by OpenAI. It’s powered by a machine learning architecture known as a Transformer, specifically a variant known as the Generative Pretrained Transformer (GPT)

The main function of ChatGPT is to generate human-like text based on the input it receives. It can answer questions, write essays, summarize long documents, translate languages, simulate characters for video games, tutor in a variety of subjects, and even generate Python code.

ChatGPT about itself

Can ChatGPT be useful for your smart home? Try asking questions!

As a software developer and tech enthusiast I was of course very interested in giving AI (although I feel this term is a bit misleading here) a try. I got the premium subscription of ChatGPT to be able to test the improved GPT-4 model.

I first tried some general conversation. ChatGPT is great at telling me what Home Assistant is, describing options to use it with Zigbee devices like I do (although it puts software like Zigbee2MQTT and ZHA in the same list as hardware like IKEA tradfri and Zigbee USB adapters and generally mixes a bunch of things together). In general the great strength here is how it remembers context. I can simply keep asking more specific questions and commands like: give me 10 interesting smart Zigbee devices.

It also shows another great weakness though: for now it has a cutoff date for the training data and is not yet fully able to access the Internet. There is no way to get up-to-date data from it. It is able to give pretty decent descriptions of, for example, a rule to turn on and off lights similar but not as intricate as my automation. Pretty impressive overall.

As the AIs tend to be very convincing but also often wrong many forums like the official Home Assistant one have (temporarily) banned generated questions and answers there. For me it seems like a great tool to generate ideas and explain high level concepts to you as long as you also spend the time to cross reference the information.

Using ChatGPT to generate code for your smart home

What works surprisingly well is to use ChatGPT to generate some code you need for your smart home. While it still makes up things here and has mistakes in the code from time to time it is a great place to start. I used it a couple of times to generate docker compose files for example where the conversational style works very well.

You can ask it to “write a docker compose file to run home assistant with influxdb and grafana on a raspberry pi” and it will write some code + a list of steps you need to follow. In my case it used the host network mode for all containers though, which is not needed. It also used restart: always and a couple other things I did not like. Luckily this can easily be fixed by just asking it to change those things. In a couple seconds I had a usable file looking like this:

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: homeassistant/raspberrypi4-homeassistant:stable
    volumes:
      - ${dataDir}/homeassistant:/config
    restart: unless-stopped
    network_mode: host

  influxdb:
    container_name: influxdb
    image: influxdb:latest
    volumes:
      - ${dataDir}/influxdb:/var/lib/influxdb
    restart: unless-stopped

  grafana:
    container_name: grafana
    image: grafana/grafana:latest
    volumes:
      - ${dataDir}/grafana:/var/lib/grafana
    restart: unless-stopped

This works great if you already mostly know what you want and are just looking to safe some time writing the code. If you don’t know anything about writing docker compose files you won’t really know what to ask for and what to look out for. Still I think this will be super helpful in the future!

Creating code via a conversation can be a great experience

If you are looking for a fully working version have a look at my own smart home server.

ChatGPT is also able to generate rules like this one for Home Assistant, but again it tends to also make up services and other things won’t work as expected. It can still be a huge time saver.

automation:
  - alias: "Living Room Motion Lights"
    trigger:
      platform: YOUR_MOTION_SENSOR_PLATFORM
      entity_id: YOUR_MOTION_SENSOR_ENTITY_ID
    condition:
      condition: sun
      after: sunset
    action:
      - service: light.turn_on
        entity_id: light.living_room_lights
      - delay:
          minutes: 5
      - service: light.turn_off
        entity_id: light.living_room_lights

Integrating ChatGPT into Home Assistant

There is one other way you can use ChatGPT in your smart home even more directly: you can include it into your Home Assistant installation. There are integrations created by the community like this one or this one. For now I do not think it is super useful but can be neat for something like generating more dynamic answers for different situations when you interact with your smart home system.

The Home Assistant team is also in the middle of the “year of the voice“, integrating the Home Assistant Assist (who came up with this name?) as a way to interact with your smart home via natural language (for now mostly text). I am sure this will in the future also be integrated with chat bots out there.

For me there are a lot of privacy concerns with the use of these bots but as soon as we are able to run capable models locally this will be a huge step forward. Once this is then combined with the at this point still astonishingly useless voice assistants like Alexa it can become a really powerful tool for your smart home. I am looking forward to it finally being able to follow really complex commands using context and maybe even being able to do things that are not being programmed before.

Let’s see what the future holds, I will definitely follow the evolution of these tools.

By the way, I generated the main image for this article using a description from ChatGPT given to DALL E 2.

Categories: Basics