[SOLVED] New MQTT binding 2.4

I have newly installed my raspberry pi with mosquitto and openhab 2.4
Now i would like to use the new mqtt binding to read data from sensors like temperature and humidity.
What is did first is creating the .things file:

Bridge mqtt:broker:broker [ host="MyBroker IP", secure=true, username="MyUserName", password="MyPasswd" ]
{
  Thing topic miflora {
  Channels:
      Type number : temperature "Air Temperature"   [ stateTopic="sensor/temperature_celsius"]
      Type number : humidity "Humidity"  [stateTopic="sensor/humidity"]
   }

}

I can then see in the openhab.log that openhab makes a connection to mosquitto.
First question did i made my things file the correct way?

I have created a .items file with the following content:

Number temperature "Air Temperature"[%.1f Ā°C]  {channel="mqtt:sensor-temperature_celsius:broker:miflora:temperature"}
Number humidity "Humidity" [%d %%] {channel="mqtt:sensor-humidity:miflora:humidity"}

Second quiestion, did i made my .items the correct way?

Then i made the .sitemap with the following content:

sitemap temp label=ā€œtempā€
{
Frame label=ā€œtempā€ {

Text item=dht_temperature
Text item=dht_humidity

Text item=Temperature
Text item=Humidity

}
}

Third question is my sidemap made the correct way.
When i look a the sitemap i do see the text: Temperature and Humidity, but i donā€™t see the C or % sings and also no numbers.

Any help would be appreciated.
Greetings

1 Like
channel="mqtt:topic:broker:miflora:temperature"
Thing mqtt:topic:miflora
channel="mqtt:topic:miflora:temperature"
1 Like

Sorry, that is what I meant, forgot to delete the ā€˜brokerā€™ bitā€¦

1 Like

Thanks for the replyā€™s
Will play around and read some more. If i need more help al post back of not iā€™l close the topic.
Greetings

The ā€œbrokerā€ witch is in the code is the name of my broker, so sould that not be in there ?

I do now receive a error aboute [%.1f Ā°C] pasrt:

Configuration model 'miflora1.items' has errors, therefore ignoring it: [1,39]: no viable alternative at input '%'

this is the item, i removed the second item, will add it when i have it working.
Number temperature "Air Temperature" [%.1f Ā°C] {channel="mqtt:topic:miflora:temperature"}

In the PUI i do see Generic MQTT Thing online:

Generic MQTT Thing ONLINE

Generic MQTT Thing

mqtt:topic:broker:miflora

and the MQTT Broker online:

MQTT Broker ONLINE

MQTT Broker

mqtt:broker:broker

Greetings

ā€œ---------ā€

"Air Temperature[%.1f Ā°C]"

special attention needs to be paid to copying paste

Thanks all for the help, its now working.
Info for others with this problem.

my .items

Number Temperature "Air Temperature[%.1f Ā°C]" {channel="mqtt:topic:broker:miflora:temperature"}
    Number Humidity "Humidity[%d %%]" {channel="mqtt:topic:broker:miflora:humidity"}

my .sitemap

    sitemap temp label="temp"
    {
            Frame label="temp" {


    Text item=Temperature
    Text item=Humidity


    }
    }

My .things

Bridge mqtt:broker:broker [ host="192.168.178.192", secure=false, clientid="openhab", username="openhab2", password="Mypasswd" ]
    {
      Thing topic miflora {
       Channels:
         Type number : temperature "Air Temperature"   [ stateTopic="sensor/temperature_celsius"]
         Type number : humidity "Humidity"  [stateTopic="sensor/humidity"]
        }
    }

Greetings

I do not think so

What do you mean?

you have to change

ā€œ 
to 
 "

I just tried that, but for some reason it keeps type the wrong ones.

Thatā€™s because you are not using the code fences

Thanks, i think i now have them all the correct way

Q1:When the new MQTT binding looses its connection, it there anything I can do to trigger a reconnect? e.g. a rule, some setting in the .things file.

