Migration MQTT to 2.4

Hi,

After two evenings of trying to migrate my MQTT 2.3 Item to 2.4, I am close to giving up and installing legacy.

This is the original item:

Number:Temperature Outside_Temperature “Temperatur [%.1f %unit%]” (Outside, gTemperature) { mqtt="<[lokal:openhab/garten/temperature:state:default]" }

This is what I came up until now for Thing and Item.

Bridge mqtt:broker:lokal [ host=“10.0.2.41”, secure=false, username=“openHAB” ]
{
Thing topic MQTT_THING {
Channels:
Type number : Outside_Temperature “Außentemperatur” [stateTopic=“openhab/garten/temperature” ]
}
}

Number:Temperature Outside_Temperature “Temperatur [%.1f %unit%]” (Outside, gTemperature) { channel=“mqtt:lokal:MQTT_THING:Outside_Temperature” }

Long story short. It does not work… Any help is appreciated.

Daniel

ps. does anyone know why the documentation states this as correct “Thing mqtt:topic:mything” however this format gives me an error message?

pps. what does it even mean that a broker has a thing with the name topic and this thing has a channel? If I read the documentation correctly I would just put all my MQTT things into the channels, correct?

1 Like

The correct syntax for your item should be:

Number Temperature “Temperatur [%.1f %unit%]” (Outside, gTemperature) { channel=“mqtt:topic:lokal:MQTT_THING:Outside_Temperature” }

Thanks, however this still does not work. Is there any way to debug? I just don’t get any output in the logs

Have you tried configure the things with PaperUI? I succeeded without any major problems:

In order to better help new users I’m not using .things files anymore so I can’t speak to the specific syntax of the Bridge and Things and Channels.

From the little I have done though I can say you need to watch the online status of the Bridge because if it goes offline then none of the Things associated with it will work. This caught me up.

Watch openhab.log for error messages too. This is how I discovered why my Bridge didn’t connect.

Sascha’s tutorial is pretty good. Even if you are using .things files there might be something useful there to help with this problem.

1 Like

I totally agree with @rlkoshak, however I’ m using the files and have it working.
Additionally I use mqtt-spy to check wether the commands are actually send.
Please show your log entries , we might find a clue.

I now configured the thing (bridge and generic number thing) using paper ui. I get the error “java.lang.Exception: No MQTT client”.

The Generic Thing shows OFFLINE - COMMUNICATION ERROR the Broker seems to be online.

With MQTT.fx I can connect to my broker just fine.

EDIT: A restart of OpenHab seems to have fixed the problem…

This is a working example from my things file:

Bridge mqtt:broker:mosquitto "MQTT Broker" [ host="10.200.0.4", port=1883, clientid="openhab", username="home", password="xxxx" ]
{
    Thing topic rgbw1 "Ambient Light 1" {
	    Channels:
		Type switch : state "OnOff" [ stateTopic="openhab/RGBWController1/relay/0", commandTopic="openhab/RGBWController1/relay/0/set" ]
		Type number : brightness "Brightness" [ stateTopic="openhab/RGBWController1/brightness", commandTopic="openhab/RGBWController1/brightness/set" ]
		Type number : white "White" [ stateTopic="openhab/RGBWController1/channel/3", commandTopic="openhab/RGBWController1/channel/3/set" ]
		Type colorRGB  : rgb "Color" [ stateTopic="openhab/RGBWController1/rgb", commandTopic="openhab/RGBWController1/rgb/set" ]
    }
    Thing topic rgbw2 "Ambient Light 2" {
	    Channels:
		Type switch : state "OnOff" [ stateTopic="openhab/RGBWController2/relay/0", commandTopic="openhab/RGBWController2/relay/0/set" ]
		Type number : brightness "Brightness" [ stateTopic="openhab/RGBWController2/brightness", commandTopic="openhab/RGBWController2/brightness/set" ]
		Type number : white "White" [ stateTopic="openhab/RGBWController2/channel/3", commandTopic="openhab/RGBWController2/channel/3/set" ]
		Type colorRGB  : rgb "Color" [ stateTopic="openhab/RGBWController2/rgb", commandTopic="openhab/RGBWController2/rgb/set" ]
    }
}
3 Likes

Resolved in OH 2.5 snapshot, appears if you configure via textual files.

@David_Graeff
Hi,
I’m struggling with the dimmer type channel/dimmer item combo. The Dimmer item can send PercentType commands (0…100) which should be converted on thing level to 0…255 range expected by the device.
The NumberValue class doesn’t apply any min/max transformation to percent type commands only for decimals:

