MQTT v 2.4 Items for (Tasmota) LED Strip

Hi,
I’ve got a working environment with Tasmota based LED Stripes and MQTT Binding Version 1.
Now I want to move over to MQTT Bindung Version 2.4
I have an issue in the JSON PATH Transformation.

Here are examples of my working mqtt v1 Items:

String i_mqtt_sonoffMagicHomeLED_1_LEDPower “Sonoff Magic Home LED LED: [%s]” { mqtt=“>[mosquitto:cmnd/sonoffMagicHomeLED_1/POWER:command:*:default],<[mosquitto:stat/sonoffMagicHomeLED_1/RESULT:state:JSONPATH($.POWER):.POWER.]”}

Dimmer i_mqtt_sonoffMagicHomeLED_1_Dimmer “Sonoff Magic Home LED Dimmer [%.0f %%]” {mqtt=“>[mosquitto:cmnd/sonoffMagicHomeLED_1/DIMMER:command:*:default],<[mosquitto:stat/sonoffMagicHomeLED_1/DIMMER:state:JSONPATH($.Dimmer):.Dimmer.]”}

Color i_mqtt_sonoffMagicHomeLED_1_Color “Sonoff B1 1 Color” {mqtt=“>[mosquitto:cmnd/sonoffMagicHomeLED_1/HSBCOLOR:command:*:default],<[mosquitto:stat/sonoffMagicHomeLED_1/RESULT:state:JSONPATH($.HSBColor):.HSBColor.]”}

Number i_mqtt_sonoffMagicHomeLED_1_Speed “Sonoff Magic Home LED LED Speed: [%d]” {mqtt=“>[mosquitto:cmnd/sonoffMagicHomeLED_1/SPEED:command:*:default],<[mosquitto:stat/sonoffMagicHomeLED_1/RESULT:state:JSONPATH($.Speed):.Speed.]”}

Switch i_mqtt_sonoffMagicHomeLED_1_Fade “Sonoff Magic Home LED Fade: [%s]” { mqtt=“>[mosquitto:cmnd/sonoffMagicHomeLED_1/FADE:command:*:default],<[mosquitto:stat/sonoffMagicHomeLED_1/RESULT:state:JSONPATH($.Fade):.Fade.]”}

Number i_mqtt_sonoffMagicHomeLED_1_Schema “Sonoff Magic Home LED Schema: [%d]” {mqtt=“>[mosquitto:cmnd/sonoffMagicHomeLED_1/SCHEME:command:*:default],<[mosquitto:stat/sonoffMagicHomeLED_1/RESULT:state:JSONPATH($.Scheme):.Scheme.]”}

The problem is, that the “RESULT MQTT TOPIC” stat/sonoffMagicHomeLED_1/RESULT covers different values (e.g. speed, dimmer) and I have to filter it in the JSONPATH Definition

Does anybody know , which JSONPATH Transformation Do I have to use to do a 1:1 Migration to mqtt binding version 2.4.?

1 Like

The same one should work. Just change the format, no ( )'s, to look like this.

