HOWTO: Get notifications via Prowl on your iPhone

Hi,

I have Prowl set up to alert me when energy usage hits 5kwh of house hold electricity being used, it works a treat, but once usage reaches that peak, it keeps alerting all the time i assume while it is still reporting its over 5kwh.

Is there a way to only send the alert once and then maybe reset/check again 10 mins later?

I tried adding luup.sleep (10000) to the very end, but it gave me an error that looked like it effected other scenes.

There is probably a few ways you can do this. But a few ideas are:

One set up a vertical switch (say send notification) that is now part of the conditional tests. after you send the first message it is set to off (do not send notification) and then it would be reset to on (send) when you reading falls below threshold (this maybe diffent to the send value e.g. Send at 5000 reset at 4900) or manually acknowledge.

Otherwise use variable container to do the same with old and new readings and only send when the Old reading < 5000 and >=5000.

Thanks Brientim

I’m using the combination switch and having it so when the value hits 5000+ the switch goes on and the notifications are sent.

Quick other question, please could someone share expels of the text and priority that can be sent via the Luup code and Prowl, I understand there are a number of severities, but the text is interesting with ‘+’ for spaces and %27 for apostrophes ? Why?

&application=Micasaverde+Vera&event=Alert&description=Testing+nodecentral%27s+Notification+System&priority=-1")

No idea but here is an old post I tried brfore I decide to use Automator.app
http://forum.micasaverde.com/index.php/topic,6459.msg39774.html#msg39774

http://forum.micasaverde.com/index.php/topic,9796.msg65873.html#msg65873

[quote=“parkerc, post:61, topic:166686”].
the text is interesting with ‘+’ for spaces and %27 for apostrophes ? Why?[/quote]

It’s called URI encoding. It’s a feature of HTTP to hide characters “special” to HTTP so that they are passed through untouched to the application. See: URL encoding - Wikipedia

[quote=“Brientim, post:62, topic:166686”]No idea but here is an old post I tried brfore I decide to use Automator.app
http://forum.micasaverde.com/index.php/topic,6459.msg39774.html#msg39774

http://forum.micasaverde.com/index.php/topic,9796.msg65873.html#msg65873[/quote]

I’m all for an easy life of no coding, hence it sounds like rather than doing stuff like this. (how do you edit the Lua start up anyway?)

[quote=“chixxi”]I use Prowl. I set up a main function in the startup lua:

-- Send push message to all or custom reciver -- send to all devices: use param ALL -- usage: pushMsg("message", "topic", "receiver")

apikeys = { mirk=“ssdfaadafdawedxdedsdddafx”, chix=“fxasdxfawedxaefxaxaxecaxf” }

