Page 7 of 17
Re: MQTT Client
Posted: Sun May 15, 2016 6:38 am
by krambriw
As you can see, there are more messages received by your Plugin (the <paho.mqtt... > lines) than Eg events triggered by it (<the MQTT./openHAB/in... lines.
Indeed, there are as many <paho.mqtt...> lines as messages published. And it also matches the count of messages received by other subscribers
CODE: SELECT ALL
19:57:02 MQTT./openHAB/in/AV_mRDC_Salon_media_album/state u"02"
19:57:02 <paho.mqtt.client.Client object at 0x0500D7B0> None 02
19:57:03 <paho.mqtt.client.Client object at 0x0500D7B0> None 03
19:57:04 MQTT./openHAB/in/AV_mRDC_Salon_media_album/state u"03"
19:57:04 <paho.mqtt.client.Client object at 0x0500D7B0> None 04
19:57:04 MQTT./openHAB/in/AV_mRDC_Salon_media_album/state u"04"
19:57:04 <paho.mqtt.client.Client object at 0x0500D7B0> None 04
19:57:04 <paho.mqtt.client.Client object at 0x0500D7B0> None 04
19:57:04 <paho.mqtt.client.Client object at 0x0500D7B0> None 04
19:57:05 <paho.mqtt.client.Client object at 0x0500D7B0> None 05
19:57:06 MQTT./openHAB/in/AV_mRDC_Salon_media_album/state u"05"
I think the above is correct since the code is written in such a way that it by default will block repeated events (I think in this case during 1 second). You can see that you received one event each for '02', '03', '04' and '05' which is what I expected. Maybe this is what is causing the problem for you.
Also worth mentioning is that the MQTT Client is not written to support any kind of message formats by default so it could be we would have to add some specific section for messages coming from openhab.
Could you add the following print statements / modify your code and see what results we get printed when you receive messages from openhab?
Code: Select all
def ProcessEvent(msg, bDelay, delay, res_key, res_base):
print bDelay, delay
print res_key
print res_base
Re: MQTT Client
Posted: Sun May 15, 2016 2:23 pm
by wawa79
krambriw wrote:
I think the above is correct since the code is written in such a way that it by default will block repeated events (I think in this case during 1 second). You can see that you received one event each for '02', '03', '04' and '05' which is what I expected. Maybe this is what is causing the problem for you.
For sure this kind of 'prevent auto-repeat' feature is causing my problem: my initial issue happened when triggering twice same MQTT message. In our current test script the '02', '03' are indeed the seconds of the time when message is sent so we clearly see event only occurs when seconds have changed.
Could there be an additional tick box to tell the plugin not to discard repeated messages or a configurable 'non-repeat time' where setting this parameter to 0 would disable this feature?
Because this is what I need as I have implemented a cancellation behaviour using zwave: when user pushes a switch, a zwave scene command is received by openHAB and forwarded to Eg as a MQTT message. The scene command activates a certain 'house mode' and user is notified by TTS. If he wants to cancel his action, he just needs to push the switch again. Currently, this means that the 2nd push will be discarded as it does not generate a 2nd identical event in Eg.
From my short experience with MQTT, message sending on a LAN is reliable even with a QoS set to 0 so this kind of 'prevent auto-repeat' does not sound necesary.
krambriw wrote:
Also worth mentioning is that the MQTT Client is not written to support any kind of message formats by default so it could be we would have to add some specific section for messages coming from openhab.
Personally I am using Python scripts which makes it easy to interpret the MQTT.* events but other Eg users may be interested in this. OpenHAB handles MQTT in 2 ways:
1) an event bus binding which basically translates all in/out messages from opnHAB bus to MQTT messages. This is configured in the global OpenHAB configuration file so the topic can be customized and the documentation suggests:
mqtt-eventbus:broker=m2m-eclipse
mqtt-eventbus:commandPublishTopic=/openHAB/out/${item}/command
mqtt-eventbus:stateSubscribeTopic=/openHAB/in/${item}/state
where item is the name of the item (=device) and the content of the message is the state/command received/sent
This is my setup as I only use openHAB for interfacing to zwave and its clean and fast Web UI: all the 'intelligence' of automation is in Eg.
2) per item binding: any item (=device) can be configured in a way it generates an MQTT message (command message) or is updates through a MQTT message (state message): so again the topic is fully configurable
krambriw wrote:
Could you add the following print statements / modify your code and see what results we get printed when you receive messages from openhab?
Here is the log of same test with additional output :
15:45:54 <paho.mqtt.client.Client object at 0x04756FB0> None 54
15:45:54 self.eventCollection[res_key]=
15:45:54 res_base= ['54']
15:45:54 bDelay= True delay= 5.0
15:45:54 res_key= /openHAB/in/AV_mRDC_Salon_media_album/state, 54
15:45:54 res_base= ['54']
15:45:54 MQTT./openHAB/in/AV_mRDC_Salon_media_album/state u"54"
15:45:57 <paho.mqtt.client.Client object at 0x04756FB0> None 57
15:45:57 self.eventCollection[res_key]=
15:45:57 res_base= ['57']
15:45:57 bDelay= True delay= 5.0
15:45:57 res_key= /openHAB/in/AV_mRDC_Salon_media_album/state, 57
15:45:57 res_base= ['57']
15:45:57 MQTT./openHAB/in/AV_mRDC_Salon_media_album/state u"57"
15:45:57 <paho.mqtt.client.Client object at 0x04756FB0> None 57
15:45:57 self.eventCollection[res_key]= ['57']
15:45:57 res_base= ['57']
15:45:57 bDelay= True delay= 5.0
15:45:57 res_key= /openHAB/in/AV_mRDC_Salon_media_album/state, 57
15:45:57 res_base= ['57']
Indeed I am happy we found the reason of that strange behaviour!
Now I have to investigate the connect/disconnect every 20 secs of your Paho based plugin on my home automation PC. But this should be software or hardware related as it did not happen on other computers where I tested your plugin on.
Re: MQTT Client
Posted: Sun May 15, 2016 3:12 pm
by krambriw
I think for now, it would be easier for me to just add support for openHAB in a special section. Could we agree that '/openHAB/' is a required part of the topics? If so, you could try the attached version where I have added code to handle this. With this you should get all events, even replicas.
From my short experience with MQTT, message sending on a LAN is reliable even with a QoS set to 0 so this kind of 'prevent auto-repeat' does not sound necesary.
I did see problems without it so I rather keep it as is
Re: MQTT Client
Posted: Mon May 16, 2016 2:14 pm
by wawa79
krambriw wrote:I think for now, it would be easier for me to just add support for openHAB in a special section. Could we agree that '/openHAB/' is a required part of the topics? If so, you could try the attached version where I have added code to handle this. With this you should get all events, even replicas.
From my short experience with MQTT, message sending on a LAN is reliable even with a QoS set to 0 so this kind of 'prevent auto-repeat' does not sound necesary.
I did see problems without it so I rather keep it as is
__init__.py
Hello Walter,
If other interfaces require preventing repeat, it is better to do the way you propose. '/openHAB/' is part of my topic and is suggested as default in openHAB conf file but it might be different.
It is working fine with the delay set to zero as you set ip for openHAB topics.
Now I really need to investigate why the Paho version is reconnecting every 10 secs on my home automation PC and not on my laptop

