Blink Camera

I have been tinkering with our new Blink camera to see if I can access it from Python; possibliy to use it for some Image-classification testing. Meet Blinkpy.

!pip install -q blinkpy
import asyncio
import os.path
from aiohttp import ClientSession
from blinkpy.blinkpy import Blink
from blinkpy.auth import Auth
from blinkpy.helpers.util import json_load

async def inital_connect():
    blink = Blink(session=ClientSession())
    await blink.start()
    return blink

async def connect(credentials):
    blink = Blink()
    auth = Auth(await json_load(credentials))
    blink.auth = auth
    await blink.start()
    return blink

First time you use it, it will ask for credentials and an MFA code. When you have done this once and saved the credentials, you will not have to reenter them.

CREDENTIALS_FILE = "./blink.credentials.txt"
if not os.path.isfile("./blink.credentials.txt"):
    blink = await inital_connect()
    await blink.save(CREDENTIALS_PATH)
else:
    blink = await connect(CREDENTIALS_FILE)

Now you can access your cameras. Lets list them first:

for name, camera in blink.cameras.items():
    print(name)                   # Name of the camera
    print(camera.attributes)      # Print available attributes of camera

Let’s take a picture from one of the cameras and write it to a file.

camera = blink.cameras['Froschi']
await camera.snap_picture()
await blink.refresh()
await camera.image_to_file("img.jpg")

Let’s print the image.

from PIL import Image
pil_im = Image.open("img.jpg")
pil_im