Skip to content

Commit

Permalink
Finally add support for RGBW lights, per corbanmailloux#7.
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanmailloux committed Jul 31, 2017
1 parent 72d40a2 commit 94d1f74
Show file tree
Hide file tree
Showing 4 changed files with 511 additions and 6 deletions.
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This project adds an easy way to create DIY lighting for [Home Assistant](https:

I was frustrated that the built-in MQTT light didn't support transitions (fading between colors/brightnesses), and that it uses multiple separate calls to set the different values (state (on/off), brightness, color), so I decided to make my own version. As of version 0.26, the [MQTT JSON light platform](https://home-assistant.io/components/light.mqtt_json/) has been merged into Home Assistant.

By sending a JSON payload (in an MQTT message), Home Assistant can include whichever fields are necessary, reducing the round trips from 3 to 1. For example, this is a sample payload including all of the fields:
By sending a JSON payload (in an MQTT message), Home Assistant can include whichever fields are necessary, reducing the round trips from 3 to 1. For example, this is a sample payload including most of the fields:
```json
{
"state": "ON",
Expand All @@ -23,16 +23,40 @@ By sending a JSON payload (in an MQTT message), Home Assistant can include which
To set this system up, you need to configure the [MQTT JSON light](https://home-assistant.io/components/light.mqtt_json/) component in Home Assistant and set up a light to control. This guide assumes that you already have Home Assistant set up and running. If not, see the installation guides [here](https://home-assistant.io/getting-started/).

### The Home Assistant Side
1. In your `configuration.yaml`, add the following:
1. In your `configuration.yaml`, add the following, depending on the supported fatures of the light:

```yaml
# Only one color:
light:
+ platform: mqtt_json
- platform: mqtt_json
name: mqtt_json_light_1
state_topic: "home/rgb1"
command_topic: "home/rgb1/set"
brightness: true
optimistic: false
qos: 0

# OR: RGB:
light:
- platform: mqtt_json
name: mqtt_json_light_1
state_topic: "home/rgb1"
command_topic: "home/rgb1/set"
brightness: true
rgb: true
optimistic: false
qos: 0

# OR: RGBW
# RGB
light:
- platform: mqtt_json
name: mqtt_json_light_1
state_topic: "home/rgb1"
command_topic: "home/rgb1/set"
brightness: true
rgb: true
white_value: true
optimistic: false
qos: 0
```
Expand All @@ -43,7 +67,7 @@ To set this system up, you need to configure the [MQTT JSON light](https://home-
I'm using ESP8266-01 microcontrollers for my lights because they are so cheap and small. The downside of the size and price is that programming them can be a bit of a hassle. There are many sites that go into detail, so I won't do it here. You'll need an ESP set up to work with the Arduino IDE. See the readme [here](https://github.com/esp8266/Arduino) for instructions.

1. Using the Library Manager in the Arduino IDE, install [ArduinoJSON](https://github.com/bblanchon/ArduinoJson/) and [PubSubClient](http://pubsubclient.knolleary.net/). You can find the Library Manager in the "Sketch" menu under "Include Library" -> "Manage Libraries..."
2. Open the appropriate folder for your lights. For an RGB light, use `mqtt_esp8266_rgb`. For a light that only supports brightness, use `mqtt_esp8266_brightness`.
2. Open the appropriate folder for your lights. For an RGB light, use `mqtt_esp8266_rgb`. For a light that only supports brightness, use `mqtt_esp8266_brightness`, and for an RGBW light, use `mqtt_esp8266_rgbw`.
3. Update the `config-sample.h` file with your settings for pin numbers, WiFi settings, and MQTT settings.
4. Ensure that the `CONFIG_MQTT_CLIENT_ID` setting is a unique value for your network.
5. Set `CONFIG_MQTT_TOPIC_STATE` and `CONFIG_MQTT_TOPIC_SET` to match the values you put in your `configuration.yaml`.
Expand Down
4 changes: 2 additions & 2 deletions mqtt_esp8266_brightness/mqtt_esp8266_brightness.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* See https://github.com/corbanmailloux/esp-mqtt-rgb-led
*/

// Set configuration options for pings, WiFi, and MQTT in the following file:
// Set configuration options for pins, WiFi, and MQTT in the following file:
#include "config.h"

// https://github.com/bblanchon/ArduinoJson
Expand All @@ -18,7 +18,7 @@
#include <PubSubClient.h>

const int redPin = CONFIG_PIN_LIGHT;
const int txPin = 1; // On-board blue LED
const int txPin = BUILTIN_LED; // On-board blue LED
// const int greenPin = 2;
// const int bluePin = 3;

Expand Down
30 changes: 30 additions & 0 deletions mqtt_esp8266_rgbw/config-sample.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This is a sample configuration file for the "mqtt_esp8266_rgbw" light.
*
* Change the settings below and save the file as "config.h"
* You can then upload the code using the Arduino IDE.
*/

// Pins
#define CONFIG_PIN_RED 0
#define CONFIG_PIN_GREEN 2
#define CONFIG_PIN_BLUE 3
#define CONFIG_PIN_WHITE 4

// WiFi
#define CONFIG_WIFI_SSID "{WIFI-SSID}"
#define CONFIG_WIFI_PASS "{WIFI-PASSWORD}"

// MQTT
#define CONFIG_MQTT_HOST "{MQTT-SERVER}"
#define CONFIG_MQTT_USER "{MQTT-USERNAME}"
#define CONFIG_MQTT_PASS "{MQTT-PASSWORD}"

#define CONFIG_MQTT_CLIENT_ID "ESPRGBWLED" // Must be unique on the MQTT network

// MQTT Topics
#define CONFIG_MQTT_TOPIC_STATE "home/rgbw1"
#define CONFIG_MQTT_TOPIC_SET "home/rgbw1/set"

#define CONFIG_MQTT_PAYLOAD_ON "ON"
#define CONFIG_MQTT_PAYLOAD_OFF "OFF"
Loading

0 comments on commit 94d1f74

Please sign in to comment.