HOWTO: Get notifications via Prowl on your iPhone

Anyone know if it’s possible to use variable in the message text?

Anyone know if it’s possible to use variable in the message text? [/quote]
Response to what you quoted, not your question: in a single scene use events for each desired PIN and attach Luup to each event that sends the message with a different text (“John opened door X”, “Jane opened door X”, etc.; assuming John and Jane use their own PIN.).

You would do something like this:

local partition = luup.devices[94].description local user = luup.variable_get("urn:micasaverde-com:serviceId:AlarmPartition1", "LastUser", 94) or "Unknown" luup.inet.wget("https://prowl.weks.net/publicapi/add?apikey=123456789012345678901234567890&application=Vera&event=Armed&description=" .. partition .. "+Armed+by+" .. user .. "&priority=-1") return true

Problems:

[ul][li]The strings have to be URI-escaped (percent-encoding), which there isn’t a nice Lua function for.[/li]
[li]MiOS doesn’t update variables immediately, so the “last user” above is actually the last last user.[/li][/ul]

Holy crap, that works. Thanks.

[tt]socket.url [/tt] provides [tt]url.escape()[/tt] and [tt]url.unescape()[/tt].

[tt]socket.url [/tt] provides [tt]url.escape()[/tt] and [tt]url.unescape()[/tt].[/quote]

Duh, and I knew that too. Brainfart on my part. Thanks for pointing it out.

MiOS doesn't update variables immediately, so the "last user" above is actually the [i]last[/i] last user.

Belay that. Stupid programmer mistake. MiOS does update variables immediately. Too immediately: the implementation of my security system device updated the alarm’s state a few lines earlier in the code than it updated the last user, and the event was firing in between. Solution: swap the lines of code. It works great now.

@futzle

Ok if i throw this into a “How To”?

Id like you to review it before i put it on the wiki.

Let me know

Regards,

Henk

[quote=“futzle, post:1, topic:166686”]I use Prowl, an iPhone app which displays push notifications. Prowl has an HTTP API which lets programs running on your computer, or Vera, transmit push notifications to your phone.

Getting Vera to inform you of an event just requires adding the following Luup code to the event that triggers a scene. Create the scene event just as you normally would (here, “Alarm system is armed”), then put this code into the Luup event box:

-- Inform me when the alarm system is armed. luup.inet.wget("https://prowl.weks.net/publicapi/add?apikey=0123456789012345678901234567890123456789&application=Vera&event=Armed&description=Alarm+Armed&priority=-1") return true

Just change the 40-digit API key to the one for your Prowl account.

(Edit: Make more grammaticaller.)[/quote]

@futzle
Im trying this out on an event that switches of lights and added the code with my personal API key to the evnt box of LUUP in the created event.

Did this and get an “error in lua message” any suggestions?

–edit!–

Note to self… when cutting and pasting, make sure not to insert spaces in code

By all means.

After some experimenting with Prowl, i found that it will also work with the SMTP lib for Lua.
There is some code flying around in the forums to use luup code in a scene to receive email.

For instance the Plugins @Ap15e created (SND) here.
If one uses his Prowl mailaddress as decribed here

Also it is possible to integrate Prowl this way by adding the publickey emailaddress to cp.mios.com as your primary notification mail address and get messages pushed directly to your iPhone

Your address will be in the form personal_apikey@api.prowlapp.com. Using your address You can use your address wherever you would normally use an email address. Put it into an email notifications field on a website, or forward your email to it for instant notification.

I have also been able to use Prowl with the new Ap15e plugin FCM (found here.)

Using the code described in other messages in this thread

-- Inform me when the alarm system is armed.
luup.inet.wget("https://prowl.weks.net/publicapi/add?apikey=0123456789012345678901234567890123456789&application=Vera&event=Armed&description=Alarm+Armed&priority=-1")
return true

And putting it in the luup section of a created scene-event, notifications are sent to your prowl client.

Just wanted to say that this is a brilliant and easy way to get notifications on my phone.

I’m working on a script that monitors outside temp (via google weather) and the inside temp (via thermostat) and tells me when to open/close windows.

This got me most of the way there, I just need to get the timing right so it polls every minute and only sends notifications when it changes state.

Oh. Actually that’s what I need to do, just make it a state machine instead of doing odd delay/timing stuff.

Is there a way to get rid of the “Vera-Armed” portion of the notification?

