# SmartLight

Welcome at the home of SmartLight

As a computer science student, I didn't realize I had to spend hundreds of dollars on a system like Philips Hue. So I decided to develop my own smart lighting system. After several hundred hours of work, a lot of joy but also frustration "SmartLight V3" was created.

## What can SmartLight do?

* You can use cheap RGB LED strips as well as more complex NeoPixel strips.
* The basic module (ESP8266-01) costs less than 5€.
* modern Web-App that you can add to your Homescreen.
* support for IFTTT & Google Home (via IFTTT)

{% content-ref url="/pages/-LWBd0gMBZSDsDpsiwB4" %}
[How does it work?](/about/how-does-it-work)
{% endcontent-ref %}


# How does it work?

{% hint style="success" %}
All communication that contains user data is secured by HTTPs.\
The insecure ws connection will keep inside your local network and will not be accessible from the outside.
{% endhint %}

![](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-85bdc31eab5b8c5c2d1b02302d281298e00499fe%2FSmartLight-V3%20-%20Information%20Flow.png?alt=media)

Unfortunately it is not possible to server the webpage over HTTPs, because then all local requests to the ESPs would be blocked by the browsers security policy which disallows mixed content. That is why the actual website is served over HTTP. To use HTTPs, a completly different architecture would be required that exposes the ESPs to the world wide web. With the current architecture, all communication to the ESPs is 100% local and the network traffic will never leave your home network.


# Links

