I am wondering is it possible to attach photo in notification? I have added few generic cameras in configuration.yaml and I can view the snapshot using the URL set in still_image_url.
It would be great if I can attach those snapshots in my notifications. For example, when the home alarm is triggered, it will notify me with the snapshot from the specific camera.
That would be awesome!!! At least to send the image by email when the alarm is triggered… I’m sure that there is a workaround to do it through scrips or command lines…
Let’s see. For the moment Im still learning the basics and connecting my sensors from mysensors.
While I’d like to make it better, here is the script. I shamelessly copied it from a Reddit post, I just added the lines at the top to grab the image via shell commands. I’m going to fix that part, it was a quick and dirty hack.
Script:
#!/usr/bin/perl
use JSON;
use LWP::UserAgent;
# credentials and device identifier
my $api_key = 'pushbullet api key';
my $device = 'device iden';
# file to send
`rm /tmp/camera1.jpg`;
`wget -q -O /tmp/camera1.jpg http://x.x.x.x:8123/api/camera_proxy/camera.camera1`;
my $file_name = '/tmp/camera1.jpg';
my $file_type = 'image/jpeg';
my $user_agent = LWP::UserAgent->new();
$user_agent->agent('My File Pusher v1.0');
# Send a request for authorisation to upload a file ..
my $request_response = $user_agent->post('https://api.pushbullet.com/v2/upload-request',
'Authorization' => 'Bearer '.$api_key,
'Content' => ['file_name' => $file_name,
'file_type' => $file_type]);
if ($request_response->is_success) {
# no obvious error from the server, parse the JSON ..
my $json = from_json($request_response->content);
if ($json->{'upload_url'}) {
# we have an end point to push to and we can upload the file
my @data;
# the order of these fields is important, AWS will cry if you don't respect the ordering!!
foreach my $item ('awsaccesskeyid', 'acl', 'key', 'signature', 'policy', 'content-type') {
push(@data, $item => $json->{'data'}->{$item})
}
# and add the file
push(@data, 'file' => [ $file_name ]);
# now attempt to upload the file
my $upload_response = $user_agent->post($json->{'upload_url'},
'Content_Type' => 'form-data',
'Content' => \@data);
if ($upload_response->is_success) {
# looks like we uploaded the file successfully
# so now send the actual push to the device
my $push_response = $user_agent->post('https://api.pushbullet.com/v2/pushes',
'Authorization' => 'Bearer '.$api_key,
'Content-Type' => 'application/json',
'Content' => to_json({'device_iden' => $device,
'type' => 'file',
'file_name' => $json->{'file_name'},
'file_type' => $json->{'file_type'},
'file_url' => $json->{'file_url'}}));
if ($push_response->is_success) {
#print "Pushed OK!\n";
exit 0;
}
else {
#print "Push failed!\n";
exit 1;
}
}
}
}
Thank you rpr for the tip.
Is it working for you? In my case, I get the upload-request successful but then it stuck when uploading the file into the upload_url.
I also tried with curl and I have the same problem…
curl -i -X POST https://upload.pushbullet.com/upload-legacy/blablablablablaaaa -F [email protected]g
Yes, it works fine for me. Did you generate an API key in pushbullet and get your device iden? You need to get those and put them in the script at the top, and change the url of your camera to grab a still frame.
You can’t just use curl like that to upload to pushbullet. You need to send a request to upload, then process the response, then tell it what file you are uploading, then upload the file. It’s detailed in the script above. If it was a simple one-line curl, we wouldn’t need the script!
Hi, Yes, I understand. The upload-request works fine and after doing it I received the upload_url to upload the file and the file_url to perform the push later. But on the next step when I try to perform the upload of the file (POST) it get’s stuck.
It get’s stuck in this part of the code: my $upload_response = $user_agent->post($json->{'upload_url'}, 'Content_Type' => 'form-data', 'Content' => \@data);
I tried to do the POST with curl (after doing the upload-request) first but I get the same behaviour.
Something that is a little bit strange is the name of the upload_url that receive. It contains upload-legacy in its name…
In my case, the scrip is failing on the upload step (before the push) where the deviceID is not necessary yet… I’m sure that it is something related to my account because I have the same problem with another script (based on bash) and also doing it manually with curl.
I will write to pushbullet support to see what happens…
Ok. I’m progressing with my problem with pushbullet. I know that the problem is not with my account but with the curl version on Linux. I tried from two different ubuntu distribution and I have the same problem. I also tried with curl on the Raspberry (weezy) and I got the same.
But when installed and tried curl on windows the upload is working fine! That’s very strange… I don’t know what could be the root cause on Linux. It seems that all the scripts around (perl, php, phyton, bash) are based on curl or curl library.
I will keep trying…
I’m becoming crazy… The same command works on windows but not in Linux. (any linux)
Problem solved!!!
After doing a lot of tests I discovered that the problem was on the router. For some reason the server is trying to stablish a connection to the client or something like this. That’s very strange for a POST but I noticed that If I set the DMZ to the client’s IP then everything is working.
I still don’t know why this is working on windows… And why it is working with very small files… But it is working now !!!
I discovered this when I run the Linux on a Window’s virtual machine. Then it was working… because it was using the Windows NW adaptor.
Yes. I’m using that version written in Perl. It is working fine and it is easy to understand.
I modified the code a little bit in order to push the message to all my devices (instead of one) and also to change the Subject of the message (instead the name of the file).
There are more versions available in bash, python and php with more functionalities but this one is doing the job pretty well.