. They are both running Win10...
Thank you for your support!
Re: MQTT Client
Posted: Thu May 19, 2016 6:27 am
by crispy3417
Hello,
tried to install the plugin (extracted all to the plugins folder) but when adding it EG always crashes.
Am I doing something wrong ?
Best regards
Christopher
Re: MQTT Client
Posted: Thu May 19, 2016 10:43 am
by krambriw
Did you move the paho subdirectory to the place I mentioned?
http://eventghost.net/forum/viewtopic.p ... =75#p39278
Re: MQTT Client
Posted: Sun May 22, 2016 9:19 am
by crispy3417
Thanks for the solution. Now I┬┤m happy !

Thank you for the plugin.
Best regards
Christopher
Re: MQTT Client
Posted: Wed Jul 20, 2016 12:19 am
by thedude
Thanks for this great plugin!
Works smoothly, only thing I'm having trouble with is the ability to include the message payload in the event title and trigger macros accrodingly.
It shows up correctly with the message payload in the log when the message is sent (i.e. MQTT./vncstatus/ u"on"), but when I attempt to drag the message over from the log to a macro, it gets lost (i.e. MQTT./vncstatus/). When I attempt to edit the event title to include the message payload, it makes no difference and the macro is not triggered.
I know I can just make another topic to subscribe to send messages to it, but it would be nice to have the message payload on a single topic be able to trigger macros.
Is it not possible or am I not configuring something correctly?
Thanks for any insight
Re: MQTT Client
Posted: Thu Jul 21, 2016 6:07 am
by krambriw
The info that you want to use as macro trigger is as you say in the payload of the event. If you want to trigger various macros on events you need to create new events based on the payload content. How to do this has been described several times in this forum but I cannot give you a link right now
EDIT: here is an example of a similar case
viewtopic.php?f=9&t=982&p=40258&hilit=payload#p40170
Re: MQTT Client
Posted: Fri Jul 22, 2016 6:20 am
by thedude
krambriw wrote:The info that you want to use as macro trigger is as you say in the payload of the event. If you want to trigger various macros on events you need to create new events based on the payload content. How to do this has been described several times in this forum but I cannot give you a link right now
EDIT: here is an example of a similar case
viewtopic.php?f=9&t=982&p=40258&hilit=payload#p40170
Thanks very much for the reply. That works! Thought it was already a default feature, guess you need to extract it. Here is my attempt to improve upon that:
Code: Select all
topic = eg.event.string
str = eg.event.payload
eg.TriggerEvent(
str,
prefix = topic
)
del str
This way you can have a dynamic prefix and just make one macro to extract payload for all MQTT topics. Thanks again!
Re: MQTT Client
Posted: Sun Aug 14, 2016 9:17 am
by krambriw
New version released
Compatible with EventGhost 0.5.0
Re: MQTT Client
Posted: Sat Oct 08, 2016 5:35 am
by krambriw
New version released
Added support for Domoticz events via MQTT
Re: MQTT Client
Posted: Sat Oct 08, 2016 10:29 am
by WoLpH
krambriw wrote:New version released
Added support for Domoticz events via MQTT
Great work krambriw! Thanks for the help

Re: MQTT Client
Posted: Sat Oct 08, 2016 6:52 pm
by kalinkamaen
How does this work? I have never used MQTT. Do i need to install MQTT software to get Domoticz commands?
Re: MQTT Client
Posted: Sat Oct 08, 2016 7:00 pm
by WoLpH
I've added a short explanation to the domoticz topic earlier today:
viewtopic.php?f=9&t=9105
Let me know if you need any help