...
           else if (command instanceof PercentType) {
                numberValue = ((PercentType) command);
            } else if (command instanceof DecimalType) {
                double v = ((DecimalType) command).doubleValue();
                v = (v - min) * 100.0 / (max - min);
                numberValue = new PercentType(new BigDecimal(v));
            } 
...

Any suggestion how to archive this?
I’m using Number channels with Setpoint controls on sitemap as workaround but it renders ugly…
Thanks

Outbound transformations are coming soon. You need a proxy item for now

Hi,
I have a problem with the migration from oh2.3 stable to oh2.4 stable (MQTTv2):
on the picture you can see that with the new version of the mqtt bindings “on” and “OFF” can be seen in the sitemap, at the bottom of the picture you can see the old mqtt binding. how can I remove this “ON” resp. “OFF”?

MQTTv2:

Bridge mqtt:broker:Mosquitto [ host="localhost", port=1883, clientid="xxx", secure=false, username="xxx", password="xxx"]
{
    Thing topic sonoff1Basic "sonoff1 BASIC" {
    Channels:
        Type switch : StatusSonoff1 "EIN/AUS" [ stateTopic="stat/sonoff1/POWER", commandTopic="cmnd/sonoff1/POWER" ]
        Type switch : ReachableSonoff1 "Erreichbarkeit" [ stateTopic="tele/sonoff1/LWT", transformationPattern="MAP:reachable.map" ]
        Type number : RSSISonoff1 "RSSI" [ stateTopic="tele/sonoff1/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI" ]
        Type string : UptimeSonoff1 "Uptime" [ stateTopic="tele/sonoff1/STATE", transformationPattern="JSONPATH:$.Uptime" ]
        Type string : FirmwareSonoff1 "Firmware" [ stateTopic="tele/sonoff1/INFO1", transformationPattern="JSONPATH:$.Version" ]
    }
}
Switch                  sonoff1                 "EIN/AUS"                       <switch>        (gAnwensenheitsSimulation)  { channel="mqtt:topic:Mosquitto:sonoff1Basic:StatusSonoff1" }
Switch                  sonoff1_Reachable       "sonoff1 BASIC"                 <switch>                                    { channel="mqtt:topic:Mosquitto:sonoff1Basic:ReachableSonoff1" }
Number                  sonoff1_RSSI            "RSSI [%d %%]"                  <wlan>                                      { channel="mqtt:topic:Mosquitto:sonoff1Basic:RSSISonoff1" }
String                  sonoff1_uptime          "Uptime [%s]"                   <clock>                                     { channel="mqtt:topic:Mosquitto:sonoff1Basic:UptimeSonoff1" }
String                  sonoff1_Firmware        "Firmware [%s]"                 <firmware>                                  { channel="mqtt:topic:Mosquitto:sonoff1Basic:FirmwareSonoff1" }

MQTTv1:

Switch                  sonoff2                 "EIN/AUS"                       <switch>        { mqtt=">[broker:cmnd/sonoff2-pow/POWER:command:*:default], 
                                                                                                        <[broker:stat/sonoff2-pow/POWER:state:default]" 
                                                                                                }
Switch                  sonoff2_Reachable       "sonoff2 POW"                   <switch>        { mqtt="<[broker:tele/sonoff2-pow/LWT:state:MAP(reachable.map)]" }
Number                  sonoff2_RSSI            "RSSI [%d %%]"                  <wlan>          { mqtt="<[broker:tele/sonoff2-pow/STATE:state:JSONPATH($.Wifi.RSSI)]" }
String                  sonoff2_uptime          "Uptime [%s]"                   <clock>         { mqtt="<[broker:tele/sonoff2-pow/STATE:state:JSONPATH($.Uptime)]" }

// 
Switch                  sonoff3                 "EIN/AUS"                       <switch>                                { mqtt=">[broker:cmnd/sonoff3-th/POWER:command:*:default], 
                                                                                                                                <[broker:stat/sonoff3-th/POWER:state:default]" 
                                                                                                                        }
