Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nma notification.pl #253

Merged
merged 1 commit into from
Aug 31, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions code/common/nma_notification.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Category=Home_Network
#
#@ Sends Notification messages to NMA - Notify My Android

# The following config parameters should be in mh.private.ini or mh.ini
#
# nma_api_key=<api key> (API Key from NotifyMyAndroid)

use LWP::UserAgent;

# noloop=start
my $nma_api_key = $config_parms{nma_api_key};
# noloop=stop


#Tell MH to call our routine each time something is spoken
&Speak_pre_add_hook(\&nma_notify,1) if $Reload;

# Notify the on startup / restart
if ($Startup) {
print_log("System Restarted, Notifying NMA -- using api key: ", $nma_api_key );
nma_notify_b("$nma_api_key", "Misterhouse has been restarted");
}

sub nma_notify() {
my %parms = @_;
print "NMA message sent";
print "----------------";
nma_notify_b("$nma_api_key", "$parms{text}");
return;
}

sub nma_notify_b{
my ($nma_api_key, $text) = @_;

print "NMA message sent";

# syntax to send a message from a browser or curl -- ie: for testing
# https://www.notifymyandroid.com/publicapi/notify?apikey=<api key>&application=<application name>&event=<event name>&description=<description>&priority=0

# NMA allows you to print to 3 lines
# I prefer printing to the main line which is listed as application in the below url. This works great fot GTV since the event pops up over whatever you are watching
my $url = 'https://www.notifymyandroid.com/publicapi/notify?apikey='.$nma_api_key.'&application='.$text.'&event=&description=&priority=0';

# If you prefer the main line to list MisterHouse and have your event appear on the second line, uncomment the following line and comment out the line above this
# my $url = 'https://www.notifymyandroid.com/publicapi/notify?apikey='.$nma_api_key.'&application=MisterHouse&event='.$text.'&description=&priority=0';

# Change spaces to HTML space codes
$url =~ s/ /%20/g;
my $ua = new LWP::UserAgent;
my $req = new HTTP::Request GET => $url;
my $res = $ua->request($req);
}