Type number   : rssi       "WiFi Signal Strength" [ stateTopic="tele/sonoff-b/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]

Hi, Signal is working :wink:

I need Dimmer, Speed, Color, Fade, from my example above. I don’t know how to format…

This topic example shows the config for Dimmer and Fade. I didn’t look close but Color and Speed may be there as well.

You can deduce the other channels required with the example @H102 just gave you. The jsonpath transformation pattern is in there

Yes, but in the example the STATE topic is used. This topic only send after teleperiod (default 300s).
In my current configuration the RESULT topic is used, which is updated after setting the parameter…

In this part of the example I see both STATE and RESULT be used. Or am I missing something?

Thing topic sonoffrf "RF Bridge" @ "Yet Another Room" {
        Type string : reachable     "Reachable"            [ stateTopic="tele/sonoff-rf/LWT" ]
        Type string : recieveddata  "Received Data"        [ stateTopic="tele/sonoff-rf/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data"]
        Type string : recievedsync  "Received Sync"        [ stateTopic="tele/sonoff-rf/RESULT", transformationPattern="JSONPATH:$.RfReceived.Sync"]
        Type string : recievedlow   "Received Low"         [ stateTopic="tele/sonoff-rf/RESULT", transformationPattern="JSONPATH:$.RfReceived.Low"]
        Type string : recievedhigh  "Received High"        [ stateTopic="tele/sonoff-rf/RESULT", transformationPattern="JSONPATH:$.RfReceived.High"]
        Type string : recievedrfkey "Received RfKey"       [ stateTopic="tele/sonoff-rf/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"]
        Type switch : button1       "Button 1"             [ stateTopic="stat/sonoff-rf/RESULT", commandTopic="cmnd/sonoff-rf/RFKEY1", transformationPattern="JSONPATH:$.RfKey1" ]
        ...
        Type switch : button16      "Button 16"            [ stateTopic="stat/sonoff-rf/RESULT", commandTopic="cmnd/sonoff-rf/RFKEY16", transformationPattern="JSONPATH:$.RfKey16" ]
        Type number : rssi          "WiFi Signal Strength" [ stateTopic="tele/sonoff-rf/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    }

So change the topic…
Look you have ALL the information you need.
We are not going to code it for you, you need to figure it out by yourself.
Compare the MQTTv1 config and the MQTTv2 config that H102 gave you and WORK IT OUT
Once you have done that, you’ll be able to do it again WITHOUT the forum spoon feeding you code that you just copy and paste.
Time to walk

1 Like

Hi,

not really. As I said before. The WS2812 LED Stripes sends different RESULT Topics, depending what you change (fade, dimmer, speed, color).
So if you want to use the RESULT topic as an input source for Openhab Things/Items you must filter them, as shown in the mqtt v1 config.
Maybe you should set up such a environment, than you can recognize what I mean.

I will try changig the items, also it’s not the thing I want to do.

A community forum should be the please a question to ask.

Thanks for your replies.

Regards

Helmar

No it doesn’t it’s always the same topic. The payload changes, and you use a transformation to extract the value needed.

Sorry…

A community forum is not a helpdesk and not there to write code for you
We are here to guide, help and teach.
You need to figure it out by yourself:

I give you one:

MQTTv1:

{mqtt=">[mosquitto:cmnd/sonoffMagicHomeLED_1/SPEED:command:*:default],<[mosquitto:stat/sonoffMagicHomeLED_1/RESULT:state:JSONPATH($.Speed):.Speed.]"}

MQTTv2

Type number   : spped       "Speed" [ stateTopic="mosquitto:stat/sonoffMagicHomeLED_1/RESULT", transformationPattern="JSONPATH:$.Speed"]
1 Like

I would like to take over the current dimmer value in a variable in a rule and continue to work with it. Unfortunately, my idea does not work, who can help me please?

.things

Type number : dim2       "LED Stripe dim"    [ stateTopic="stat/LEDRGB-02/STATE", transformationPattern="JSONPATH:$.Dimmer" ,  commandTopic="cmnd/LEDRGB-02/DIMMER" ]

.items

Number 	LED_FADE_02    "Office LED FADE"        ["Lighting"] { channel="mqtt:topic:rgbled:fade2" }

and in .rules

rule "Schalte SteckerOffice aus"
when
	// Time cron "0 40 16 ? * MON-SUN *"  or
	Channel "innogysmarthome:WSC2:SMARTHOME07:bb2b4975f3bf4c318946fb7f45b24ac9:button2" triggered PRESSED 
then	
	// Socket_3DPrinter_08.sendCommand(OFF)
		logInfo("FlagZimmerTaste2", FlagZimmerTaste2.toString)
	if (FlagZimmerTaste2 === false)	{
		FlagZimmerTaste2=true
		logInfo("FlagZimmerTaste2", LED_FADE_02.state)
		val actions = getActions("mqtt","mqtt:broker:myBroker")
		var int rot
		rot=100
		while (rot >=0)	{
			actions.publishMQTT("cmnd/LEDRGB-02/DIMMER", rot.toString)
			rot = rot - 1
			Thread::sleep(100)
		}
		FlagZimmerTaste1=false
	}
end

Protocol:
2019-01-17 20:14:42.956 [vent.ChannelTriggeredEvent] - innogysmarthome:WSC2:SMARTHOME07:bb2b4975f3bf4c318946fb7f45b24ac9:button2 triggered PRESSED

==> /var/log/openhab2/openhab.log <==

2019-01-17 20:14:45.444 [INFO ] [home.model.script.FlagZimmerTaste2-1] - false

2019-01-17 20:14:45.450 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Schalte SteckerOffice aus’: An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.LogAction.logInfo(java.lang.String,java.lang.String,java.lang.Object[]) on instance: null

Not quite sure but maybe the 3 === are the problem?

if (FlagZimmerTaste2 === false)	{

You can try?

if (FlagZimmerTaste2 == false)	{

Could be but you have other problems too:
You need to use the syntax item.state to get an item state
You need to use the syntax item.postUpdate(value) to update the state of an item
Using loops is not recommended and it’s better to use a time for this
I also have reduced the steps to 20 (5 by 5) there should be any visible difference
because a step of 100ms is faster than the time it take to execute the loop itself

Now, why are you using the mqtt action?
Create an MQTT thing with a dimmer channel with a commandTopic and send a command to an item inked to that channel. It would be easier and cleaner.

var timer = null // AT HE TOP OF THE RULES FILE
var Number rot

rule "Schalte SteckerOffice aus"
when
    // Time cron "0 40 16 ? * MON-SUN *"  or
    Channel "innogysmarthome:WSC2:SMARTHOME07:bb2b4975f3bf4c318946fb7f45b24ac9:button2" triggered PRESSED 
then	
    // Socket_3DPrinter_08.sendCommand(OFF)
    logInfo("FlagZimmerTaste2", FlagZimmerTaste2.toString)
    if (FlagZimmerTaste2.state == "false" ) {
        FlagZimmerTaste2.postUpdate("true")
        logInfo("FlagZimmerTaste2", LED_FADE_02.state)
        val actions = getActions("mqtt","mqtt:broker:myBroker")
        rot = 100
        timer = createTimer(now, [ |
            actions.publishMQTT("cmnd/LEDRGB-02/DIMMER", rot.toString)
            rot = rot - 5
            if(rot > 0) {
                timer.reschedule(now.plusMillis(500))
            } else {
                FlagZimmerTaste1.postUpdate("false")
                timer = null
            }
        ])
    }
end