Switch                  sonoff3_Reachable       "sonoff3 TH16"                  <switch>                                { mqtt="<[broker:tele/sonoff3-th/LWT:state:MAP(reachable.map)]" }
Number                  sonoff3_RSSI            "RSSI [%d %%]"                  <wlan>                                  { mqtt="<[broker:tele/sonoff3-th/STATE:state:JSONPATH($.Wifi.RSSI)]" }
Number:Temperature      sonoff3_temp            "Temperature  [%.1f °C]"        <temperature>  (gTemperatureFireAlarm)  { mqtt="<[broker:tele/sonoff3-th/SENSOR:state:JSONPATH($.AM2301.Temperature)]" }
Number                  sonoff3_humidity        "Luftfeuchte  [%.1f %%]"                                                <humidity>      { mqtt="<[broker:tele/sonoff3-th/SENSOR:state:JSONPATH($.AM2301.Humidity)]" }
String                  sonoff3_uptime          "Uptime [%s]"                                                           <clock>         { mqtt="<[broker:tele/sonoff3-th/STATE:state:JSONPATH($.Uptime)]" }

Frame {
    	Text label="sonfoffs" icon="sonoff" {
			Frame label="sonoff1" {
				Switch 	item=sonoff1_Reachable 		mappings=[ON="online ✔"] 		icon="connected" 	visibility=[sonoff1_Reachable=="ON"]
				Switch 	item=sonoff1_Reachable 		mappings=[OFF="offline ✘"] 		icon="error" 		visibility=[sonoff1_Reachable!="ON"]
				Switch 	item=sonoff1 																	visibility=[sonoff1_Reachable=="ON"]
				Text 	item=sonoff1_RSSI 										 						visibility=[sonoff1_Reachable=="ON"]
				Text 	item=sonoff1_uptime 											 				visibility=[sonoff1_Reachable=="ON"]
				Text 	item=sonoff1_Firmware 											 				visibility=[sonoff1_Reachable=="ON"]
			}

			Frame label="sonoff2" {
				Switch 	item=sonoff2_Reachable 		mappings=[ON="online ✔"] 		icon="connected" 	visibility=[sonoff2_Reachable=="ON"]
				Switch 	item=sonoff2_Reachable 		mappings=[OFF="offline ✘"]		icon="error" 		visibility=[sonoff2_Reachable!="ON"]
				Switch 	item=sonoff2 																	visibility=[sonoff2_Reachable=="ON"]
				Text 	item=sonoff2_RSSI 													 			visibility=[sonoff2_Reachable=="ON"]
				Text 	item=sonoff2_uptime 														 	visibility=[sonoff2_Reachable=="ON"]
			}

			Frame label="PC-KELLER" {
				Switch 	item=sonoff3_Reachable 		mappings=[ON="online ✔"] 		icon="connected"	visibility=[sonoff3_Reachable=="ON"]
				Switch 	item=sonoff3_Reachable 		mappings=[OFF="offline ✘"]		icon="error" 		visibility=[sonoff3_Reachable!="ON"]
				Switch 	item=sonoff3 																	visibility=[sonoff3_Reachable=="ON"]
				Text 	item=sonoff3_RSSI 													 			visibility=[sonoff3_Reachable=="ON"]
				Text 	item=sonoff3_temp 																visibility=[sonoff3_Reachable=="ON"]
				Text 	item=sonoff3_humidity 															visibility=[sonoff3_Reachable=="ON"]
				Text 	item=sonoff3_uptime 														 	visibility=[sonoff3_Reachable=="ON"]
			}
1 Like

Same problem here, my solution was to use a MAP transformation and hide the unwanted state. This problem is related to the new MQTT binding, perhaps there is a more elegant solution that I dont know.

Are you sure that this problem (a switch item showing its ON /OFF as text additionally) is related to MQTT?
IMHO it is a problem (or even a wanted? new feature) of the sitemap.

@fmrenan @miwok

Just put an empty [] into the label of the item to make the item’s value disappear:

Switch                  sonoff2                 "EIN/AUS []" 
1 Like

Maybe the MQTT binding is not the right place to implement this outbound transformation. I have a feeling that implementing it on profile level would be a better solution. WDYT?

I think we are all in agreement with this but that is a longer term project. Adding outbound transforms to the MQTT binding is a stop gap solution until something like that gets implemented.

David did say elsewhere that profiles will probably not be the right approach but he didn’t provide details for why. I suspect profiles are set up to only process incoming data.

Thanks for pointing, it works. However, I do not understand the cause of the problem. with version MQTT v1 I did not have this problem …

The mqtt2 addon does things more … accurate, for example correctly defining the state presentation including a unit if necessary etc.

1 Like

Please help convert to new binding:

Switch	ESP_Dock_State "Dock online" <network> { expire="5m,command=OFF", mqtt="<[zbox:/esp/esp-dock/sensors/uptime:state:ON]" }

I need to trasform any number value (‘10’ for example) from /esp/esp-dock/sensors/uptime topic to ON state.