[CLOSED] MQTT binding version 2.4 (Pre-release !)

Bindings are not allowed to access the event bus. The event bus is really just for the core of the framework and everything else should use what is available an abstraction layer above: Items, Things, Channels. So this does not fall into the responsibility of this binding.

What you probably want is an “io” addon like the hue-emulation, homekit, openhab-cloud that can be configured to publish items to mqtt. But in contrast to the mentioned io add-ons mqtt topics are not standardized, the values aren’t as well. That’s why nobody will write such an add-on, I guess.

For the moment, you can use a rule to accomplish the same though.

The contact channel only accepts OPEN or CLOSED

That’s the right way to do it.

Possibly a bug
Use a MAP transform instead
@David_Graeff, see above

A bug. Just to be sure and to have it on my to-do list: please open a bug report and describe your setup and the wrong behaviour.

Also reverting back to the MQTT1 binding and action for now.

Thanks for the explanation, this makes sense.
But it should be possible to design the addon configurable just as the mqqt-eventbus is (i.e. structure of topics with the option of variables), right?

Of course. But at least for me the question remains how to publish state updates. I only managed to publish commands an item has received. Or did I miss a config option there?

I have added that to the docu. The PR is not yet accepted though but at the same time I don’t want to repeat myself :smiley:
But you can react on item changes as well not only commands, of course. Have a look at the doc for rules again.

Cheers,
David

I think I found a bug with the auto discovery (Home Assistant type) and the new binding.
I just updated a few of my Tasmota devices to the latest version (Sonoff-Tasmota 6.4.1) - with that version I was able to use the new HASS auto discovery option (SetOption19) which only seems to work sometimes in OH.

My device is sending the following discovery message:

13:03:41 MQT: homeassistant/light/45D1FA_LI_1/config =  (retained)
13:03:41 MQT: homeassistant/switch/45D1FA_RL_1/config = {"name":"Sonoff_Garage","cmd_t":"~cmnd/POWER","stat_t":"~tele/STATE","val_tpl":"{{value_json.POWER}}","pl_off":"OFF","pl_on":"ON","avty_t":"~tele/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"45D1FA_RL_1","device":{"identifiers":["45D1FA"],"name":"Sonoff_Garage","model":"1 Channel","sw_version":"6.4.1(sonoff)","manufacturer":"Tasmota"}, "~":"sonoff/sonoff_garage/"} (retained)
13:03:41 MQT: homeassistant/light/45D1FA_LI_2/config =  (retained)
13:03:41 MQT: homeassistant/switch/45D1FA_RL_2/config =  (retained)
13:03:41 MQT: homeassistant/light/45D1FA_LI_3/config =  (retained)
13:03:41 MQT: homeassistant/switch/45D1FA_RL_3/config =  (retained)
13:03:41 MQT: homeassistant/light/45D1FA_LI_4/config =  (retained)
13:03:41 MQT: homeassistant/switch/45D1FA_RL_4/config =  (retained)
13:03:41 MQT: homeassistant/light/45D1FA_LI_5/config =  (retained)
13:03:41 MQT: homeassistant/switch/45D1FA_RL_5/config =  (retained)
13:03:41 MQT: homeassistant/light/45D1FA_LI_6/config =  (retained)
13:03:41 MQT: homeassistant/switch/45D1FA_RL_6/config =  (retained)
13:03:41 MQT: homeassistant/light/45D1FA_LI_7/config =  (retained)
13:03:41 MQT: homeassistant/switch/45D1FA_RL_7/config =  (retained)
13:03:41 MQT: homeassistant/light/45D1FA_LI_8/config =  (retained)
13:03:41 MQT: homeassistant/switch/45D1FA_RL_8/config =  (retained)

The device is discovered in OH but non-functional since the HomeAssistant config ID is set to “config” (should be 45D1FA_RL_1 in this case if I am not mistaken)

Can anyone confirm that behavior?

2 Likes

This is a bug. Please report it on Github for tracking. Thanks.

Thanks @David_Graeff, done

After a reboot of OH the device is offline again - but with a different message, i can’t figure out what the problem is here. I was able to delete the thing, re-discover and it worked again. But after a reboot/restart of OH same issue again:

2018-12-27 15:49:33.339 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.eclipse.smarthome.binding.mqtt.generic.internal.handler.HomeAssistantThingHandler@2a3c0c': Channel needs a group ID with the pattern component_node!

java.lang.IllegalArgumentException: Channel needs a group ID with the pattern component_node!
	at org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homeassistant.HaID.<init>(HaID.java:87) ~[?:?]
	at org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homeassistant.CFactory.createComponent(CFactory.java:87) ~[?:?]
	at org.eclipse.smarthome.binding.mqtt.generic.internal.handler.HomeAssistantThingHandler.initialize(HomeAssistantThingHandler.java:120) ~[?:?]
	at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [102:org.eclipse.smarthome.core:0.11.0.201812232227]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [102:org.eclipse.smarthome.core:0.11.0.201812232227]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	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) [?:?]

