[SOLVED] H801 Tasmota - send MQTT command to change color

Hi there,

I would like to do the same as described in this thread.

Unfortunately, I’m facing problems with adopting this to the new mqtt 2.4 binding.

So, the aim is to send a mqtt command from openhab to the H801 controller.

// .items
Number test_mqtt_led
// .sitemap
    Frame label="MQTT send" {
        Switch item=test_mqtt_led mappings=[3="grün", 2="rot", 1="blau", 0="Aus"]
    }
// .rules
rule "MQTT send"
when 
    Item test_mqtt_led changed                       
then
    switch (test_mqtt_led.state as DecimalType) {
        case 0 : {
            // send power = off via mqtt
            logInfo("RULE", "--> LED: AUS")
        }
        case 1 : {
            // send color = 1 via mqtt
            logInfo("RULE", "--> LED: 1")
        }
        case 2 : {
            // send color = 2 via mqtt
            logInfo("RULE", "--> LED: 2")
        }
        case 3 : {
            // send color = 3 via mqtt
            logInfo("RULE", "--> LED: 3")
        }
    }
end

Instead of the comment lines // send ... the mqtt command should be there.
For example if case = 1 color should be set to 1.

In tasmota console of H801 it is possible with color 1
The output is:

tasmota/sonoff-2550-h801/stat/RESULT = {"POWER":"ON","Dimmer":100,"Color":"FF00000000","HSBColor":"0,100,100","Channel":[100,0,0,0,0],"CT":327}