Q2: Is there a way to not trigger any more mqtt messages out of a rule when the Broker is disconnected? e.g can I check the status of the ā€œactionsā€ variable before I do an

actions.publishMqtt(ā€œtopicā€,ā€œsome messageā€).

mqtt:broker:solace [ host="m11.cloudmqtt.com", port=11403, username="username", clientID="someClient", qos=0, password="somePW" ]

val actions = getActions(ā€œmqttā€,ā€œmqtt:broker:solaceā€)
actions.publishMQTT(ā€œmoosecabin/homeautomation/persistenceā€,i.name + ā€œ,ā€ + i.state)

2018-12-28 16:00:37.044 [INFO ] [ansport. **mqtt** .internal.ClientCallback] - MQTT connection to 'm11.cloud **mqtt** .com' was lost
org.eclipse.paho.client. **mqtt** v3.MqttException: Connection lost
at org.eclipse.paho.client. **mqtt** v3.internal.CommsReceiver.run(CommsReceiver.java:181) [213:org.eclipse.paho.client. **mqtt** v3:1.2.0]

at org.eclipse.paho.client. **mqtt** v3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:92) ~[?:?]

at org.eclipse.paho.client. **mqtt** v3.internal.CommsReceiver.run(CommsReceiver.java:133) ~[?:?]

1.Solved using dimmer not using number (how use number?)

Troubles to create mqtt Things file. on way with paperUI its work.
wats is my trouble on Code?:

Its xiaomi smoke detector an cc2531 on zigbee2mqtt


mqtt.things

Bridge mqtt:systemBroker:embedded-mqtt-broker
{
    // Rauchmelder 1
    Thing mqtt:topic:Rauchmelder_1 "Rauchmelder 1" @ "MQTT"  {
      Channels:
          Type contact : Rauchmelder1_Rauch "Rauchmelder1 Rauch" [ 
            stateTopic="zigbee2mqtt/Rauchmelder1", 
            transformationPattern="JSONPATH:$.smoke", 
            on="true",
            off="false"          
          ]
         
          Type dimmer : Rauchmelder1_battery "Rauchmelder1 battery" [ 
            stateTopic="zigbee2mqtt/Rauchmelder1",
            transformationPattern="JSONPATH:$.battery"
          ]
    }

        // Rauchmelder 2
    Thing mqtt:topic:Rauchmelder_2 "Rauchmelder 2" @ "MQTT"  {
      Channels:
          Type contact : Rauchmelder2_Rauch "Rauchmelder2 Rauch" [ 
            stateTopic="zigbee2mqtt/Rauchmelder2", 
            transformationPattern="JSONPATH:$.smoke", 
            on="true",
            off="false"          
          ]
         
          Type dimmer : Rauchmelder2_battery "Rauchmelder2 battery" [ 
            stateTopic="zigbee2mqtt/Rauchmelder2",
            transformationPattern="JSONPATH:$.battery"
          ]
    }

            // Rauchmelder 3
    Thing mqtt:topic:Rauchmelder_3 "Rauchmelder 3" @ "MQTT"  {
      Channels:
          Type contact : Rauchmelder3_Rauch "Rauchmelder3 Rauch" [ 
            stateTopic="zigbee2mqtt/Rauchmelder3", 
            //commandTopic=".....",
            //retained=false,
            //postCommand="",
            transformationPattern="JSONPATH:$.smoke", 
            //formatBeforePublish="%s",
            on="true",
            off="false"          
          ]
         
          Type dimmer : Rauchmelder3_battery "Rauchmelder3 Battery" [ 
            stateTopic="zigbee2mqtt/Rauchmelder3",
            transformationPattern="JSONPATH:$.battery"
          ]
    }



}

mqtt.items


Contact     RAUCHMELDER_1_RAUCH     "Rauchmelder Kinderzimmer Rauch"        {channel="mqtt:topic:Rauchmelder_3:Rauchmelder1_Rauch" }
Dimmer      RAUCHMELDER_1_Battery   "Rauchmelder Kinderzimmer Battery"      {channel="mqtt:topic:Rauchmelder_3:Rauchmelder1_battery" }