==> /var/log/openhab2/events.log <==
2018-12-27 15:49:33.357 [hingStatusInfoChangedEvent] - 'mqtt:homeassistant:embedded-mqtt-broker:config' changed from INITIALIZING to UNINITIALIZED (HANDLER_INITIALIZING_ERROR): Channel needs a group ID with the pattern component_node!

==> /var/log/openhab2/openhab.log <==
2018-12-27 15:49:33.355 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while initializing handler of thing 'mqtt:homeassistant:embedded-mqtt-broker:config': Channel needs a group ID with the pattern component_node!

java.lang.IllegalArgumentException: Channel needs a group ID with the pattern component_node!
	at org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homeassistant.HaID.<init>(HaID.java:87) ~[?:?]
	at org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homeassistant.CFactory.createComponent(CFactory.java:87) ~[?:?]
	at org.eclipse.smarthome.binding.mqtt.generic.internal.handler.HomeAssistantThingHandler.initialize(HomeAssistantThingHandler.java:120) ~[?:?]
	at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [102:org.eclipse.smarthome.core:0.11.0.201812232227]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [102:org.eclipse.smarthome.core:0.11.0.201812232227]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	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) [?:?]

Another bug?

The same bug. I just need your /config response from tasmota to create a test case to make this work. I do not have a home-assistant mqtt client here for a real test.

Ok, not sure what response you refer to. As far as I can see there is no response. Just the same message (as posted earlier) again. Then the device updates:

20:50:27 MQT: homeassistant/switch/45D1FA_RL_1/config = {"name":"Sonoff_Garage","cmd_t":"~cmnd/POWER","stat_t":"~tele/STATE","val_tpl":"{{value_json.POWER}}","pl_off":"OFF","pl_on":"ON","avty_t":"~tele/LWT","pl_avail":"Online","pl_not_avail":"Offline","uniq_id":"45D1FA_RL_1","device":{"identifiers":["45D1FA"],"name":"Sonoff_Garage","model":"1 Channel","sw_version":"6.4.1(sonoff)","manufacturer":"Tasmota"}, "~":"sonoff/sonoff_garage/"} (retained)
2018-12-27 20:50:28.316 [hingStatusInfoChangedEvent] - 'mqtt:homeassistant:embedded-mqtt-broker:config' changed from OFFLINE (GONE): No response from the device yet to ONLINE

I also noticed another issue: when the HASS autodiscover feature is turned off (SetOption19 0) an empty identification is sent, which (as per the Tasmota & HASS documentation) should remove the device.

OH only produces an error message.
Message sent by Tasmota:

20:56:21 CMD: setoption19 0
20:56:21 MQT: homeassistant/light/45D1FA_LI_1/config =  (retained)
20:56:21 MQT: homeassistant/switch/45D1FA_RL_1/config =  (retained)
20:56:21 MQT: homeassistant/light/45D1FA_LI_2/config =  (retained)
20:56:21 MQT: homeassistant/switch/45D1FA_RL_2/config =  (retained)
20:56:21 MQT: homeassistant/light/45D1FA_LI_3/config =  (retained)
20:56:21 MQT: homeassistant/switch/45D1FA_RL_3/config =  (retained)
20:56:21 MQT: homeassistant/light/45D1FA_LI_4/config =  (retained)
20:56:21 MQT: homeassistant/switch/45D1FA_RL_4/config =  (retained)
20:56:21 MQT: homeassistant/light/45D1FA_LI_5/config =  (retained)
20:56:21 MQT: homeassistant/switch/45D1FA_RL_5/config =  (retained)
20:56:21 MQT: homeassistant/light/45D1FA_LI_6/config =  (retained)
20:56:21 MQT: homeassistant/switch/45D1FA_RL_6/config =  (retained)
20:56:21 MQT: homeassistant/light/45D1FA_LI_7/config =  (retained)
20:56:21 MQT: homeassistant/switch/45D1FA_RL_7/config =  (retained)
20:56:21 MQT: homeassistant/light/45D1FA_LI_8/config =  (retained)
20:56:21 MQT: homeassistant/switch/45D1FA_RL_8/config =  (retained)
20:56:21 MQT: sonoff/sonoff_garage/stat/RESULT = {"SetOption19":"OFF"}

“Response” in OH:

