Blink Cameras and Presense detection

In my house me and my wife have phones, OH already checks them thru WiFi and Bluetooth and with this detects if we are at home. Recently I bought a set of Blink Cameras but i couldn’t find any add-on for OH that gives full control on this Cameras.

The only thing I needed was that OH detected me or my wife are at home and disarm (disable) the cameras, or, arm them if both of us are out.

Searched online for a solution and found this REPO:
With a bit of POSTMan and some REST POSTs and GETs later I finally found out the final CURLs that needed to be executed.

First you need to use this CURL to get the SECRET_TOKEN, replace YOUR_SECRET_PASSWORD and EMAIL_THAT_YOU_USE_IN_THE_BLINK_APP with you own information:

curl -X POST \ \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Host:' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F 'password=[YOUR_SECRET_PASSWORD]' \
  -F 'client_specifier=iPhone 9.2 | 2.2 | 222' \

Then you will need to get the NETWORK_ID and CAMERA_ID, to do that use this CURL:

curl -X GET \[ACCOUNT_ID]/homescreen \
  -H 'Host:' \
  -H 'cache-control: no-cache'

Now use that info in this CURL to Enable the camera:

curl -X POST[NETWORK_ID]/camera/[CAMERA_ID]/enable -H 'Host:' -H 'TOKEN_AUTH: [SECRET_TOKEN]' -H 'cache-control: no-cache'> /dev/null 2>&1

and this one to Disable the camenra:

curl -X POST[NETWORK_ID]/camera/[CAMERA_ID]/disable -H 'Host:' -H 'TOKEN_AUTH: [SECRET_TOKEN]' -H 'cache-control: no-cache'> /dev/null 2>&1

Now you just need to create one script for enable and other for disable in the folder Scripts, make them executable. Also, if you have more then one camera, put 5s sleep in the middle of the CURL calls, this is to avoid API to refuse your connections.

== My own Script ==

curl -X POST[NETWORK_ID]/camera/[CAMERA_ID]/disable -H 'Host:' -H 'TOKEN_AUTH: SECRET_TOKEN' -H 'cache-control: no-cache'> /dev/null 2>&1
sleep 5s
curl -X POST[NETWORK_ID]/camera/[CAMERA_ID]/disable -H 'Host:' -H 'TOKEN_AUTH: SECRET_TOKEN' -H 'cache-control: no-cache'> /dev/null 2>&1
echo "Blink - Cameras Disabled"

And the last bit is to add the execution of this scripts in wherever place you need, just by doing something like this:

val results = executeCommandLine ("/srv/openhab2-conf/scripts/",10000)
val results = executeCommandLine ("/srv/openhab2-conf/scripts/",10000)

And to finalize, here’s a little demo video showing this working:

Enjoy and hope this helps someone.


It looks like after a while the token dies. Let’s update the bash script and with a new PHP file.

I’m not a master Jedi at bashing, I’m more a PHP guy, that’s why the PHP is in here, but if you know how to do it in bash, share with me :slight_smile: and make this solution a bit more simple.

This is assuming that you have a PHP service running on your Pi.

== My new Script ==

touch token.txt
tokenValue=$(cat token.txt)
code=$(curl -X POST[NETWORK_ID]/camera/[CAMERA_ID]/disable -H 'Host:' -H "TOKEN_AUTH: ${tokenValue}")

if [[ $code == *"Unauthorized"* ]]; then
    sleep 5s
    cd /srv/openhab2-conf/scripts/; /usr/bin/php gettoken.php
    tokenValue=$(cat token.txt)
    curl -X POST[NETWORK_ID]/camera/[CAMERA_ID]/disable -H 'Host:' -H "TOKEN_AUTH: ${tokenValue}"> /dev/null 2>&1
sleep 5s
curl -X POST[NETWORK_ID]/camera/[CAMERA_ID]/disable -H 'Host:' -H "TOKEN_AUTH: ${tokenValue}" -H 'cache-control: no-cache'> /dev/null 2>&1

echo "Blink - Cameras Disabled"

== My PHP file to get the new token ==

$client="iPhone 9.2 | 2.2 | 222";

$headers = array(
    "Content-Type: application/x-www-form-urlencoded",
    "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
$data = "password=".$password."&email=".$email."&client_specifier=".$client;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
$response = json_decode($result, true);
file_put_contents("token.txt", $response['authtoken']['authtoken']);

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.