# Pushbullet Sender für WG
# In conf GA, title und body eintragen
# wenn GA=1 dann werden title und body gesendet
# by NetFritz KNX-Userforum
# Konfigurationsfile einlesen
my $conf=$plugname; $conf=~s/\.pl$/.conf/;
$conf="/etc/wiregate/plugin/generic/conf.d/$conf";
my %push=();
my $err=read_from_config();
return $err if $err;
#
# in $iso steht Datum-Zeit = 'd.m.Y H:M'
my @dta = localtime(time);
my $iso=sprintf('%02d.',$dta[3]);
$iso.=sprintf('%02d.',$dta[4]+1);
$iso.=($dta[5]+1900)." ";
$iso.=sprintf('%02d:',$dta[2]);
$iso.=sprintf('%02d',$dta[1]);
#
$plugin_info{$plugname.'_cycle'} = 3600;
# Alle GAs aus der config abonnieren
for my $r (grep ref($push{$_}), keys %push)
{
$plugin_subscribe{$push{$r}{GA}}{$plugname}=1;
plugin_log($plugname, "plugin_subscribe $push{$r}{GA}");
}
my $req = "";
my $body = "";
# BUS ueberwachen
if ($msg{'apci'} eq "A_GroupValue_Write") { # A_GroupValue_Write Telegramm eingetroffen
plugin_log($plugname, "subscribe wurde ausgefuehrt");
for my $r (grep ref($push{$_}), keys %push){ # Ueberwachte GAs durchlaufen
if ($msg{'dst'} eq $push{$r}{GA}){ # GAs vergleichen
if($msg{'value'} == 1){
$body = $push{$r}{body_on};
$plugin_info{$plugname.'_'.$r.'_alt'} = 1;
}elsif($msg{'value'} == 0){
$body = $push{$r}{body_off};
$plugin_info{$plugname.'_'.$r.'_alt'} = 0;
}
# Push senden
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
my $ua = LWP::UserAgent->new;
my $req = POST 'https://api.pushbullet.com/v2/pushes',
[
type => 'note',
title => $push{$r}{title},
body => $iso." ". $body
];
$req->authorization_basic('KEY');
#return ($push{$r}{GA});
print ($ua->request($req)->as_string);
plugin_log($plugname, "$push{$r}{title} $push{$r}{body} $msg{'value'}");
}
}
}
return;
# ------------- config einlesen ----------------------
sub read_from_config
{
open CONFIG, "<$conf" || return "no config found";
my @lines = <CONFIG>;
close CONFIG;
plugin_log($plugname, "lines @lines");
eval("@lines");
return "config error" if $@;
}
# In conf GA, title und body eintragen
# wenn GA=1 dann werden title und body gesendet
# by NetFritz KNX-Userforum
# Konfigurationsfile einlesen
my $conf=$plugname; $conf=~s/\.pl$/.conf/;
$conf="/etc/wiregate/plugin/generic/conf.d/$conf";
my %push=();
my $err=read_from_config();
return $err if $err;
#
# in $iso steht Datum-Zeit = 'd.m.Y H:M'
my @dta = localtime(time);
my $iso=sprintf('%02d.',$dta[3]);
$iso.=sprintf('%02d.',$dta[4]+1);
$iso.=($dta[5]+1900)." ";
$iso.=sprintf('%02d:',$dta[2]);
$iso.=sprintf('%02d',$dta[1]);
#
$plugin_info{$plugname.'_cycle'} = 3600;
# Alle GAs aus der config abonnieren
for my $r (grep ref($push{$_}), keys %push)
{
$plugin_subscribe{$push{$r}{GA}}{$plugname}=1;
plugin_log($plugname, "plugin_subscribe $push{$r}{GA}");
}
my $req = "";
my $body = "";
# BUS ueberwachen
if ($msg{'apci'} eq "A_GroupValue_Write") { # A_GroupValue_Write Telegramm eingetroffen
plugin_log($plugname, "subscribe wurde ausgefuehrt");
for my $r (grep ref($push{$_}), keys %push){ # Ueberwachte GAs durchlaufen
if ($msg{'dst'} eq $push{$r}{GA}){ # GAs vergleichen
if($msg{'value'} == 1){
$body = $push{$r}{body_on};
$plugin_info{$plugname.'_'.$r.'_alt'} = 1;
}elsif($msg{'value'} == 0){
$body = $push{$r}{body_off};
$plugin_info{$plugname.'_'.$r.'_alt'} = 0;
}
# Push senden
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
my $ua = LWP::UserAgent->new;
my $req = POST 'https://api.pushbullet.com/v2/pushes',
[
type => 'note',
title => $push{$r}{title},
body => $iso." ". $body
];
$req->authorization_basic('KEY');
#return ($push{$r}{GA});
print ($ua->request($req)->as_string);
plugin_log($plugname, "$push{$r}{title} $push{$r}{body} $msg{'value'}");
}
}
}
return;
# ------------- config einlesen ----------------------
sub read_from_config
{
open CONFIG, "<$conf" || return "no config found";
my @lines = <CONFIG>;
close CONFIG;
plugin_log($plugname, "lines @lines");
eval("@lines");
return "config error" if $@;
}
Kommentar