Contact     RAUCHMELDER_2_RAUCH     "Rauchmelder Schlafzimmer Rauch"        {channel="mqtt:topic:Rauchmelder_3:Rauchmelder2_Rauch" }
Dimmer      RAUCHMELDER_2_Battery   "Rauchmelder Schlafzimmer Battery"      {channel="mqtt:topic:Rauchmelder_3:Rauchmelder2_battery" }

Contact     RAUCHMELDER_3_RAUCH     "Rauchmelder Wohnen Rauch"              {channel="mqtt:topic:Rauchmelder_3:Rauchmelder3_Rauch" }
Dimmer      RAUCHMELDER_3_Battery   "Rauchmelder Wohnen Battery"            {channel="mqtt:topic:Rauchmelder_3:Rauchmelder3_battery" }

LOG

018-12-30 20:16:48.219 [ERROR] [ansport.mqtt.internal.ClientCallback] - MQTT message received. MqttMessageSubscriber#processMessage() implementation failure

java.lang.IllegalArgumentException: Value must be between 0 and 100

	at org.eclipse.smarthome.core.library.types.PercentType.validateValue(PercentType.java:58) ~[?:?]

	at org.eclipse.smarthome.core.library.types.PercentType.<init>(PercentType.java:53) ~[?:?]

	at org.eclipse.smarthome.core.library.types.DecimalType.as(DecimalType.java:160) ~[?:?]

	at org.eclipse.smarthome.core.internal.items.ItemStateConverterImpl.convertToAcceptedState(ItemStateConverterImpl.java:58) ~[?:?]

	at org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl.sendUpdate(ProfileCallbackImpl.java:135) ~[?:?]

	at org.eclipse.smarthome.core.thing.internal.profiles.SystemDefaultProfile.onStateUpdateFromHandler(SystemDefaultProfile.java:54) ~[?:?]

	at org.eclipse.smarthome.core.thing.internal.CommunicationManager.lambda$9(CommunicationManager.java:477) ~[?:?]

	at org.eclipse.smarthome.core.thing.internal.CommunicationManager.lambda$11(CommunicationManager.java:497) ~[?:?]

	at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?]

	at org.eclipse.smarthome.core.thing.internal.CommunicationManager.handleCallFromHandler(CommunicationManager.java:493) ~[?:?]

	at org.eclipse.smarthome.core.thing.internal.CommunicationManager.stateUpdated(CommunicationManager.java:475) ~[?:?]

	at org.eclipse.smarthome.core.thing.internal.ThingManagerImpl$1.stateUpdated(ThingManagerImpl.java:167) ~[?:?]

	at org.eclipse.smarthome.core.thing.binding.BaseThingHandler.updateState(BaseThingHandler.java:287) ~[?:?]

	at org.eclipse.smarthome.binding.mqtt.generic.internal.handler.AbstractMQTTThingHandler.updateChannelState(AbstractMQTTThingHandler.java:215) ~[?:?]

	at org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState.processMessage(ChannelState.java:177) ~[?:?]

	at org.eclipse.smarthome.io.transport.mqtt.internal.ClientCallback.lambda$3(ClientCallback.java:90) ~[259:org.eclipse.smarthome.io.transport.mqtt:0.10.0.oh240]

	at java.util.ArrayList.forEach(ArrayList.java:1257) ~[?:?]

	at org.eclipse.smarthome.io.transport.mqtt.internal.ClientCallback.messageArrived(ClientCallback.java:90) [259:org.eclipse.smarthome.io.transport.mqtt:0.10.0.oh240]

	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:499) [256:org.eclipse.paho.client.mqttv3:1.2.0]

	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:402) [256:org.eclipse.paho.client.mqttv3:1.2.0]

	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:206) [256:org.eclipse.paho.client.mqttv3:1.2.0]

	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:?]

	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

	at java.lang.Thread.run(Thread.java:748) [?:?]

mqtt message