function pushMsg(msg, event, reciver)
if ( reciver ~= “ALL” ) then
luup.log("mirkLog[i] push MSG: " … msg … " event: " … event … " to: " … reciver … “=”… apikeys[reciver])
luup.inet.wget(“https://api.prowlapp.com/publicapi/add?apikey=” … apikeys[reciver] … “&application=Vera3&event=” … event … “&description=” … msg … “&priority=+1”)
else
–loop throug apikeys
for k,v in pairs(apikeys) do
– print(msg … “event: " … event … " to: " … k … " apikey” … v )
luup.log("mirkLog[i] push MSG: " … msg … " event: " … event … " to: " … k)
luup.inet.wget(“https://api.prowlapp.com/publicapi/add?apikey=” … v … “&application=Vera3&event=” … event … “&description=” … msg … “&priority=+1”)
end
end
end

then I can easily set up messages in the scenes with a simple luup code:

pushMsg("Coffee+Machine+is+ready!", "Nespresso", "ALL")

I am thinking about writing a prowl plugin, but didn’t have time so far…

BTW: Thanks to @kru, he’s a friend of mine and wrote this code![/quote]

You’ve gone with the built in functionality of Automator.app. .

http://push.automatorapp.com/

I like Prowl, obviously as it can technically be integrated into a number of things, but what are the pros/cons of the Automatorapp push feature.

@parkerc

Lua start up is in Apps > Develop Apps > Edit Startup Lua

Automator.app does the same to deliver notifications to an iDevice…
It give you both control over you Vera and its devices remotely and can it is configure via a scene to deliver the notification. Becase, it is an embedded app once installed, it is similiar to manage the notification as you do not have to worry about luup codes.

With the new firmware it provides some additional functionality see.

http://forum.micasaverde.com/index.php/topic,11019.0.html

All–

Anyone out there proficient enough with lua to add a date/time to the prowl/growl notifications?

luup.inet.wget(“http://www.prowlapp.com/publicapi/add?apikey=XXXXXXXXXXXXXXX&application=Vera&event=Alert&description=Girlfriend’s+PIN+Code+Entered&priority=-1”)

When I get the prowl notifications on the iphone I can’t tell when they occurred. I would be great to have the date and time appended to the notification. I spent the afternoon playing with it and a lua guide… I’m no closer to getting it to work…

Any help would be appreciated.

Don

Something like this should do it:

local url = require("socket.url") local when = url.escape(os.date()) luup.inet.wget("http://www.prowlapp.com/publicapi/add?apikey=XXXXXXXXXXXXXXX&application=Vera&event=Alert&description=Girlfriend%27s+PIN+Code+Entered+" .. when .. "&priority=-1")

Something like this should do it:

local url = require("socket.url") local when = url.escape(os.date()) luup.inet.wget("http://www.prowlapp.com/publicapi/add?apikey=XXXXXXXXXXXXXXX&application=Vera&event=Alert&description=Girlfriend%27s+PIN+Code+Entered+" .. when .. "&priority=-1") [/quote]

Futzle

Thank you. That works great!!!

    Don

A long shot, but you never know…

If anyone here is using Prowl and has wanadoo.fr as their ISP, take a moment to check that your scenes haven’t Gone Skynet and started sending thousands of notifications. The author of Prowl is reporting getting DoS’d from that provider.

Something like this should do it:

local url = require("socket.url") local when = url.escape(os.date()) luup.inet.wget("http://www.prowlapp.com/publicapi/add?apikey=XXXXXXXXXXXXXXX&application=Vera&event=Alert&description=Girlfriend%27s+PIN+Code+Entered+" .. when .. "&priority=-1") [/quote]

I tried this but I must be doing something wrong. This is the code I entered…am I missing something.

local url = require(“socket.url”)
local when = url.escape(os.date())
luup.inet.wget(“http://www.prowlapp.com/publicapi/add?apikey=xxxxxxxxxxxxxxxxxxxxxx&application=Vera&event=ArmedSensors &description=Alarm+Armed&priority=-1”)
return true

Thanx

[quote=“nanuetsteve, post:70, topic:166686”]I tried this but I must be doing something wrong. This is the code I entered…am I missing something.

luup.inet.wget("http://www.prowlapp.com/publicapi/add?apikey=xxxxxxxxxxxxxxxxxxxxxx&application=Vera&event=ArmedSensors &description=Alarm+Armed&priority=-1") [/quote]

There’s a space in that URL. URLs aren’t allowed to contain spaces.

[quote=“futzle, post:71, topic:166686”][quote=“nanuetsteve, post:70, topic:166686”]I tried this but I must be doing something wrong. This is the code I entered…am I missing something.

luup.inet.wget("http://www.prowlapp.com/publicapi/add?apikey=xxxxxxxxxxxxxxxxxxxxxx&application=Vera&event=ArmedSensors &description=Alarm+Armed&priority=-1") [/quote]

There’s a space in that URL. URLs aren’t allowed to contain spaces.[/quote]

Thanks for reply. I don’t have the space you refer to…I am getting the prowl notification, but not any time stamp, so I assume, maybe wrongfully so, the second half of the code is correct. If you have the patience, can we take one last look. Again, the copied and pasted code below.

– Inform me when the alarm system is armed.
local url = require(“socket.url”)
local when = url.escape(os.date())
luup.inet.wget(“http://www.prowlapp.com/publicapi/add?apikey=6251f75d109e35a200603bfcb6713e29f50f0cf6&application=Vera&event=Alarm+Armed&priority=-1”)
return true

The code as shown in the vera trigger luua section has all three instances of "url"and one instance of “os” underlined with a red squiggly.
If you have the time, thanks, if not, no worries

Regards,
Steve

Hi Steve,

Thanks for copy-and-pasting your actual code. That precludes any chance of introducing typos like that stray space, which led me to the wrong conclusion.

The reason why your timestamp isn’t appearing in the notification is that you never refer to the variable “when” after you assign to it. Take a look at the code in my post 67 in this thread, and compare it with yours. In particular pay attention to the part that goes " … when …"; this is the part that inserts the timestamp into the URL.

[quote=“futzle, post:73, topic:166686”]Hi Steve,

Thanks for copy-and-pasting your actual code. That precludes any chance of introducing typos like that stray space, which led me to the wrong conclusion.

The reason why your timestamp isn’t appearing in the notification is that you never refer to the variable “when” after you assign to it. Take a look at the code in my post 67 in this thread, and compare it with yours. In particular pay attention to the part that goes " … when …"; this is the part that inserts the timestamp into the URL.[/quote]

Ok, i will run through it…sorry I am very new to this but am coming close to getting what I need and will be content with. Very nice that people like yourself offer to help. By the way, your combination switch is really nice.

Great, I just got it working, now I don’t have to open Prowl app to see time…very nice and Thanx

I have added Prowl to Vera Alerts.

You can add the time to any message in Vera Alerts by sending a message as follows:

The door was opened at: {Datetime(currenttime, {DateTimeFormat})}

The message will be received as:
The door was opened at: Friday December 06 2013 08:19

There are options to format this time differently!

Well, I hadn’t seen this thread, and I apparently reimplemented the wheel. If anyone’s curious, here’s my version:

[ul][li]Is a pure lua version[/li]
[li]Supports multiline text[/li]
[li]Supports message priority[/li]
[li]Supports rate limiting (for some reason, each trigger causes my scene’s luup code to be run three times).[/li]
[li]Everything’s easily configured via variables at the top.[/li][/ul]

[code]local apikey = “0000000000000000000000000000000000000000”
local application_name = “Front door”
local event_text = “Door opened”

– default description is like:
– 04:59:23 PM, Jan 25, 2013
local description = os.date(“%I:%M:%S %p, %b %d, %Y”)

– Priority is an integer in the range of [-2 … 2].
– -2 is very low priority, 0 is normal, and +2 is emergency
local priority = 0

– limit notifications to only once every this many seconds:
local limit_notifications = 10

local class_name = “front_door”


require ‘socket.http’
require ‘ltn12’

– Convert text into a URL-safe form. See RFC 1738 for unsafe characters.
local function transmorgrify_text(str)
– There’s probably a much better way to do this, but lua seems to be
– poorly documented, as the authors seem to want you to buy the book …
local s = string.gsub(str, “%%”, “%%25”)
s = string.gsub(s, “\n”, “%%0a”)
s = string.gsub(s, “\r”, “”) – go away
s = string.gsub(s, “\t”, “%%09”)
s = string.gsub(s, " ", “%%20”)
s = string.gsub(s, “!”, “%%21”)
s = string.gsub(s, “"”, “%%22”)
s = string.gsub(s, “#”, “%%23”)
s = string.gsub(s, “\$”, “%%24”) – not necessary?
s = string.gsub(s, “&”, “%%26”)
s = string.gsub(s, “'”, “%%27”)
s = string.gsub(s, “[(]”, “%%28”) – not necessary?
s = string.gsub(s, “[)]”, “%%29”) – not necessary?
s = string.gsub(s, “[*]”, “%%2a”) – not necessary?
s = string.gsub(s, “[+]”, “%%2b”) – not necessary?
s = string.gsub(s, “,”, “%%2c”) – not necessary?
s = string.gsub(s, “:”, “%%3a”)
s = string.gsub(s, “;”, “%%3b”)
s = string.gsub(s, “<”, “%%3c”)
s = string.gsub(s, “=”, “%%3d”)
s = string.gsub(s, “>”, “%%3e”)
s = string.gsub(s, “[?]”, “%%3f”)
s = string.gsub(s, “@”, “%%40”)
s = string.gsub(s, “[[]”, “%%5b”)
s = string.gsub(s, “\”, “%%5c”)
s = string.gsub(s, “]”, “%%5d”)
s = string.gsub(s, “[\^]”, “%%5e”)
s = string.gsub(s, “`”, “%%60”)
s = string.gsub(s, “{”, “%%7b”)
s = string.gsub(s, “|”, “%%7c”)
s = string.gsub(s, “}”, “%%7d”)
s = string.gsub(s, “~”, “%%7e”)
return s
end

local function prowl_notify(apikey, application_name, event_text, rate_limit)

if rate_limit then
local current_time = os.time()

  if prowl_last_notify_time then
 if prowl_last_notify_time[class_name] then
    if prowl_last_notify_time[class_name] > 
       (os.time() - rate_limit) then
       return nil
    end
 end
  else
 prowl_last_notify_time = {}
  end
  prowl_last_notify_time[class_name] = current_time

end

local response_body = {}

local request_body = “apikey=” … apikey …
“&application=” … transmorgrify_text(application_name) …
“&event=” … transmorgrify_text(event_text) …
“&description=” … transmorgrify_text(description) …
“&priority=” … tostring(priority)

socket.http.request{
url = “https://api.prowlapp.com/publicapi/add”,
method = “POST”,
headers = {
[“Content-Type”] = “application/x-www-form-urlencoded”,
[“Content-Length”] = string.len(request_body)
},
source = ltn12.source.string(request_body),
sink = ltn12.sink.table(response_body)
}
return response_body
end

local response_body

response_body = prowl_notify(apikey, application_name, event_text,
limit_notifications)
– if response_body then
– table.foreach(response_body,print)
– end
– response_body = prowl_notify(apikey, application_name, event_text,
– limit_notifications)
– if response_body then
– table.foreach(response_body,print)
– end

return true
[/code]

Thanks for sharing your bells-and-whistles version. If you are curious, Lua has a table form of gsub() which makes your URLification much shorter:

rep = { [" "] = "%20", ["!"] = "%21",
  -- and so on
}
print s:gsub("[ !"#\$%...]", rep)

There’s an example like this in the Lua 5.1 manual online.

Worked a treat :slight_smile: