Unlock seamless workflows and faster delivery with our latest releases – get the details

IOT studio for your home!

Build your home automation with Sanity! We use home automation to show you the extent that Sanity can read and write to different API's, that Sanity is well capable of reaching out beyond the internet and into the physical world.

Published

  • Nicholas Klem

    Nicholas Klem

    Smooth Operations

  • Bjørge Næss

    Bjørge Næss

    Full-stack engineer at Sanity, working mostly on Sanity Studio.

  • Kapehe

    Kapehe

    Developer Community Enablement Manager at Sanity

  • Armando Cerna

    Armando Cerna

    I make the servers go beep and boop.

  • Carolina Gonzalez

    Carolina Gonzalez

    Carolina is a Solution Engineer at Sanity.

  • Mikolaj Dobrucki

    Mikolaj Dobrucki

    Product Designer at Sanity.io, working on the Sanity Studio.

  • Tony Stimpfel

    Tony Stimpfel

    Enterprise Sales at Sanity!!!

Why would you build your home automation with Sanity? Because you can!

Of course, we are not aiming to replace Homekit in your home. We use home automation to show you the extent that Sanity can read and write to different API's, that Sanity is well capable of reaching out beyond the internet and into the physical world.

The most common setup among our employees is running Raspberry Pis. While the RPi's are user-friendly, they are picky about who their friends are. If you like tinkering with under-powered Linux platforms with a soldering iron, check out that sanity tutorial here.


What we will build

In this example, we use the Phillips Hue system, since it has already solved the "how to traverse your home's firewall" by giving you a publicly available API endpoint you can communicate with. So, what do you need? You will need:

  • Philips Hue Bridge to control your devices
  • Philips Hue Bulb the light you want to control from Sanity
  • Philips Smart Plug to control anything else on your electric grid
    • Your coffee machine?
    • Your disco-ball and smoke machine?
    • Your angle grinder (to scare away thieves!)

Of course, as long as you are in the Philips Universe the Philips provided UI's and functionalities are by far easier to set up and use. But for illustrating the reach of Sanity, as something beyond a CMS, this is a great combination.

Starting our project

Plug in the bulb and the smart plug, and set up your Hue as instructed.

The Sanity part is relatively easy, we have made plugins to support A simple Hue setup. If you want to expand on this example it is a great starting point:

https://github.com/sanity-io/sanity-template-home-automation

Create a new project with the starter:

This starter automatically adds the plugins necessary and the schema used.

sanity create --starter=sanity create --starter=sanity-io/sanity/starter/home-automation

In the root directory of your app you have the example schema. It has a nifty color-picker to control your lamp brightness and color, and a simple on-off button for you smart plug.

Enter Your API endpoint at the top. The starter will inject your Hue Access Token from the environment variable HUE_ACCESS_TOKEN. Insert your devices like in the following schema:

{
  "root": true,
  "project": {
    "name": "home-automation"
  },
  "api": {
    "projectId": "NNNNNNNN",
    "dataset": "production"
  },
  "hue": {
    "api": {
      "endpoint": "https://api.meethue.com/bridge/<whitelist_identifier>",
      "accessToken": "<injected from the starter>"
    }
    "devices":
      "bulbs": [
        "bulb_id_1",
        "buld_id_2"
      ]
      "plugs": [
        "plug_id_1"
      ]
    }   
  }
  "plugins": [
    …,
    "@sanity/home-automation",
    "@sanity/home-automation-hue",
  ],
…
}

See https://developers.meethue.com/develop/hue-api/remote-api-quick-start-guide/ for details on the remote API calls.

Here are your devices in Vision:

Home automation with Sanity

And actually, that's all there is. You should now have a working studio controlling your lamp brightness and color, and a switch for your smart plug.

In addition to the Philips Hue lights, there are many things you can automate in your home right from your Sanity Studio.

Some automation ideas include, but are not limited to:

  • Temperature readings outside and inside your home using a ZigBee type sensor
  • Moisture readings for your many house plants!
  • Adjust the thermostat in your house
  • Adjust the indoor temperature based on weather forecasts
  • Connect your devices to AI processing through sanity plugin IOTAI

GROQ at home

When using the Sanity content lake for integrating data from all your home automation sources you will also be able to use GROQ to do queries to get answers to all the stuff you want to know about your home. For example, easily query how the soil moisture in your favourite house plant has developed for the past 24 hours.