{"battery":100,"voltage":3125,"linkquality":0,"smoke":false}

  1. ASK its a BUG?
    and wats a realy bug. If the thing file include the Bride Line
Bridge mqtt:systemBroker:embedded-mqtt-broker

its disconect the embedet Broker. Or if the line include a IP information, Broker.
its only function given a new Broker Name on every new save version.

I need a little on this one - it should be fairly simple, but I cannot figure out why it isnā€™t working.
The issue is I canā€™t see the temperature in my sitemap with the new MQTT 2.4 binding

This is my config :
Things

Bridge mqtt:broker:mosquitto "local mosquitto" [ host="localhost",secure=false ]
{
        Channels:
		Type number : MQTT_BoilerRoom_1_1  "Flow"  [ stateTopic="/ESP_Easy_BoilerRoom/OneWireBus1_1/Temperature" ]
}

Items

Number  Temp1  "Temperature"  {channel="mqtt:broker:mosquitto:MQTT_BoilerRoom_1_1"}

Sitemap

Text item=Temp1	label="Temp1 [%.2f Ā°C]"

In the openhab.log (and paperUI) I can see that the broker is online, and in the events.log I see events regarding receiving temperatures. I guess this indicates that the binding is working as expected, and the issue is related to my item/sitemap config, but I cannot figure out what Iā€™m missing ?

openhab.log 
2019-01-01 21:07:10.250 [me.event.ThingUpdatedEvent] - Thing 'mqtt:broker:mosquitto' has been updated.
2019-01-01 21:07:10.329 [hingStatusInfoChangedEvent] - 'mqtt:broker:mosquitto' changed from OFFLINE to ONLINE
2019-01-01 21:07:10.330 [me.event.ThingUpdatedEvent] - Thing 'mqtt:broker:mosquitto' has been updated.

events.log
2019-01-01 21:28:07.413 [vent.ChannelTriggeredEvent] - mqtt:broker:mosquitto:MQTT_BoilerRoom_1_1 triggered 27.87

Any ideas ?

/Lars

You did create a broker thing, after that you need to create a ā€œGeneric MQTT Thingā€.

Like:

Bridge mqtt:broker:myBroker [ host="MyIP", secure=false, username="myUser", password="myPassword" ]
{
  Thing topic sonoff_1_Thing "Light_1" @ "Sonoff" {  
    Channels:
        Type switch : PowerSwitch  [ stateTopic="stat/sonoff_1/POWER" , commandTopic="cmnd/sonoff_1/POWER", on="ON", off="OFF" ]
        Type string : Version [stateTopic="stat/sonoff_1/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
      } 
}

and an item like:

Switch Stern_1 "Stern1" ["Lighting"] { channel="mqtt:topic:myBroker:sonoff_1_Thing:PowerSwitch" }

2 Likes

Hi JĆ¼rgen

It works :partying_face: :+1:
I really thought I had tried all combinations, but apparently there was one, I hadnā€™t tried

Thank you very much
/Lars

Hi JĆ¼rgen

First of all thank you for your help, things are working now (thanks to you), but now I would really like to understand what Iā€™m doing :thinking:

On this page https://www.openhab.org/blog/2018-12-16-mqtt-arrives-in-the-modern-openhab-2-x-architecture.html the thing-syntax is described with a colon (and a mqtt: in the beginning) Thing mqtt:topic:mything and you have spaces between Thing topic sonoff_1_Thing - do you know if both are valid, or is it just a typo on the blog-page?

Your example has Light_1" @ ā€œSonoffā€, which the example on the doc page doesnā€™t have https://www.openhab.org/addons/bindings/mqtt.generic/ - what is the purpose of Light_1" @ ā€œSonoffā€ ?

And last but not not leastā€¦ the channel part of the item is a ā€œlittleā€ confusing - it looks like its a mix something from ā€œbridgeā€:ā€œthingā€:ā€œbridgeā€:ā€œthingā€:ā€œchannelā€ - i canā€™t find any documentation about channels in general. Do you know if its described somewhere, or can you explain it ?

I have tried to visualize it with this image

6 Likes