Overview
We were controlling a generic 12V 5050 RGB LED strip with the supplied IR remote, but I wanted to tie it in to OpenHab
Below is what worked for me - hope it helps!
Prerequisites
Hardware
- 5050 RGB LED strip - I already had this one which came with the IR controller and remote.
- MagicHome WIFI RGB LED strip controller - I bought this one which also has IR capability (WF113IR).
Software
- MQTT broker - I use Mosquitto, setup as per its defaults
- On my setup, Mosquitto and OpenHab are running on the same device, at 192.168.1.92
- JSONPath and RegEx Transformation installed in OpenHab
- PaperUI -> Add-ons -> Transformations -> JSONPath Transformation -> Install
- PaperUI -> Add-ons -> Transformations -> RegEx Transformation -> Install
Hardware setup
The MagicHome device is ESP8285 based, which means it can be flashed with Tasmota using the instructions here.
Tasmota setup
MQTT
(http://sonoff-ip-address/mq , or device home -> Configuration -> Configure MQTT )
OpenHab setup
Things
MQTT bridge
I have a separate file which just contains the bridge Thing to my Mosquitto MQTT broker:
Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [
host="192.168.1.92",
secure=false,
port=1883,
clientID="OpenHAB2"
]
lights.things
//RGB1 LED strip
Thing mqtt:topic:swRGB1 "RGB1 LED strip" (mqtt:broker:MosquittoMqttBroker) {
Channels:
Type switch:switch "Power" [
commandTopic="cmnd/swRGB1/POWER",
stateTopic="stat/swRGB1/RESULT",
transformationPattern="JSONPATH:$.POWER",
on="ON",
off="OFF"
]
Type switch : reachable "Reachable" [
stateTopic = "tele/swRGB1/LWT",
on="Online",
off="Offline"
]
Type dimmer:dimmer "Dimmer" [
stateTopic="stat/swRGB1/RESULT",
commandTopic="cmnd/swRGB1/DIMMER",
transformationPattern="REGEX:(.*Dimmer.*)â©JSONPATH:$.Dimmer"
]
Type colorHSB:color "Colour" [
stateTopic="stat/swRGB1/RESULT",
commandTopic="cmnd/swRGB1/HSBColor",
transformationPattern="REGEX:(.*HSBColor.*)â©JSONPATH:$.HSBColor"
]
}
Note: When setting POWER on, Tasmota replies with
stat/swRGB1/RESULT = {"POWER":"ON"}`
This is also picked up by the dimmer and colour channels because they are linked to the same stateTopic (stat/swRGB1/RESULT
). The RegEx transformation first tries to find either the Dimmer
or HSBColor
property in the reply. If it doesnât exist, nothing is passed onto the JSONPath transformation - i.e. the event is ignored, as neither the dimmer nor colour was altered.
Items file
Switch sRGB1 "RGB1 LED Strip" (gLights, gIndoorLights, gUpstairsLights) {channel="mqtt:topic:swRGB1:switch"}
Switch sRGB1Reachable "RGB1 LED Strip" (gReachable) { channel="mqtt:topic:swRGB1:reachable" }
Dimmer dRGB1 "RGB1 LED Strip" {channel="mqtt:topic:swRGB1:dimmer"}
Color cRGB1 "RGB1 LED Strip" {channel="mqtt:topic:swRGB1:color"}
Sitemap file
Switch item=sRGB1 label="RGB strip" icon="light"
Slider item=dRGB1 label="RGB strip [%d %%]" sendFrequency=500
Colorpicker item=cRGB1 label="RGB strip colour"
Advanced sitemap file
This sitemap file is very similar to the one above, but when the MagicHome device goes offline the controls will be hidden and replaced with an error icon
Switch item=sRGB1 label="Sebs bed" icon="light" visibility=[sRGB1Reachable==ON]
Slider item=dRGB1 label="Sebs bed [%d %%]" icon="slider" sendFrequency=500 visibility=[sRGB1Reachable==ON]
Colorpicker item=cRGB1 label="Sebs bed colour" visibility=[sRGB1Reachable==ON]
Text item=sRGB1Reachable label="Sebs bed [%s]" icon="error" visibility=[sRGB1Reachable==OFF]
Rule snippets
//Turn RGB strip on
sRGB1.sendCommand(ON)
//Turn RGB strip off
sRGB1.sendCommand(OFF)
//Dim RGB strip to 50%
dRGB1.sendCommand(50)
//Set RGB strip colour to red (and also turn it on if off)
//Colour value in quote marks is a HSB/HSV value
//First number is Hue, second is Saturation, third is Brightness (or Value)
cRGB1.sendCommand("0,100,100")
Edit 23/12/2020: Updated Things to split the Broker and Generic Thing into two files.
Edit 05/07/2020: Improved things definition for dimmer and colour to remove warnings in logs. Requires REGEX transformation.
Edit 21/06/2020: Updated with improved things definition, additional sitemap configuration, and removed extraneous rules which are no longer required as a result of the improved things definitions.
Edit 18/05/2020: Updated to use default Tasmota MQTT settings for FullTopic
Edit 20/04/2020: Add channel, thing and rule enabling the main switch item to update if the LED strip has been turned on via the IR remote.