Wifi controlled RGB-LED-Stripes using ESP8266

Tags: #<Tag:0x00007fc20b0609a8>

Goal:

Control cheap (China) RGB-LED-Stripes via OpenHAB without the original IR-Remote – instead we’ll use Wifi.

Solution:

Build Wifi-Controller for the RGB-Stripes and send commands via HTTP.

Controller:

Hardware:

To Build the Controller I followed Chris Klinger’s Instructions (german).
To keep things simple I just hardwired the breadboard prototype. From
the available ESP8266 boards I used the LOLIN D1 mini because it
is pretty cheap (~4€ EU/~2$ China) and I can flash it via USB.

Software:

I use the provided software without any notable personal changes. It is
available on Github.

OpenHAB config:

Items:

//Groups
Group:Color:AVG          RGB_color     "Master Color"   <colorwheel>    (RGB_color)     {alexa="Lighting"}
Group:Switch:OR(ON, OFF) RGB_switch    "Master Switch"  <switch>            (RGB_switch)    {alexa="Switchable"}
Group:Dimmer:AVG         RGB_dimmer    "Master Dimmer"  <switch>            (RGB_dimmer)    {alexa="Lighting"}


//UI Components
Color  wifirgb001_color  "RGB-001" <lightbulb> (RGB_color)   ["Oase"]
Dimmer wifirgb001_dimmer "RGB-001" <lightbulb> (RGB_dimmer)  ["Oase"]
Switch wifirgb001_switch "RGB-001" <lightbulb> (RGB_switch)  ["Oase"]

//Data Exchange
String wifirgb001_json   "RGB-001" <lightbulb> (RGB)         ["Oase"] {http=">[*:POST:http://192.168.1.11/api/v1/state:default]"}


//UI Components
Color  wifirgb002_color  "RGB-002" <lightbulb> (RGB_color)   ["Oase"]
Dimmer wifirgb002_dimmer "RGB-002" <lightbulb> (RGB_dimmer)  ["Oase"]
Switch wifirgb002_switch "RGB-002" <lightbulb> (RGB_switch)  ["Oase"]

//Data Exchange
String wifirgb002_json   "RGB-002" <lightbulb> (RGB)         ["Oase"] {http=">[*:POST:http://192.168.1.12/api/v1/state:default]"}


//UI Components
Color  wifirgb003_color  "RGB-003" <lightbulb> (RGB_color)   ["Oase"]
Dimmer wifirgb003_dimmer "RGB-003" <lightbulb> (RGB_dimmer)  ["Oase"]
Switch wifirgb003_switch "RGB-003" <lightbulb> (RGB_switch)  ["Oase"]

//Data Exchange
String wifirgb003_json   "RGB-003" <lightbulb> (RGB)         ["Oase"] {http=">[*:POST:http://192.168.1.13/api/v1/state:default]"}

Rules:

rule "RGB-001"
when
        Item wifirgb001_color changed or
        Item wifirgb001_switch changed or
        Item wifirgb001_dimmer changed
then
        var HSBType hsbValue
        var int redValue
        var int greenValue
        var int blueValue
        var int brightnessValue
        var String myJSON

        hsbValue = wifirgb001_color.state as HSBType

        redValue = hsbValue.red.intValue
        greenValue = hsbValue.green.intValue
        blueValue = hsbValue.blue.intValue
        brightnessValue = wifirgb001_dimmer.state

        myJSON="{\"state\":\""+wifirgb001_switch.state+"\",\"brightness\":"+brightnessValue+",\"color\":{\"mode\":\"rgb\",\"r\":"+redValue.toString+",\"g\":"+greenValue.toString+",\"b\":"+blueValue.toString+"},\"mode\":\"SOLID\"}"

        sendCommand(wifirgb001_json, myJSON)
end

I use a distinct rule for every of my RGB controllers.

One simplification is possible. The controller can also accept HSV values
directly. However, i didn’t know and came up with the above.

I use my RGB-LED-Stripes mainly in rules to display system status or control them
via Alexa. Therefore, my sitemap is pretty short and does only contain the
group of all strips together:

Sitemap

    Frame label="RGB" {
            Colorpicker     item=RGB_color          label="RGB-Master"
            Slider          item=RGB_dimmer         label="RGB-Dimmer"
            Switch          item=RGB_switch         label="RGB-Switch"
    }

Final Remarks

This is my first project with OpenHAB and custom build hardware. For my
setting this works already pretty well.

5 Likes