MQTT Client

Questions and comments specific to a particular plugin should go here.
alonmalka
Posts: 27
Joined: Wed Dec 04, 2013 10:07 am

Re: MQTT Client

Post by alonmalka » Tue Apr 10, 2018 10:32 am

Yes you are right.
Any suggestions?

alonmalka
Posts: 27
Joined: Wed Dec 04, 2013 10:07 am

Re: MQTT Client

Post by alonmalka » Tue Apr 10, 2018 10:55 am

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.

Snowbird
Experienced User
Posts: 349
Joined: Fri Jul 03, 2009 10:04 am

Re: MQTT Client

Post by Snowbird » Tue Apr 10, 2018 2:59 pm

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 ?

alonmalka
Posts: 27
Joined: Wed Dec 04, 2013 10:07 am

Re: MQTT Client

Post by alonmalka » Wed Apr 11, 2018 8:59 pm

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?

User avatar
kgschlosser
Site Admin
Posts: 4289
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MQTT Client

Post by kgschlosser » Thu Apr 12, 2018 12:46 am

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.
If you like the work I have been doing then feel free to Image

wawa79
Posts: 25
Joined: Fri Nov 02, 2012 11:01 pm

Re: MQTT Client

Post by wawa79 » Sat Apr 14, 2018 10:09 am

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

Terr
Posts: 14
Joined: Wed Jul 11, 2018 8:42 am

Re: MQTT Client

Post by Terr » Wed Jul 11, 2018 8:53 am

hi
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" ?

Terr
Posts: 14
Joined: Wed Jul 11, 2018 8:42 am

Re: MQTT Client

Post by Terr » Wed Jul 11, 2018 9:20 am

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-+"

Snowbird
Experienced User
Posts: 349
Joined: Fri Jul 03, 2009 10:04 am

Re: MQTT Client

Post by Snowbird » Wed Jul 11, 2018 7:03 pm

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.
Last edited by Snowbird on Thu Jul 12, 2018 11:32 am, edited 1 time in total.

User avatar
kgschlosser
Site Admin
Posts: 4289
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MQTT Client

Post by kgschlosser » Wed Jul 11, 2018 10:06 pm

@Terr
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()
	else:
	    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()
	else:
	    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

MQTT.*
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

suffix=volume-mute

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

MQTT.eventghost.volume-mute

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

TV.Mute

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

payload=payloaddata

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.


@Snowbird

That's a good tutorial. very easy to understand
If you like the work I have been doing then feel free to Image

Terr
Posts: 14
Joined: Wed Jul 11, 2018 8:42 am

Re: MQTT Client

Post by Terr » Thu Jul 12, 2018 7:55 am

thx guys
"It's Alive!!!"
:)

Terr
Posts: 14
Joined: Wed Jul 11, 2018 8:42 am

Re: MQTT Client

Post by Terr » Thu Jul 12, 2018 8:55 am

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%

User avatar
kgschlosser
Site Admin
Posts: 4289
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MQTT Client

Post by kgschlosser » Thu Jul 12, 2018 11:00 am

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..

{str(eg.event.payload)}

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.

u'
"
[
{
<

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.
If you like the work I have been doing then feel free to Image

Terr
Posts: 14
Joined: Wed Jul 11, 2018 8:42 am

Re: MQTT Client

Post by Terr » Fri Jul 13, 2018 3:06 pm

all done except brightness
dont know ho to change it with eventghost

found
https://blogs.technet.microsoft.com/hey ... rightness/
but it doesnt work with powershell

and something with python
https://stackoverflow.com/questions/365 ... -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 ?

User avatar
kgschlosser
Site Admin
Posts: 4289
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MQTT Client

Post by kgschlosser » Fri Jul 13, 2018 4:58 pm

hmmm never had someone ask to change the brightness on the screen. going to have to do some research on this one.
If you like the work I have been doing then feel free to Image

Post Reply