| Project           | URLs                                                                                                                                                                                                                   |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Documentation     | <p><a href="https://docs.smartlight.ga"><https://docs.smartlight.ga></a></p><p>Repo: <a href="https://github.com/adrianjost/SmartLight-Documentation">SmartLight-Documentation</a></p>                                 |
| Homepage          | <p><a href="https://smartlight.ga"><https://smartlight.ga></a></p><p>Repo: <a href="https://github.com/adrianjost/SmartLight-Homepage">SmartLight-Homepage</a></p>                                                     |
| App               | <p><a href="http://app.smartlight.ga"><http://app.smartlight.ga></a></p><p>Repo: <a href="https://github.com/adrianjost/SmartLight-Web-Client">SmartLight-Web-Client</a></p>                                           |
| Hardware          | <p><a href="https://easyeda.com/adrian.aus.berlin/SmartLight-6ff7039580814d20a6c5e83e7830ab1b">EasyEda Project</a></p><p>Repo: <a href="https://github.com/adrianjost/SmartLight-Hardware">SmartLight-Hardware</a></p> |
| Firmware          | Repo: [SmartLight-Firmware](https://github.com/adrianjost/SmartLight-Firmware)                                                                                                                                         |
| IFTTT Integration | Repo: [SmartLight-IFTTT-Google-Home-Adapter](https://github.com/adrianjost/SmartLight-IFTTT-Google-Home-Adapter)                                                                                                       |


# Build the Hardware

Let's build your SmartLight

## What will be build?

The hardware is designed to be modular and extendable. The Base contains everything to make the ESP8266-01 run and connect to the other modules. This includes several (optional) power connectors as well as Buttons for programming and restarting of the Chip. In addition there are the pinholes for connecting to the other modules.

![the fully equipped base module](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-5c48fa63102c458373fd66df9a1549421916495a%2F20191019_135854.jpg?alt=media)

## What do you need?

Please download the following two repositories:

* <https://github.com/adrianjost/SmartLight-Hardware>
* <https://github.com/adrianjost/SmartLight-Firmware>

The first repository contains the schematics, gerber files, ... to actually order and build the hardware. The second repository contains the firmware for the ESP8266 to communicate with the App.

## Let's start building:

{% content-ref url="/pages/-Lwn2wrK5mg-E0KsGwJL" %}
[Assemble the PCB(s)](/setup/build-the-hardware/assemble-the-pcb-s)
{% endcontent-ref %}


# Get required components

Depending on the devices you want to controle you may can skip several of these components. The circuit board is designed to support several variations and use cases. It is therefore recommended to read the full build tutorial before ordering any components.

## Get the PCB(s)

I have ordered my PCBs from [JLCPCB](https://jlcpcb.com/). The quality is great there and the price is incredibly good, especially for low quantities. Simply upload the gerber files from the hardware repository and order your PCBs.

![](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-8dfefe4356aaeb1fcf2bf8193bb65514ed260546%2Fimage.png?alt=media)

I orderd black PCBs with a thickness of 0.8mm. I wouldn't recommend thinner PCBs but everything else is up to you.

![my order settings - only \~$15 including shipping](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-7c716ca026c11c1572553cc2550e2744d8f46fdf%2Fimage.png?alt=media)

## Get the Components

You obviosly need some components to solder on the PCB.

### Main/Base PCB

#### ESP8266-01

Obviosly you need a ESP8266-01. It will be the brain of the project. If you can try to get one with a black PCB. These will have 1MB of Flash. The blue ones often only have 512K and doesn't cost less.

![ESP8266-01](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-97503e937baf6944185d6dcc854e01384607f67b%2Fimage.png?alt=media)

You also need 2 Push Buttons to flash, reboot and setup the ESP.

![6mm x 6mm push button](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-c94d34958b7628d6a7211266a4323d3ae37b1dc0%2Fimage.png?alt=media)

1x 10k Ohm resistor

#### Power

To Power the project you can use Micro USB, a 2.1mm Barrel Plug or a simple 2.54mm Pin Header.

![supported power connectors](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-dca8285224d1a8d803f69adb33aaff26a7a86eed%2Fpower-connectors.png?alt=media)

In addition you need some voltage converter to create 3V3 for the ESP. You can either use one of these efficient boost converters or you can use a TO-220 based voltage converter like the LD1117V33. I prefer the boost converter, just because it is more efficient, but I haven't had any problems using the LD1117V33 so it's up to you.

![supported power converter boards/chips](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-3f2dba0160fecd1fb381b2e6fbaece94de4e2e17%2Fpower-converter.png?alt=media)

If you decide to use the LD1117V33 you will also need two capacitors (1x 100nF and 1x 10uF)

#### Pin Header

In addition you will need a lot of male and female pin headers.

* 2x4 or 2x (1x4) female pin headers for mounting the ESP8266-01
* 1x4 pin header for programming the ESP

Depending in the LEDs you want to connect you need:

* 1x3 male pin header to connect WS2812B NeoPixel LED Stripes
* 1x5 male pin header to connect to the MOSFET Adapter PCB
  \*
  * 1x3 male pin header just for stability

### MOSFET Adapter PCB

{% hint style="danger" %}
Do not add the R5 Resistor. If connected the ESP won't boot when this PCB is connected. Check [Issue 2](https://github.com/adrianjost/SmartLight-Hardware/issues/2).
{% endhint %}

If you want to controle 12V/24V based LED Stripes you can not connect them directly to the ESP. You need to boost the output signal in order to light them up. For this reason, there exists the MOSFET Adapter PCB. Depending on the number of Channels you wan't to connect you need 1 to 3 MOSFETs. In addition you need *(optional: 3 Pull Down Resitors and)* 3 current limiting Resitors. I can't tell you the exact values you need, because they depend on the MOSFETs you can get. The most important thing is, that the MOSFET can be fully opened by 3V3.\
I am using the IRLB8721PBF TO-220AB 65W MOSFETs and 470 Ohm current limiting resistors.

{% hint style="info" %}
Before buying the resitors, please check that they actually fit onto the PCB.
{% endhint %}

In addition you need a 1x5 and a 1x3 female counterpart to the male headers from the main PCB and a 1x5 male/female header to connect to the LED Stripes.

### Custom Dev Adapter PCB

This PCB is designed for prototyping of new adapter boards. You will need some female counterparts headers to connect this PCB to the base and everything else is up to you.


# Assemble the PCB(s)

## Main/Base PCB

{% hint style="success" %}
It is highly recommended to start with the flat components and do the tall components at last.
{% endhint %}

{% hint style="info" %}
The order presendet here is just the order I assembled the PCB. It is not required to follow this guide strictly and you can skip and reorder all the steps as much as you like. 😉
{% endhint %}

### 1. get the main PCB

![](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-1c36788f527a5977d5b4a2e6f072b669fa2d127c%2Fbase-1.jpg?alt=media)

### 2. R1: 10k Ohm resistor

![10k Ohm resistor](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-bbfe66cf1c860f08f0589ed620d45bb244157dee%2Fbase-2.jpg?alt=media)

### 3. USB1: Micro USB

This is most likely the trickiest part. My way is, to add some solder to the left mounting point and move the port into position while heating up this point. I then secure the other side with more solder and connect the pins at last. When soldering the data pins I add some solder to them and then move the solder iron from the port away until there are no short circuits. (Except the one between the two connections next to VIN, those are required by some cheap power supplies to detect that a device is plugged in.)

![](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-f11f0dd9e5a89b6c862691f04dfe4c56782bdb45%2Fbase-3.jpg?alt=media)

### 4. S1, S2: Push Buttons

I recommend folding the legs before soldering them. This makes soldering way easier.

![](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-866c7f4ae10baccc0b726a193d50679155413ebd%2Fbase-4-2.jpg?alt=media)

![](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-5521f3360b7d4ba0042129610800f7d8397adec2%2Fbase-4-1.jpg?alt=media)

### 5. DC1: Barrel Plug

![](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-ec01e31edf383d6009082fb7e4d0ad175a30d1dc%2Fbase-5.jpg?alt=media)

### 6. M0-M3: Pin Headers

M0 is for programming the ESP, M1 is for stability when connecting adapter PCBs and therefore optional.

{% hint style="danger" %}
I accidently soldered M1 oriented to the top. Do not do this! M1 belongs to the other (bottom) side of the PCB.
{% endhint %}

![top pin header, M1 should go to the bottom. My fault!](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-a18549426016cd7f194d4b2b986c2a5638b56e4c%2Fbase-6-1.jpg?alt=media)

{% hint style="danger" %}
accidently soldered M3 oriented to the bottom. Do not do this! M3 belongs to the other (top) side of the PCB.
{% endhint %}

![bottom pin header](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-ff54336c380048c656379c32dabd81bf6bea388d%2Fbase-6-2.jpg?alt=media)

### 7. U2-U3: Power Converter

#### 7.1 U2: Boost Converter

Step one is, to connect the 3V3 jumper on the backside and verify that the converter outputs 3V3,´. If it is not, you may need t adjust the potentiometer on the front side using a screwdriver. I also got my converter with some pin headers attached which made the soldering very easy. But this step is not required and you can also lay the converter onto the PCB and add a lot of solder to it. This step may require some creativity.

![](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-222e1d738c9a7af853e6f7e18486a2c6113ccf35%2Fbase-7-1.jpg?alt=media)

![](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-7e595d7db37919bea92b4b658fb3254fdca95946%2Fbase-7-2.jpg?alt=media)

#### 7.2 U3: LD1117V33

{% hint style="warning" %}
WIP, this section is not tested and without images. Use your brain and tinker around. Feel free to contribute to this page.
{% endhint %}

* [ ] LD1117V33
* [ ] 10nF capacitor to C1
* [ ] 100uf capacitor to C2

### 8. U1: ESP8266-01

I am using 2x (1x4) pin headers. To solder them more easaly I plugged in an dead ESP to hold them together. But be carefull and fast! To much heat may damage something.

![](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-d83d0261230eee7a29d2b6553d806596241f3e99%2Fbase-8.jpg?alt=media)

### You did it 🥳

## MOSFET Adapter PCB

### 1. R1-Q3: Add current limitig Resistors

{% hint style="warning" %}
Please check that they will not interfere with the MOSFETs added in Step 2. Otherwise you may need some smaller resistors.
{% endhint %}

### 2. Q1-Q3: MOSFETs

Bend the legs of the MOSFETs so they fit into the lines marked on the PCB

### 3. R5-R7: Pull Down Resistors (optional)

{% hint style="danger" %}
Do not add the R5 Resistor. If connected the ESP won't boot when this PCB is connected. Check [Issue 2](https://github.com/adrianjost/SmartLight-Hardware/issues/2).
{% endhint %}

I don't know 100% if they are really necessary but they may help discharge the MOSFET gate and prevent them from breaking. I am currently monitoring this. For now you should be save to skip this step.


# Install Firmware

Firmware Setup - https\://github.com/adrianjost/SmartLight-Firmware

{% hint style="warning" %}
**PREREQUISITES**: you should already know how to programm the ESP8266-01 with the Arduino IDE
{% endhint %}

## Step 1 - Download the Firmware

You can find the latest firmware version in the [releases section](https://github.com/adrianjost/SmartLight-Firmware/releases) of the [github repository](https://github.com/adrianjost/SmartLight-Firmware).

{% hint style="info" %}
Firmware V3 only works with the Web Client V3. It is not backwards compatible.
{% endhint %}

## Step 2 - Connect the PCB to your Computer

Use the M0 connector to connect the PCB to your computer using a programmer.

## Step 3 - Flash Firmware

After downloading the firmware, open `./SmartLight-Firmware/SmartLight-Firmware.ino` with the Arduino IDE.

Make sure that your ESP8266-01 is connected to your PC and you choose the right **Flash Size with at least 128KB SPIFS** for your ESP8266-01.

![My flash config for an ESP8266-01 with 1MB of Flash Storage.](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-37311e943b5f6932f22e535a2998f213b19b462a%2Fimage.png?alt=media)

#### Compile and Upload your Code.

{% hint style="warning" %}

* Hold down both push buttons during the compile step in the Arduino IDE
* release the RESET Button as soon as the IDE say "Upload"
* release the FLASH Button as soon as the upload has started and you see a progress in percent in the IDE
  {% endhint %}

{% hint style="info" %}
Sometimes it is required to power off/disconnect the ESP/Programmer just before you upload the firmware.
{% endhint %}

## Step 3 - Setup

When you Power On the ESP8266-01 it tries (for 5 minutes) to connect to the saved WiFi Access Point. While doing so he is hosting his own Access Point called *"SmartLight - Setup"*.

Connect to it with your PC or Smartphone and open the URL <http://192.168.4.1>. The Password is *"LightItUp"* You must choose your WiFi there and can set up some other things like the type of LED-Strips you connected and what the hostname of the device in your WiFi should be.

{% hint style="success" %}
Don't worry. If you ever want to change the config, restart the ESP and hold down the FLASH Button for >0.5s in the first 5s after restart. This will force the setup mode and opens the SmartLight Setup Access Point.
{% endhint %}

After Saving your settings, the ESP8266-01 should restart and the connected light should light up blue. When the ESP8266-01 established a connection to the given WiFi he will turn off all the lights and waits for your commands.


# Connect your devices

The Setup is almost done now 😊 The only thing todo is to open the webapp, login and add your lamp.

## [Step 0 - Open the Web-App](http://smartlight.hackedit.de/)

[http://app.smartlight.](http://smartlight.hackedit.de/)ga

## Step 1 - Login

![](https://github.com/adrianjost/SmartLight-Documentation/blob/master/.gitbook/assets/image%20\(6\).png)

You can choose one of the given options. Whatever you choose, I promise you that I don't do anything with your data. I created this project purely for myself without any commercial interests. But be aware that for the same reason, this isn't a commercial product so it's totaly possible that I delete your userdata at some point or stop mainting the product at all. To be on the safe side, setup your own instance of the webapp. It's simple, I promise.

{% content-ref url="/pages/-Lwn1dEIKR-B005zP-yC" %}
[Setup the Server (optional)](/setup/setup-the-server-optional)
{% endcontent-ref %}

## Step 2 - Add your Lamps

I think the UI is pretty self-explanatory but to be on the safe side:

### 1. Navigate to "Settings"

![/settings](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-9161f6ea3ccf0d982e9c587cba6a05156a9ed8a1%2FScreenshot-Settings.png?alt=media)

### 2. Click on the "+" below "Lamps:"

![/settings/add/lamp](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-9d194cc65193692675d658de9a374e622b412cd1%2FScreenshot-Settings-add.png?alt=media)

### 3. Fill in the information

Almost all fields are optional, except the Name, Hostname or IP, and the Icon. The Tags are only used to identify lamps when using the IFTTT Google Home adapter.

Add the Lamp by clicking the checkmark at the bottom of the page.

{% hint style="info" %}
I can recommend the App "Fing - Network Scan" to get the hostname and IP of all devices in your local network.
{% endhint %}

### 4. DONE - Control your lamps


# Setup the Server (optional)

How to host your own version of the SmartLight Front- & Back-end


# API

{% hint style="danger" %}
The API is currently WIP and under active development. You can follow the implementation here: <https://github.com/adrianjost/SmartLight-IFTTT-Google-Home-Adapter/issues/8>
{% endhint %}


# Examples


# IFTTT & Google Assistant

This page shows, how you can use the natural language API in combination with Google Assistant to control SmartLight with your voice.

{% hint style="danger" %}
You need an [IFTTT Account](https://ifttt.com/discover) to continue.
{% endhint %}

### 0. Open IFTTT and create a new action

Open: <https://ifttt.com/create>

### 1. Create Action Trigger

1. Choose "Google Assistant" as the Service
2. Choose "Say a phrase with a text ingredient"
3. Enter some phrases with a $ placeholders like: "*Turn the light $*" (figure 1) and choose your language.
4. Click "Create Trigger"

![figure 1](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-3b414baa4b8fb0c97e7449f707840edbe18c6f24%2Fimage.png?alt=media)

### 2. Create Action

1. Choose "Webhooks" (figure 2) as your action service.
2. Fill in the webhook form
   1. URL: `http://localhost:5000/aj-smartlight/us-central1/api/units/setNL`
   2. Method: `POST`
   3. Content Type: `application/JSON`
   4. Body
      1. Open the Web-App, go to settings and create your personal access token. (figure 3)
      2. Body Content: `{ "userid": "YOUR USERID", "token": "YOUR ACCESS TOKEN", "lang": "de", "payload": "{{TextField}}" }`
3. Click "Create Action"

![figure 3](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-516a5da70b7ec21fbb9c2d18d92ddf856320d982%2FScreenshot-Settings-API-Token.png?alt=media)

![figure 2](https://3417828307-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LWBNCVaeiDCEfoDne4Z%2Fuploads%2Fgit-blob-1c2d4747d6688bcb7df371045dc676a4cdd97667%2Fimage.png?alt=media)

### 3. Test it - "Hey Google, turn on the kitchen light"

That's it. Now enjoy using your voice to control your home.\
The API understands a lot of colors and all the named gradients you have saved. If you discover that the Assistant doesn't understand some words correctly, you can give your lamps and groups "tags" which will be handled like aliases.


# Google Home

{% hint style="danger" %}
The API is currently WIP and under active development. You can follow the implementation here: <https://github.com/adrianjost/SmartLight-IFTTT-Google-Home-Adapter/issues/9>
{% endhint %}