If there is, I’m sure it’s simple… I’m new to this, and trial and error has yet to yield my desired result.

You can’t get rid of it, but you can change it. The “application=Vera” and “event=Armed” parts of the URL string are the important bits. The text to the right of the equals can be changed to whatever text you want. (URL percent-escaping applies if you are doing anything more fancy than alphanumerics.)

@ExHempKnight & Futzle

Well actually you can’t get rid of it, but it can be customized!
Its simply the text based format in which the message arrives. One being the header (subject) the other being the message content.

So Application=Vera can be set to any device to match f.i. a sensor (sending device)
And Event=Armed can be set to any event in any language like"Motion" or “Tripped” (subject)

Lastly the description=Lights+are+on part is the message content. and this can exist out of more than one word as long as they ar kept together by “+” characters).

So for instance this would work:

application=Lock&event=Unlocked&description=Frontdoor+has+been+unlocked!&priority=-1

As for the URL percent escaping, @futzle is completely right!

Hope that helps!

Henk

You can’t get rid of it, but you can change it. The “application=Vera” and “event=Armed” parts of the URL string are the important bits. The text to the right of the equals can be changed to whatever text you want. (URL percent-escaping applies if you are doing anything more fancy than alphanumerics.)[/quote]

@futzle: +1

Thanks for this!!

[UPDATED] count me as another with flawless results right out of the gate. Excellent tip.

Dave

Has anybody had any success with manipulating the priorities?

I would like to set the Prowl sounds settings to handle different priority messages, but the setting “-1” doesn’t seem to have any bearing - i have changed it to no avail…

[quote=“pkitch, post:36, topic:166686”]Has anybody had any success with manipulating the priorities?

I would like to set the Prowl sounds settings to handle different priority messages, but the setting “-1” doesn’t seem to have any bearing - i have changed it to no avail…[/quote]

It now seems to be working, though I did not change any of the code other than text the direct URL to verify. One very happy camper :smiley:

I’ve started getting this error while communicating with Prowl:

curl: (35) Unknown SSL protocol error in connection to www.prowlapp.com:443

I’m suspecting that the cipher that the OpenWrt version of curl uses is not among the ones that Prowl accepts. Given that (a) Prowl now accepts non-SSL HTTP for the sake of microcontrollers and other small citizens of the Internet of Things, and (b) luup.wget() disables certificate-checking anyway and would be oblivious to eavesdropping, I think it’s probably OK to just switch to using HTTP in the URL:

-- Inform me when the alarm system is armed.
luup.inet.wget("http://api.prowlapp.com/publicapi/add?apikey=0123456789012345678901234567890123456789&application=Vera&event=Armed&description=Alarm+Armed&priority=-1")
return true

(Also note deprecation of the old address prowl.weks.net.)

I keep accidentally erasing this more complex version when I do updates, so I’ll post it here for easy cut-and-paste. It demonstrates how to get device names and how to access variables, and how to correctly escape them for passing to Prowl.

local url = require("socket.url")
local apikey = "01234567890123456789abcdefabcdefabcdef01" -- CHANGE ME.
local partition = 123 -- CHANGE ME.
local which = luup.devices[partition].description
local who = luup.variable_get("urn:micasaverde-com:serviceId:AlarmPartition1", "LastUser", partition)
luup.inet.wget("http://www.prowlapp.com/publicapi/add?apikey=" .. apikey .. 
  "&application=Vera&event=Armed&description=" .. url.escape(which) .. 
  "+Armed+by+" ..  url.escape(who) .. "&priority=-1")
return true

Im trying to use this to notify me if I forgot to set my Away scene when leaving for work.
I’ve created a new scene, set it to run at 9:00 each morning, and inserted this into the LuuP tab. The script is one I found on the forum and I changed a couple of spots to fit my setup.

– Inform me if I forgot to set away scene.
local home_away = luup.variable_get(“urn:schemas-upnp-org:device:VSwitch:1”, “Status”, 16)
if (home_away == ‘1’) then
luup.inet.wget(“http://www.prowlapp.com/publicapi/add? apikey=1234567890123456789012345678901234567890&application=Vera&event=Armed&description=Home+still+set&priority=1”)
return true
else
return false
end

Im not getting any notifications when I test it.
The device is a virtual switch and the name was copied from the advanced tab.

Could someone give this a look over and see where I went wrong? Its my first attempt at using LuuP.