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.?
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…
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
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.
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
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
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