Trigger when a specifc pushbullet is received (or contains a specifc word).

If you have a question or need help, this is the place to be.
Post Reply
TrentLane
Posts: 4
Joined: Wed May 20, 2009 7:38 pm

Trigger when a specifc pushbullet is received (or contains a specifc word).

Post by TrentLane » Tue Mar 06, 2018 8:11 pm

I'm using the pushbullet plugin and can get it to work when a specific person messages my computer for it to then action something (works fine).

What I want to do is action different things depending on the contents of the message.

The current event is: PushBullet.Note.HomeAssistant

This is an example of the full event: PushBullet.Note.HomeAssistant [u'DOOR1', None, u'XXXXXXXXXXXXXXXXXXXXXX', u'Home Assistant', '2018-02-27 21:25:15']

DOOR1 is the message I want to trigger on my PC.

I'm not too sure what the "None" is and I've changed the 3rd part as I assume that's my API key.

I'm trying to figure out how to just trigger based on user and key word.

I've tried:

PushBullet.Note.HomeAssistant [u'DOOR1']

But I'm assuming it's not that easy as that was unsuccessful.

User avatar
yokel22
Experienced User
Posts: 265
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: Trigger when a specifc pushbullet is received (or contains a specifc word).

Post by yokel22 » Tue Mar 06, 2018 9:56 pm

You need to pull the message from the payload. I don't use pushbullet, so I'm not totally sure here but I'm guessing the xXxX variable is some sort of deviceID. You'd use that to determine which device sent the command. Parse out the payload with a python script/statement like so.

Code: Select all

message = eg.event.payload[0]
pushId = eg.event.payload[2]
sender = eg.event.payload[3]
eg.TriggerEvent(prefix='pushbullet', suffix=message)
print 'Message came from' + sender
If you want to evaluate the message or sender, you can do it like this.

Code: Select all

if eg.event.payload[0] == "DOOR1":
    #condition met execute code
    eg.TriggerEvent(prefix=eg.event.payload[3], suffix=eg.event.payload[0])

Code: Select all

if eg.event.payload[3] == "Home Assistant":
    #condition met execute code
    eg.TriggerEvent(prefix=eg.event.payload[3], suffix=eg.event.payload[0])
Last edited by yokel22 on Wed Mar 07, 2018 4:39 pm, edited 1 time in total.

User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Trigger when a specifc pushbullet is received (or contains a specifc word).

Post by Pako » Wed Mar 07, 2018 11:55 am

Your solution
yokel22 wrote:
Tue Mar 06, 2018 9:56 pm

Code: Select all

eg.TriggerEvent(prefix='pushbullet', suffix=eg.event.payload[0])
is pretty good (it will work), but you are wrong in the other:
1) you can get the sender identification as a eg.event.payload[3] (in this case, it is 'Home Assistant')
2) eg.event.payload[2] - this is push ID. This can be used, for example, for automatic push dismission

Pako

User avatar
yokel22
Experienced User
Posts: 265
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: Trigger when a specifc pushbullet is received (or contains a specifc word).

Post by yokel22 » Wed Mar 07, 2018 4:31 pm

Thanks for adding that Pako. I'll update the example. Just out of curiosity, what's payload[1]?

TrentLane
Posts: 4
Joined: Wed May 20, 2009 7:38 pm

Re: Trigger when a specifc pushbullet is received (or contains a specifc word).

Post by TrentLane » Wed Mar 07, 2018 6:35 pm

Thank you both for your input, I get what your saying but I don't fully appreciate how to incorperate the if into Evenghost itself.

As it stands I have a Macro aptly named "Door Notify"

Under that I have an event "PushBullet.Note.HomeAssistant"

Then I have a Python Script under that with the following:

Code: Select all


if eg.event.payload[0] == "Door1":
    #condition met execute code
    eg.TriggerEvent(prefix=eg.event.payload[3], suffix=eg.event.payload[0])
Then I have an action called 'Run Notification' which runs "C:\Program Files\Home Assistant\Notifications\front_door.ahk" (an AHK script that pops up a notification at the bottom of my screen saying "Front Door Opened").

At the moment I can message anything and it will load the notification. I appreciate that it's because I have no corrilation between the python script and the action. How to i incorperate this? Do I need to move away from EventGhost's "action" and somehow run the .ahk file from the PythonSript instead?

User avatar
yokel22
Experienced User
Posts: 265
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: Trigger when a specifc pushbullet is received (or contains a specifc word).

Post by yokel22 » Wed Mar 07, 2018 7:30 pm

There are a number of ways you can do it. The example i showed should trigger a 2nd event if the condition is met 'Home Assistant.DOOR1'. You'd add that event to your 'Run Notification' macro. Or you could skip the trigger event and run the action directly with python. To get the python for an action, right click on it and choose 'copy as python'. Then you can paste that into your script. It will look something like this

Code: Select all

eg.plugins.System.Execute(u'"C:\\Program Files\\Home Assistant\\Notifications\\front_door.ahk', u'', 0, False, 2, u'', False, False, u'', False, False, False, False)
So your python script would look something like this.

Code: Select all

if eg.event.payload[0] == "DOOR1":
    #condition met execute code, run action
    eg.plugins.System.Execute(u'"C:\\Program Files\\Home Assistant\\Notifications\\front_door.ahk', u'', 0, False, 2, u'', False, False, u'', False, False, False, False)
If you prefer seeing the actions icons instead of just a python script you can do it like this also. This is xml not python, copy code, then right click somewhere on your egTree & paste.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="0.5.0-rc4">
    <Macro Name="Door Notify" XML_Guid="{DB0E82DB-7EA3-496E-A94C-77B5FBD8B0CB}" Expanded="True">
        <Event Name="PushBullet.Note.HomeAssistant" XML_Guid="{DA244F45-0D84-4EDA-9D6D-DF1D94D587B2}" />
        <Action XML_Guid="{AE271B09-D51E-4A32-AF3D-7108762A0143}">
            EventGhost.PythonScript(u'if eg.event.payload[0] == "DOOR1":\n    #condition met, exit script, continue subsequent actions in the macro.\n    eg.Exit()\nelse:\n    #condition not met, exit macro immediately. \n    eg.StopMacro()\n    eg.Exit()\n')
        </Action>
        <Action XML_Guid="{1671A9DC-3571-4746-969F-62FEBDE64233}">
            System.Execute(u'"C:\\Program Files\\Home Assistant\\Notifications\\front_door.ahk', u'', 0, False, 2, u'', False, False, u'', False, False, False, False)
        </Action>
    </Macro>
</EventGhost>
To see more about python scripting see here: http://eventghost.net/docs/scripting.html

TrentLane
Posts: 4
Joined: Wed May 20, 2009 7:38 pm

Re: Trigger when a specifc pushbullet is received (or contains a specifc word).

Post by TrentLane » Wed Mar 07, 2018 8:47 pm

Thank you for your help, I went down the route of :

Code: Select all

if eg.event.payload[0] == "DOOR1":
    eg.Exit()
else:
    eg.StopMacro()
    eg.Exit()
As, quite frankley, it made sense to me. I should probably go down the full python route as it would be adventages to learn a bit of pything. Regardless, thank you very much for your help.

User avatar
yokel22
Experienced User
Posts: 265
Joined: Thu Feb 05, 2015 5:56 pm
Location: U.S. - Kansas city

Re: Trigger when a specifc pushbullet is received (or contains a specifc word).

Post by yokel22 » Wed Mar 07, 2018 9:28 pm

That's the way I prefer to do it. You could also use a "jump to" action. It's kinda cludgy like TriggerEvent IMO.

Post Reply