My mqtt broker is defined as Bridge mqtt:broker:mosquitto in .things file.
The H801 thing is

	Thing topic h801_2550 "LED H801 #1 (sonoff-2550-h801)" @ "MQTT" {
      Channels:
        Type switch : h801_2550_switch			"LED H801 #1: Power Switch"             	[ stateTopic="tasmota/sonoff-2550-h801/stat/POWER", commandTopic="tasmota/sonoff-2550-h801/cmnd/POWER", on="ON", off="OFF" ]
        Type colorHSB : h801_2550_color 		"LED H801 #1: Farbe"              			[ stateTopic="tasmota/sonoff-2550-h801/stat/RESULT/HSBColor", commandTopic="tasmota/sonoff-2550-h801/cmnd/HSBColor" ]
		Type string : h801_2550_reachable  		"LED H801 #1: Reachable"          			[ stateTopic="tasmota/sonoff-2550-h801/tele/LWT" ]
		Type number : h801_2550_rssi       		"LED H801 #1: Empfang: RSSI" 				[ stateTopic="tasmota/sonoff-2550-h801/stat/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }

Ok so the tasmota command is color and the payload is 1
The topic would then be: tasmota/sonoff-2550-h801/cmnd and the payload 1
So do this:

		Type number : h801_2550_tasmocolor       		"LED H801 #1: Empfang: Color" 				[ commandTopic="tasmota/sonoff-2550-h801/cmnd/color", formatBeforePublish="%d"]

Create a number item linked to that channel
Link a switch item to the switch channel
Then your rule is:

rule "MQTT send"
when 
    Item test_mqtt_led changed                       
then
    switch (test_mqtt_led.state as DecimalType) {
        case 0 : {
            // send power = off via mqtt
            mySwitchItem.sendCommand(OFF)
            logInfo("RULE", "--> LED: AUS")
        }
        case 1 : {
            // send color = 1 via mqtt
            myTasmoColorItem.sendCommand(1)
            logInfo("RULE", "--> LED: 1")
        }
        case 2 : {
            // send color = 2 via mqtt
            myTasmoColorItem.sendCommand(2)
            logInfo("RULE", "--> LED: 2")
        }
        case 3 : {
            // send color = 3 via mqtt
            myTasmoColorItem.sendCommand(3)
            logInfo("RULE", "--> LED: 3")
        }
    }
end
1 Like

Many thanks! It works like a charm.

Now I’m trying to get the command scheme work.
I suppose it’s quite the same - but nothing happens.

Tasmota console:

CMD: scheme 2
MQT: tasmota/sonoff-2550-h801/stat/RESULT = {"Scheme":2}

My MQTT Channel:

Type number : h801_2550_scheme      	"LED H801 #1: Scheme" 						[ commandTopic="tasmota/sonoff-2550-h801/cmnd/Scheme", formatBeforePublish="%d"]

Log:

[ome.event.ItemCommandEvent] - Item 'OG_bad_l_led1_schemev' received command 2
[vent.ItemStateChangedEvent] - OG_bad_l_led1_schemev changed from 0 to 2
[ome.event.ItemCommandEvent] - Item 'OG_bad_l_led1_scheme' received command 2
==> /var/log/openhab2/openhab.log <==
[INFO ] [.eclipse.smarthome.model.script.RULE] - --> SCHEME: 2
==> /var/log/openhab2/events.log <==
[nt.ItemStatePredictedEvent] - OG_bad_l_led1_scheme predicted to become NULL

Your rule and your item please

// .items
Number      OG_bad_l_led1_scheme            "Bad OG: LED - Scheme"             <light>          (gM,gR,Glicht)      {channel="mqtt:topic:mosquitto:h801_2550:h801_2550_Scheme"}
Number      OG_bad_l_led1_schemev           "Bad OG: LED - Scheme"             <light>          (gM,gR,Glicht)

// .rules

rule "Licht Bad OG - LED1: SCHEME MQTT send"
when 
    Item OG_bad_l_led1_schemev changed                       
then
    switch (OG_bad_l_led1_schemev.state as DecimalType) {
        case 0 : {
            // send power = off via mqtt
            OG_bad_l_led1_scheme.sendCommand(0)
            logInfo("RULE", "--> SCHEME: 0")
        }
        case 1 : {
            // send color = 1 via mqtt
            OG_bad_l_led1_scheme.sendCommand(1)
            logInfo("RULE", "--> SCHEME: 1")
        }
        case 2 : {
            // send color = 2 via mqtt
            OG_bad_l_led1_scheme.sendCommand(2)
            logInfo("RULE", "--> SCHEME: 2")
        }
        case 3 : {
            // send color = 3 via mqtt
            OG_bad_l_led1_scheme.sendCommand(3)
            logInfo("RULE", "--> SCHEME: 3")
        }
    }
end
// .sitemap

Selection item=OG_bad_l_led1_schemev mappings=[ 0="single color for LED light",
														 1="start wake up sequence (same as Wakeup)",
														 2="cycle up through colors using Speed option",
														 3="cycle down through colors using Speed option",
														 4="random cycle through colors using Speed and Fade"]

Commands according to Tasmota wiki

Scheme	Light effects
+ = next scheme
- = previous scheme
0 = single color for LED light (default)
1 = start wake up sequence (same as Wakeup)
2 = cycle up through colors using Speed option
3 = cycle down through colors using Speed option
4 = random cycle through colors using Speed and Fade

Don’t see much wrong
Try that:
commandTopic="tasmota/sonoff-2550-h801/cmnd/scheme"

… without formatBeforePublish="%d" ?

Still nothing happens :frowning:

Type number : h801_2550_scheme      	"LED H801 #1: Scheme" 						[ commandTopic="tasmota/sonoff-2550-h801/cmnd/scheme" ]
[ome.event.ItemCommandEvent] - Item 'OG_bad_l_led1_schemev' received command 2
[vent.ItemStateChangedEvent] - OG_bad_l_led1_schemev changed from 3 to 2
[ome.event.ItemCommandEvent] - Item 'OG_bad_l_led1_scheme' received command 2
==> /var/log/openhab2/openhab.log <==
[INFO ] [.eclipse.smarthome.model.script.RULE] - --> SCHEME: 2
==> /var/log/openhab2/events.log <==
[nt.ItemStatePredictedEvent] - OG_bad_l_led1_scheme predicted to become NULL

No with formatBeforePublish="%d"

scheme instead of Scheme

And monitor the MQTT messages
Check the Tasmota console too

When sending scheme 1 via Tasmota console the output is as follows:

Console

CMD: scheme 1
MQT: tasmota/sonoff-2550-h801/stat/RESULT = {"Scheme":1}

MQTT.fx

{"Scheme":1}

But firing via OH sitemap there are no entries in MQTT.fx and console

Then there is somthing wrong with either your channel or item definition

Please find below the code:

// .things
Thing topic h801_2550 "LED H801 #1 (sonoff-2550-h801)" @ "MQTT" {
      Channels:
        Type switch : h801_2550_switch			"LED H801 #1: Power Switch"             	[ stateTopic="tasmota/sonoff-2550-h801/stat/POWER", commandTopic="tasmota/sonoff-2550-h801/cmnd/POWER", on="ON", off="OFF" ]
        Type colorHSB : h801_2550_color 		"LED H801 #1: Farbe"              			[ stateTopic="tasmota/sonoff-2550-h801/stat/RESULT/HSBColor", commandTopic="tasmota/sonoff-2550-h801/cmnd/HSBColor" ]
		Type number : h801_2550_tasmocolor      "LED H801 #1: Switch RGB" 					[ commandTopic="tasmota/sonoff-2550-h801/cmnd/color", formatBeforePublish="%d" ]
		Type number : h801_2550_dimmer      	"LED H801 #1: Dimmer" 						[ commandTopic="tasmota/sonoff-2550-h801/cmnd/Dimmer", formatBeforePublish="%d" ]
		Type number : h801_2550_scheme      	"LED H801 #1: Scheme" 						[ commandTopic="tasmota/sonoff-2550-h801/cmnd/scheme", formatBeforePublish="%d" ]
		Type number : h801_2550_wakeup      	"LED H801 #1: Wakeup" 						[ commandTopic="tasmota/sonoff-2550-h801/cmnd/Wakeup", formatBeforePublish="%d" ]
		Type number : h801_2550_wakeupd      	"LED H801 #1: Wakeup duration"				[ commandTopic="tasmota/sonoff-2550-h801/cmnd/WakeupDuration", formatBeforePublish="%d" ]
		
		Type string : h801_2550_reachable  		"LED H801 #1: Reachable"          			[ stateTopic="tasmota/sonoff-2550-h801/tele/LWT" ]
		Type number : h801_2550_rssi       		"LED H801 #1: Empfang RSSI" 				[ stateTopic="tasmota/sonoff-2550-h801/stat/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI" ]
    }
// .items
    // LED Controller (H801)
Switch      OG_bad_l_led1_switch            "Bad OG: LED"                      <light>          (gM,gR,Glicht)      {channel="mqtt:topic:mosquitto:h801_2550:h801_2550_switch", autoupdate="false"}
Color       OG_bad_l_led1_color             "Bad OG: LED - Farbe RGB"          <colorlight>     (gM,gR,Glicht)      {channel="mqtt:topic:mosquitto:h801_2550:h801_2550_color"}
Number      OG_bad_l_led1_rgb               "Bad OG: LED - Switch RGB"         <light>          (gM,gR,Glicht)      {channel="mqtt:topic:mosquitto:h801_2550:h801_2550_tasmocolor"}
Number      OG_bad_l_led1_rgbv              "Bad OG: LED - Switch RGB"         <light>          (gM,gR,Glicht) 

Dimmer      OG_bad_l_led1_dim               "Bad OG: LED - Dimmer"             <light>          (gM,gR,Glicht)      {channel="mqtt:topic:mosquitto:h801_2550:h801_2550_Dimmer"}
Dimmer      OG_bad_l_led1_dimv              "Bad OG: LED - Dimmer"             <light>          (gM,gR,Glicht)

Number      OG_bad_l_led1_scheme            "Bad OG: LED - Scheme"             <light>          (gM,gR,Glicht)      {channel="mqtt:topic:mosquitto:h801_2550:h801_2550_Scheme"}
Number      OG_bad_l_led1_schemev           "Bad OG: LED - Scheme"             <light>          (gM,gR,Glicht)

Switch      OG_bad_l_led1_wakeup            "Bad OG: LED - Wakeup"             <light>          (gM,gR,Glicht)      {channel="mqtt:topic:mosquitto:h801_2550:h801_2550_Wakeup"}
Number      OG_bad_l_led1_wakeupd           "Bad OG: LED - Wakeup Duration"    <light>          (gM,gR,Glicht)      {channel="mqtt:topic:mosquitto:h801_2550:h801_2550_WakeupDuration"}

As said before, your RGB color code (#2) works fine …

Here is your problem:
Channel:

		Type number : h801_2550_scheme      	"LED H801 #1: Scheme" 						[ commandTopic="tasmota/sonoff-2550-h801/cmnd/scheme", formatBeforePublish="%d" ]

Item:

Number      OG_bad_l_led1_scheme            "Bad OG: LED - Scheme"             <light>          (gM,gR,Glicht)      {channel="mqtt:topic:mosquitto:h801_2550:h801_2550_Scheme"}

Notice the difference (Think capital letters again)

Uh, your’re right.

Many thanks! And sorry for bothering you …

But it’s still confusing, as the MQTT output is with capital letters … (as I did in #5)

"POWER":"ON","Dimmer":100,"Color":"FF00000000","HSBColor":"0,100,100","Channel":[100,0,0,0,0],"CT":153,"Scheme":0,"Fade":"ON","Speed":1,"LedTable":"OFF"

I think Tasmota doesn’t care