Migration MQTT to 2.4

@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.

Any message means ON or literally any number means ON and non-numbers mean OFF? Ignored?

Any message means ON

OK, then I think this will work.

Assuming you are running OH 2.5 M1 (which you should because of many bug fixes in MQTT 2 binding immediately after 2.4 released there is a new default value in the Map transform. So if you create a .map file containing

=ON

and apply that transform to the incoming Channel any message should get transformed to ON.

Works!
Thank you @rlkoshak
One more thing, can you explain this rule from here: https://www.openhab.org/addons/bindings/mqtt.generic/

rule "Publish all"
when 
      Channel "mqtt:broker:myUnsecureBroker:myTriggerChannel" triggered
then
   //this is variable where all incoming messages is stored separated by # 
   val parts = receivedEvent.split("#")
   //but i do not understand this line 
   sendCommand(parts.get(0), parts.get(1)
end

This is to replace part of the replacement for the EventBus capability. The Rule get’s triggered for all messages published to the myTriggerChannel. The receivedEvent implicit variable carries the event as a String. The format of the String is <topic>#<value>.

So when events are received on the topic we can command the Item of the same name with the value. Thus you can sort of federate OH instances over MQTT by having them publish all events and using a Rule like this to synchronize them.

Since i install new MQTT binding (2 days ago), i have 2 mqtt_v_1 stops. This was never happen before. And strange, mqtt v1 cannot reconnect to broker, only OH restart helps (i try to restart mosquitto service - doesnt help). I use same name “zbox” on mqtt1 and “zbox” in bridge mqtt2 - is this possible fail reason?
OH 25M1 Xubuntu x86

Most likely. Each needs to have it’s own client ID. Only one client with a given client ID can be connected to the broker at a time. When a client tries to connect with the same ID as a client already connected, the broker will kill the connection to the already connected client and use new connection instead.

Hi Mate, do you have a corresponding item file for these lamps ?
Cheers

Hi, after several months I have now decided to migrate to MQTT 2.4.
Most of items are simple ON/OFF item with On=1", Off=0", but I also have some LEDS with a fadein/out and strange on/off message.
With MQTT1 the item was:

Switch	LED_Cucina	    {mqtt=">[localbroker:/N17_LEDCucina/cmd:command:ON:pwm,12,1023,2000],           >[localbroker:/N17_LEDCucina/cmd:command:OFF:pwm,12,0,2000],             <[localbroker:/N17_LEDCucina/LED_Cucina/OUT:state:OFF:0],          <[localbroker:/N17_LEDCucina/LED_Cucina/OUT:state:ON:255],",        autoupdate="false"}`

How can I create an equivalent thing/item in MQTT2.4 ?
Thanks for your help
Lorenzo