Page 14 of 16

Re: MQTT Client

Posted: Tue Apr 10, 2018 10:32 am
by alonmalka
Yes you are right.
Any suggestions?

Re: MQTT Client

Posted: Tue Apr 10, 2018 10:55 am
by alonmalka
Another thing, when I run netstat like you told me to, I don't see the MQTT port in use by the Pi though the MQTT messages does go through without a problem except for the delay I am talking about.

Re: MQTT Client

Posted: Tue Apr 10, 2018 2:59 pm
by Snowbird
that's not possible, if your broker is installed on your RPi it means it's listening on some port, I gave you the default ones earlier but maybe you have changed them ? what port is set in EG ? Are you sure your broker is installed on your RPi ? it looks like you are using an external broker and that your RPi and EG have subscribed to the same topic and communicate with each other through this external broker. What broker is set in your EG ?

Re: MQTT Client

Posted: Wed Apr 11, 2018 8:59 pm
by alonmalka
I ran netstat on Raspberry PI and it showed me the port that it is listening to 1883 (default). So I guess this means that the server side is local and os running on the Pi.
EG also seem ok since I run the same settings: Pi's local IP address, default port, username and password, topic and , message.

So why does it take more then 2 seconds? This is driving me crazy. When I use the MQTT.FX as I sayed before, the command is recived almost instantly, although you must be connected to the the server and you can't just send a message and hang up.

Maybe that is because it's faster? because it is always connected?

Re: MQTT Client

Posted: Thu Apr 12, 2018 12:46 am
by kgschlosser
raspberry pi's are not exactly the fastest thing in the world.

This is what I am understanding

you have EG set up on a PC and you have HomeAssistant set up on a Raspberry Pi.

Now. Raspberry Pi's are pretty handicapped in the resources department. And opening and closing ports does take some effort. HomeAssistant does take some time to do things if it is not a core process. it kind of gets placed on the back burner until i gets to it. so the opening and closing of a port is really going to take more time if you have HomeAssistant doing it. if you have an always open port connection the data being sent through it is going to be processed by HomeAssistant much faster.

Now you can test this and see if the issue lies with EG and the plugin or on the RPi side of things by setting up 2 instances of EG on 2 different PCs and have them send the message back and forth between them. and see if it takes 2 seconds. if it does not then the problem lies on the side of the RPi.

Re: MQTT Client

Posted: Sat Apr 14, 2018 10:09 am
by wawa79
kgschlosser wrote:
Sun Apr 01, 2018 1:18 am
I have updated the plugin with exception catching and a little better unicode decoding. I have done this for all places where any decoding was done.

The updated version is attached.
Hi, great ! I will give it a try. Thank you

Re: MQTT Client

Posted: Wed Jul 11, 2018 8:53 am
by Terr
need help with understanding EventGhost
i installed this plugin
started new mqtt subscription with topic "eventghost"
now i send from home assistant in topic "eventghost" message "volume-mute"
i saw log of EventGhost - MQTT.eventghost u"volume-mute"
and now i dont understand how to create action in EventGhost when it receive message "volume-mute" ?

Re: MQTT Client

Posted: Wed Jul 11, 2018 9:20 am
by Terr
if i drag and drop message from log - MQTT.eventghost u"volume-mute" - to default folder Volume Control -> Mute Volume
it create event item - MQTT.eventghost - without message
such it work with any message in topic eventghost with same action
i need other
i want send messages with different action
MQTT.eventghost u"volume-mute"
MQTT.eventghost u"volume--"
MQTT.eventghost u"volume-+"

Re: MQTT Client

Posted: Wed Jul 11, 2018 7:03 pm
by Snowbird
hi, this is "normal" each event can also carry a payload, and you need to work with the payload to achieve what you need.

MQTT.eventghost u"volume-mute"
--> the blue part is the event
--> the red part is the payload

so you need to make a small script to identify each payload and assign a task to it, for example :

Code: Select all

if eg.event.payload == 'volume-mute':
    print "Mute The Volume"
elif eg.event.payload == 'volume--':
    print "Reduce The Volume"
elif eg.event.payload == 'volume-+':
    print "Raise The Volume"
This is a dummy example, it won't do anything except displaying the corresponding text for each payload received. I think you need to read a bit more regarding the basics of Eventghost.

Re: MQTT Client

