MQTT Client

Questions and comments specific to a particular plugin should go here.

Re: MQTT Client

Postby krambriw » Sun May 15, 2016 6:38 am

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 :wink:
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

My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby wawa79 » Sun May 15, 2016 2:23 pm

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.
wawa79
 
Posts: 18
Joined: Fri Nov 02, 2012 11:01 pm

Re: MQTT Client

Postby krambriw » Sun May 15, 2016 3:12 pm

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
(32.49 KiB) Downloaded 71 times
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby wawa79 » Mon May 16, 2016 2:14 pm

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 :evil: . They are both running Win10...

Thank you for your support!
wawa79
 
Posts: 18
Joined: Fri Nov 02, 2012 11:01 pm

Re: MQTT Client

Postby crispy3417 » Thu May 19, 2016 6:27 am

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
crispy3417
 
Posts: 2
Joined: Thu May 19, 2016 6:18 am

Re: MQTT Client

Postby krambriw » Thu May 19, 2016 10:43 am

Did you move the paho subdirectory to the place I mentioned?

http://eventghost.net/forum/viewtopic.php?f=9&t=5728&start=75#p39278
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby crispy3417 » Sun May 22, 2016 9:19 am

Thanks for the solution. Now I´m happy ! ;-)
Thank you for the plugin.
Best regards
Christopher
crispy3417
 
Posts: 2
Joined: Thu May 19, 2016 6:18 am

Re: MQTT Client

Postby thedude » Wed Jul 20, 2016 12:19 am

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
thedude
 
Posts: 13
Joined: Sun Apr 17, 2016 6:41 am

Re: MQTT Client

Postby krambriw » Thu Jul 21, 2016 6:07 am

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

http://www.eventghost.net/forum/viewtopic.php?f=9&t=982&p=40258&hilit=payload#p40170
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby thedude » Fri Jul 22, 2016 6:20 am

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

http://www.eventghost.net/forum/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!
thedude
 
Posts: 13
Joined: Sun Apr 17, 2016 6:41 am

Re: MQTT Client

Postby krambriw » Sun Aug 14, 2016 9:17 am

New version released

Compatible with EventGhost 0.5.0
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby krambriw » Sat Oct 08, 2016 5:35 am

New version released

Added support for Domoticz events via MQTT
My latest plugins
http://plugins.krambriw.net/index.html

Two men in front of a huge excavator...
- that beast steels work from 100 men with shovels
- well, a 1000 men could do the same using teaspoons
krambriw
Plugin Developer
 
Posts: 2559
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden

Re: MQTT Client

Postby WoLpH » Sat Oct 08, 2016 10:29 am

krambriw wrote:New version released

Added support for Domoticz events via MQTT

Great work krambriw! Thanks for the help :)
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)
WoLpH
Experienced User
 
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

Re: MQTT Client

Postby kalinkamaen » Sat Oct 08, 2016 6:52 pm

How does this work? I have never used MQTT. Do i need to install MQTT software to get Domoticz commands?
kalinkamaen
Experienced User
 
Posts: 132
Joined: Wed Dec 26, 2012 9:23 am

Re: MQTT Client

Postby WoLpH » Sat Oct 08, 2016 7:00 pm

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 :)
Author of the book Mastering Python. Got Python questions? Perhaps I can help :)
WoLpH
Experienced User
 
Posts: 96
Joined: Mon Dec 10, 2012 3:57 am

PreviousNext

Return to Plugin Support

Who is online

Users browsing this forum: No registered users and 4 guests