Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Trigger events from Pi

If you have a question or need help, this is the place to be.
Post Reply
Phil
Experienced User
Posts: 111
Joined: Tue Apr 15, 2014 10:42 am
Location: Merseyside, UK

Trigger events from Pi

Post by Phil »

Hi
Could I please have some suggestions as to the best way to trigger events in eventghost from a python script running on a raspberry pi?
I've looked at pushbullet and wget to trigger one, but both seem to have undesirable overheads which will delay the process.
I'd want to send both a trigger and probably some payload with it.

The reason is that I have my pi connected to my doorbell to provide me with a photo each time the doorbell is pushed (both to my mobile and to appear on xbmc), the pushbullet implementations on python seem a little limited at the moment so i'd like to use EG to process the alert instead.

I already have the z-wave plugin running which allows communication between the two devices but need to know how to add this on.

thanks

Phil
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Trigger events from Pi

Post by krambriw »

Means you already have the Pi well prepared for communication ;)

1) In your python script in the Pi, add some code so that it publishes the desired data on the MQTT broker to a new topic

2) Add the MQTT Client plugin in EG and subscribe to the same topic
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Trigger events from Pi

Post by Sem;colon »

...Or use the webserver plugin of eventghost and do a simple get/post from your script on the Pi.
If you like my work, Image me a drink :wink:
Phil
Experienced User
Posts: 111
Joined: Tue Apr 15, 2014 10:42 am
Location: Merseyside, UK

Re: Trigger events from Pi

Post by Phil »

I guess the MQTT is a better solution, but having read lots in the past hour looks like a whole new thing to learn.
Is the speed for the webserver plugin to react good? Http has quite a large overhead I believe?
I have that plugin in use already so maybe the lazy me will just use that.
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Trigger events from Pi

Post by Sem;colon »

I guess the MQTT is a better solution
I agree, but I have to admit that I also never tried it..

HTTP is OK, I use it for several things and never had the feeling that it's slow.
If you like my work, Image me a drink :wink:
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Trigger events from Pi

Post by krambriw »

I assume both ways (and many others will work) so the question is more of the type where you feel more convinient.

As to the webserver approach, I think too it will work (I know it will) but I give you an example where I improved the performance by using an alternative solution;

I have have some web gui panels where I can control lights and read temperature sensor values etc. Until recently I triggered events & macros in EG from the web gui using http requests. This was working fine, no problems. But since I had websockets going the other direction, I changed so now I am also triggering events & macros by sending websocket messages from the gui. Here I could notice a performance gain, a faster response to my commands, I believe one reason is reduced overhead. At the end of day, it is not mission critical, just a turbo feature...

Using MQTT, which is a lightweight protocol, is dead simple since you already have the broker running. You can try to run this simple python script in your Pi from /home/pi in a putty session while having a MQTT Client in EG subscribing to the same topic (/test).

Code: Select all

import mosquitto

mqtt_host = '127.0.0.1'
port = 1883
topic = '/test'
client = mosquitto.Mosquitto("MyTest")
client.connect(mqtt_host, port)

msg = "Hello, message from your Pi"

result, mid = client.publish(topic, msg, 0)
client.disconnect()
del client
exit()
Post Reply