Posted: Wed Jul 11, 2018 10:06 pm
by kgschlosser
The MQTT plugin is a whopper of a plugin to learn EventGhost with I give you a lot of credit for using it as your first.

Because of the complex nature of MQTT the author decided to put the message information into a payload. We can greatly improve upon this if you wanted. What can be done is you would create a Macro that has a python script action in it.

In that python script paste the following code

Code: Select all

payload = eg.event.payload

if payload and isinstance(payload, (str, unicode)) and 'suffix' in payload:
	payload = payload.split('suffix=')
	suffix = payload[1].strip()
	if 'prefix' in payload[0]:
	    payload = payload[0].split('prefix=')
	    prefix = payload[1].strip()
	elif 'prefix' in suffix:
	    suffix = suffix.split('prefix=')
	    prefix = suffix[1].strip()
	    suffix = suffix[0].strip()
	    prefix = eg.event.string
	if 'payload'  in payload[0]:
	    payload = payload[0].split('payload=')
	    payload = payload[1].strip()
	elif 'payload' in prefix:
	    prefix = prefix.split('payload=')
	    payload = prefix[1].strip()
	    prefix = prefix[0].strip()
	elif 'payload' in suffix:
	    suffix = suffix.split('payload=')
	    payload = suffix[1].strip()
	    suffix = suffix[0].strip()
	    payload = None
	eg.TriggerEvent(prefix=prefix, suffix=suffix, payload=payload)

then drag and drop one of your events. double click on the event in your tree and change it to the following.

Code: Select all

so what we have done is we created a universal MQTT payload parser. you ill need to change the message being sent. now you can create custom events using MQTT here is an example of a message


this is going to cause an event in eventghost that will read


Now this event you can simply drag and drop without the need to create multiple scripts to check the payload data.
a message can also be formatted

prefix=TV suffix=Mute

this will cause an event to be generates that reads


you can also add an optional payload if you wanted. just add on


to the message.
it does not matter what order you put the 3 options. But in order for this to work it has to have the suffix= option in the message.

I have not run the code so there could be a typo in there. if you have any questions or errors please let me know.


That's a good tutorial. very easy to understand

Re: MQTT Client

Posted: Thu Jul 12, 2018 7:55 am
by Terr
thx guys
"It's Alive!!!"

Re: MQTT Client

Posted: Thu Jul 12, 2018 8:55 am
by Terr
ok next level )
now i'm looking for feedback for home assistant
what message can receive volume level to mqtt topic ?
something like {eg.globals.volumeLevel} or {System.Volume} dont work
and how to do trigger for changing volume and brightness screen ? (i control it with program volume2)

for example,
i change volume or brightness local on pc or with sending message on mqtt
and trigger sees that the volume or brightness has changed and send message something as Volume.55% or brightness.55%

Re: MQTT Client

Posted: Thu Jul 12, 2018 11:00 am
by kgschlosser
I am not sure if the MQTT library has been designed to parse variables in it's action fields.

if it is you have the right idea.. I am not going to hand you this one... But we just went over the event/payload structure for when you get an event from MQTT

so when you get a System.Volume event it uses the exact same variable.

OK so screw it' I'll give it to ya..


the reason for wrapping the payload in str() is to make sure it gets converted if it is not the correct data type.

The trick to knowing if the data at the end of the event is a payload or if it is part of the event it's self is it will almost always have an identifying mark.


except for numbers if a number is a payload it will always have a space between it and the event. I have never seen a plugin developer put the space there and have it part of the event name.

if you want to add a means to make sure there is a payload value set you need to add a python command action at the top of the macro just under the event that contains this line

Code: Select all

if eg.event.payload is None: eg.StopMacro();
Simple mechanism to make sure you are not sending any MQTT messages that have "None" as the topic.

Re: MQTT Client

Posted: Fri Jul 13, 2018 3:06 pm
by Terr
all done except brightness
dont know ho to change it with eventghost

found ... rightness/
but it doesnt work with powershell

and something with python ... -python3-x
wmi.WMI(namespace='wmi').WmiMonitorBrightnessMethods()[0].WmiSetBrightness(brightness, 0)

dont know how to correct use it in eventghost plugin's window
can u check work it in windows or not ?

Re: MQTT Client

Posted: Fri Jul 13, 2018 4:58 pm
by kgschlosser
hmmm never had someone ask to change the brightness on the screen. going to have to do some research on this one.