2018-12-27 20:46:35.671 [ERROR] [ansport.mqtt.internal.ClientCallback] - MQTT message received. MqttMessageSubscriber#processMessage() implementation failure
java.lang.NullPointerException: null
	at org.eclipse.smarthome.binding.mqtt.generic.internal.discovery.HomeAssistantDiscovery.receivedMessage(HomeAssistantDiscovery.java:168) ~[?:?]
	at org.eclipse.smarthome.binding.mqtt.discovery.TopicSubscribe.processMessage(TopicSubscribe.java:52) ~[?:?]
	at org.eclipse.smarthome.io.transport.mqtt.internal.ClientCallback.lambda$3(ClientCallback.java:90) ~[223:org.eclipse.smarthome.io.transport.mqtt:0.11.0.201812232227]
	at java.util.ArrayList.forEach(ArrayList.java:1257) ~[?:?]
	at org.eclipse.smarthome.io.transport.mqtt.internal.ClientCallback.messageArrived(ClientCallback.java:90) [223:org.eclipse.smarthome.io.transport.mqtt:0.11.0.201812232227]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.deliverMessage(CommsCallback.java:499) [214:org.eclipse.paho.client.mqttv3:1.2.0]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.handleMessage(CommsCallback.java:402) [214:org.eclipse.paho.client.mqttv3:1.2.0]
	at org.eclipse.paho.client.mqttv3.internal.CommsCallback.run(CommsCallback.java:206) [214: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) [?:?]

Update about this issue:
This only happens when receiving the string message from my device.
When I publish the same message with MQTTspy, all functions normally.
I also investigated the payload with MQTTspy, but I can’t find any difference.

Found the issue: It seems that my device is sending an illegal character within it's payload. This character isn't visible in MQTTspy neither in the log output of OpenHAB. I discovered this while saving the message as a binary file from MQTTspy. Now the only thing is to figure out why my device is sending this character along.

Could you please add this to your bug report. I haven’t considered the case that /config is null.

I can improve the log message, by adding the character count to the message. That might help to see at first glance if non-printable characters are involved. I bet on a new line or tab character.

Could you please open a bug report to ask for improved logging? I will forget this issue otherwise.

Hello, I managed to convert all my switches to the new MQTT 2.4 version.
But I’ve been struggling with the JSONPATH conversion for a week now and could’nt get things running with the new version.
in v1 my item looked like this :

Number SolarSV	 "Volt [%.0f V]"            <energy>
	{ mqtt="	<[mqttimo:tele/Solaranlage/SENSOR:state:JSONPATH($.ENERGY.Voltage)],
				<[mqttimo:stat/Solaranlage/STATUS8:state:JSONPATH($.StatusSNS.ENERGY.Voltage)]" }

EDIT: I asked for help with the JSONPATH transformation, but finally found the solution for my Sonoff POW myself:
In the channel configuration state has to be:
stat/Solaranlage/STATUS8
Incoming value transformation is:
JSONPATH:$.ENERGY.Voltage

and my item looks like this:

Number Voltage "SVoltage [%.0f V]"  {channel="mqtt:topic:IDVoltage:CIDVoltage"}

EDIT again:
This doesnt work. Item value is only updated once after ceration. Then the values stay the same.
No values after reboot.

You need two channels linked to the same item.

Hopefully the tasmota developer will get their shit together and fix this ridiculous topic structure. There are so many people struggling with this. It fills pages, literally.
(/Rant)

1 Like

Hi,

I really like the new binding but struggle to use it for the Owntracks configuration I had set up with the 1.x binding.
I know there is the GPSTracker binding which could help, but I want to stick with MQTT for this.
The old item configuration I had was:

Switch  PresenceM_PhoneMqttHome "M @ Home" (gLOG)          { mqttitude="mosquitto:owntracks/Matthias/iPhone/event:Home" }

What I understood so far is, that I can transform the incoming value from MQTT, which looks like this:

‘{“t”:“c”,“tst”:1546182339,“acc”:65,"_type":“transition”,“event”:“leave”,“lon”:XXXXXX,“lat”:YYYYY,“wtst”:1487837532,“tid”:“AA”,“desc”:“BB”}’

with JSONPATH to get out the different values. But the problem is, that I need three values to be checked:

  • event
  • tid
  • desc

Only if these three match the target pattern, the switch should turn ON.
Is this solvable with JSONPATH?

Thanks
Matthias

No, you would use a script transformation instead. Afaik Jsonpath can retrieve multiple values, but you would need to map those three concatenated extracted values to On/Off and that is not possible.

Hi to all, this is my first post.
I’m not familiar with OpenHAB, but as a developer of a mqtt bridge of another system, I got questions from my users, how to get all OpenHAB data bridged to the MQTT broker.
I don’t know exactly the OH wording, but for example, there are a bunch of non-mqtt temperature sensors configured in OpenHAB, is there an example how to configure a generic OH2MQTT bridge? Would this be worth to add an example with the new-rule-engine to the wiki?

I’ve found the MQTT 1 event bus binding, but the Wiki says, “don’t use that”. Would be nice to have a (link to a) simple generic example for the new binding.

Thanks, Christian