Blink Home scheduling Zones

blink XT photo

The Blink home security cameras are a great little piece of kit, relatively cheap, no storage costs and no wiring requirements (with an alleged two year battery life), there’s a lot to like about them.

However… There is a flaw that has seen customers return these smart little units – you can’t zone them. For example you may have one camera on the front door which you want armed at all times and one on the back garden that you don’t want armed during the day because children are playing there.

Why doesn’t this work?

Blink say it’s on the roadmap somewhere, but their focus for sometime has been the Blink doorbell. As such they don’t commit to when this functionality will be available, it’s a source of much annoyance in their community support forums. The workaround is to have two sync modules but that doesn’t appear to be without pitfalls either (and cost).

You can of course control motion detection in the app by tapping the “running man” but you might get to that after your children have spent 15 minutes in the garden and triggered 20 notifications!

Accessing Blink programmatically seems to be the answer. Dialling down to a granular control to turn on or off the motion detection element of any individual camera. Even more importantly you can schedule this with a cron job!

Controlling Blink Cameras with PHP

First things first, we need to getting logged in has become a little bit more tricky recently with 2FA (this is a good thing honestly).

We’re going to use Guzzle for our script:

composer require guzzlehttp/guzzle:^7.0

You’ll now need to include this at the start of your PHP script:

require 'vendor/autoload.php';

We’re ready to go now, first of all you’ll need to login to their main endpoint with your email address and password:

<?php 

  $loginclient = new Client([
    // Base URI is used with relative requests
    'base_uri' => 'https://rest-prde.immedia-semi.com',

    // You may need a different base_uri if you're not in Europe (untested)
    // 'base_uri' => 'https://rest-prod.immedia-semi.com',
    // You can set any number of default request options.

    'timeout'  => 2.0,
  ]);

  $body = [
    'email' => 'BLINK_EMAIL',
    'password'=> 'BLINK_PASSWORD
  ];

  $headers = [
    'content-type' => 'application/json',
  ];

  $response = $client->request(
    "POST", 
    "/api/v4/account/login", 
    [
      'headers'=> $headers, 
      'body' => json_encode($body)
    ]
);

echo $response->getBody();

This should get you a couple of things back in the response body:

  • Account ID
  • Client ID
  • Auth Token
  • and a Region Tier.

You’ll need all of these going forward!

Wait! Now whilst it may look like you’ve got access with an auth token (and you probably have according to my tests) it’s probably wise to walk through the 2FA and make sure your access token is verifiedotherwise it may stop working.

You should have received a 6 digit token via email…

<?php
  $blink_account = BLINK_ACCOUNT_ID;
  $client_id = BLINK_CLIENT_ID;
  $auth_token = AUTH_TOKEN;
  $region  = REGION_TIER;
  $pin = PIN_FROM_EMAIL;  // Your token or PIN goes here
  
  $workclient = new Client([
    // Base URI is used with relative requests
    'base_uri' => 'https://rest-'$region.'.immedia-semi.com',

    // You can set any number of default request options.
    'timeout'  => 2.0,
  ]);
  
  $headers['TOKEN-AUTH'] = $auth_token;
  
  $body = [
    'pin' => $pin,
  ];

  $response = $workclient->request(
    "POST" ,
"/api/v4/account/".$blink_account."/client/".$client_id."/pin/verify",
    [
       'headers' => $headers,
       'body' => json_encode($body)
     ]
  );
  echo $response->getBody();

This should get you verified, NOTE: I was able to make requests without doing this but I have no idea how long that access might have lasted!

Now we’re all setup it’s time for the fun part!

First we need to identify the cameras:

<?php
  $auth_token = AUTH_TOKEN;
  $region  = REGION_TIER;

  $workclient = new Client([
    // Base URI is used with relative requests
    'base_uri' => 'https://rest-'$region.'.immedia-semi.com',

    // You can set any number of default request options.
    'timeout'  => 2.0,
  ]);

  $headers['TOKEN-AUTH'] = $auth_token;

  $response = $workclient->request(
        "GET" ,
        "/api/v1/camera/usage",
        [
            'headers' => $headers,
        ]
    );

    echo $response->getBody();

With this you should get the final pieces of the puzzle we need:

  • The network id (this is the sync module the camera is attached to)
  • The camera id

From there it’s just a case of:

<?php
  // Enable motion detection
  $response = $workclient->request(
    "POST",
    "/network/".$network_id."/camera/".$camera_id."/enable",
    [
       'headers' => $headers
    ]
  );


// Disable motion detection
  $response = $workclient->request(
    "POST",
    "/network/".$network_id."/camera/".$camera_id."/disable",
    [
       'headers' => $headers
    ]
  );

What should we build next for Blink?

There’s a LOT more you can do with this system from taking snapshots to integrating with other smart home services (like turning lights on if motion is detected etc) but for now this is the only part that was required.

I did consider building a system that allowed people to schedule their individual cameras however to do that they’d pretty much have to hand over control of their Blink and access credentials to us. Whilst I’m happy to do that securely I can’t see many people wanting to do it, but if you do need something building to control your Blink then do get in touch!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.