Migrating MQTT1 items to MQTT2.4 items

Thanks, great help!

Will this also include JavaScript transformations (incoming & outgoing)?

Thank you Sascha_Billian.
I’ve searched for a whole day to how te setup mqtt in openhab2 and everithing is to version 1.
Now i have working sonoff swith :slight_smile:

But can somebody help me what to add here or change to have my switch to know when it’s turned on by RF Pilot or the hardware button?

Sonoff will publish always the same state if is triggered. that means a MQTT command or pressing the button on the sonoff will always publish the same state.
So i am afraid there is no way to do it like this, but in OpenHab you could have a proxy item (= an item without channel) that then publishes a MQTT command to the sonoff. So if sonoff switches on without this item being set to on => somebody triggered the sonof remotely.
Otherwise sonoff is triggered by openhab:

Switch SonoffProxy
rule "Switch Sonoff from OH"
when
   item SonoffProxy changed from OFF to ON
then
  MyRealSonoffItem.sendCommand(ON)
  logInfo("sonoff rule", "sonoff triggered from OH")
end
1 Like

So if I understand it right, there is no way (without using a proxy item) to reflect on an openHAB sitemap a change to an item that occurred when a physical button was pressed?
I mean, I want my Basic UI switch item to show as ON when my wife switched the light by using the light switch and not the app. Is that possible?
Thanks!

See:

[Q] So in new MQTT 2.4 there is no possibility to configure it using files. The paperUI and adding through Things is the only way?

[A] Wrong. Search the forum, I have posted several examples on how to configure MQTT2 with files.

1 Like

@Sascha_Billian @alexspitz This configuraion knows when the hardware button or rf button was pressed and change state in basicui.

This is now my working settings
mqtt.things

Bridge mqtt:broker:mosquitto "Mosquitto MQTT Broker" @ "MQTT" [ host="localhost", secure=false, port=1883, clientID="Oh2Mqtt2"]
{ 
    // Main Light
    Thing mqtt:topic:SonoffMainLight "Main Light" @ "MQTT"  {
      Channels:
          Type switch : switch "Power Switch" [ 
            stateTopic="tasmota/sonoff-mainlight/POWER", 
            commandTopic="tasmota/sonoff-mainlight/cmnd/POWER",
            on="ON",
            off="OFF"          
          ]
          Type string : state02 "Switch State 02" [ 
            stateTopic="stat/sonoff-mainlight/POWER",
            on="ON",
            off="OFF"
          ]
    }
    
    // Bed Light
    Thing mqtt:topic:SonoffBedLight "Bed Light" @ "MQTT"  {
      Channels:
          Type switch : switch "Power Switch" [ 
            stateTopic="tasmota/sonoff-bedlight/POWER", 
            commandTopic="tasmota/sonoff-bedlight/cmnd/POWER",
            on="ON",
            off="OFF"          
          ]
          Type string : state02 "Switch State 02" [ 
            stateTopic="stat/sonoff-bedlight/POWER",
            on="ON",
            off="OFF"
          ]
    }
    
     // Sonoff Amplifier
    Thing mqtt:topic:SonoffAmplifier "Sonoff Amplifier" @ "MQTT"  {
      Channels:
          Type switch : switch "Power Switch" [ 
            stateTopic="tasmota/sonoff-amplifier/POWER", 
            commandTopic="tasmota/sonoff-amplifier/cmnd/POWER",
            on="ON",
            off="OFF"          
          ]
          Type string : state02 "Switch State 02" [ 
            stateTopic="stat/sonoff-amplifier/POWER",
            on="ON",
            off="OFF"
          ]
    }
    
  
}

sonoff.items

/*
  Main Light
*/
Switch SonoffMainLight_Switch "Main Light Switch" <lightbulb> ["Lighting"] { channel="mqtt:topic:SonoffMainLight:switch" }
String SonoffMainLight_State "Main Light State"  { channel="mqtt:topic:SonoffMainLight:state02", channel="mqtt:topic:SonoffMainLight:switch" }
/*
  Bed Light
*/
Switch SonoffBedLight_Switch "Bed Light Switch" <lightbulb> ["Lighting"] { channel="mqtt:topic:SonoffBedLight:switch" }
String SonoffBedLight_State "Bed Light State"  { channel="mqtt:topic:SonoffBedLight:state02", channel="mqtt:topic:SonoffBedLight:switch" }
/*
  Amplifier
*/
Switch SonoffAmplifier_Switch "Amplifier Switch" <player> ["Switchable"] { channel="mqtt:topic:SonoffAmplifier:switch" }
String SonoffAmplifier_State "Amplifier State"  { channel="mqtt:topic:SonoffAmplifier:state02", channel="mqtt:topic:SonoffAmplifier:switch" }

EDIT (added SONOFF MQTT Config Screen):

6 Likes

Thanks @kaju666
Are these working settings or do you still have problems?

For now it works like a charm

Cool then could you change your post above to:
“This is now my working settings”

Thanks

I am working on migrating my MQTT1 items to MQTT2.4 and it is going pretty well .

Nevertheless, I am stuck migrating some items that required a JS transform call like this

String Location_Den_Samsung "Owntracks Location Den Samsung [%s]" <mqtticon> {mqtt="&lt;[mymosquitto2:owntracks/denis/samsung:state:JS(mqttitude-coordinates.js)]"}

So when I enter

JS(mqttitude-coordinates.js)

in the Incoming value transformation field of the Configure Channel form in Paper UI I always get an error on my Generic MQTT Thing that says

Status: OFFLINE - CONFIGURATION_ERROR Remove and recreate: mqtt:topic:ff8e91b4:Test

What should I write there ?

You should write:
JS:mqttitude-coordinates.js

2 Likes

Yes ! Thank so much for the hint! All my MQTT migration is now done and working very well.

I am SUPER new to this and with very little tech background.
Was struggling with codes and such; searching for conig files (:grin: I am on OpenHAB 2.4 LOL)
Your post sorted it out for me;Sonoff Tasmota running like it should…a Charm!

getting this error with my setup not sure whats wrong it reading but not getting temp in

2019-01-20 15:39:53.111 [WARN ] [eneric.internal.generic.ChannelState] - Incoming payload ‘{“Time”:“2019-01-20T16:39:53”,“DS18B20”:{“Temperature”:17.9},“TempUnit”:“C”}’ not supported by type ‘NumberValue’

state:JSONPATH:$.DS18B20.Temperature

JSONPATH:$.DS18B20.Temperature

1 Like

thanks for that another typo from me been trying for 2 days to get that working

@Sascha_Billian Not like it matters but there should be an opening square bracket [ after the > and before mosquitto I think. I tried to compare your before and after items entry with mine and spotted that little difference.

1 Like