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
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.
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
-
krambriw
- Plugin Developer
- Posts: 2570
- Joined: Sat Jun 30, 2007 2:51 pm
- Location: Stockholm, Sweden
- Contact:
Re: Trigger events from Pi
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
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
My released plugins
https://drive.google.com/drive/folders/ ... y01eVBKeHM
https://drive.google.com/drive/folders/ ... y01eVBKeHM
Re: Trigger events from Pi
...Or use the webserver plugin of eventghost and do a simple get/post from your script on the Pi.
Re: Trigger events from Pi
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.
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.
Re: Trigger events from Pi
I agree, but I have to admit that I also never tried it..I guess the MQTT is a better solution
HTTP is OK, I use it for several things and never had the feeling that it's slow.
-
krambriw
- Plugin Developer
- Posts: 2570
- Joined: Sat Jun 30, 2007 2:51 pm
- Location: Stockholm, Sweden
- Contact:
Re: Trigger events from Pi
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).
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()
My released plugins
https://drive.google.com/drive/folders/ ... y01eVBKeHM
https://drive.google.com/drive/folders/ ... y01eVBKeHM
