Tasmota flashed MagicHome RGB LED strip controller via mqtt

Tags: #<Tag:0x00007f616d85a630> #<Tag:0x00007f616d85a478> #<Tag:0x00007f616d85a2c0>

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 file

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [host="192.168.1.92", secure=false]
{

	//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 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.

2 Likes

Thanks for your comprehensive post. I’m attempting to implement it but what are the rule snippets?
Can you post the full rule?

Those are just simple lines that you can use in your own rules. They’re not required to control the lights from your sitemap!