Blink Camera support

Since it seems like most people have examples using curl (which I have never used before now) I tried using it to see what happens then I felt I would be able to make the driver replicate it. I already had the portion to request the PIN working, so I started with a curl command to do the equivalent figuring that once I had one figured out, the other should be similar...

I have replaced any "identifying" information in the below examples with variable names.

This will successfully trigger a PIN request:

curl --request POST --url https://rest-prod.immedia-semi.com/api/v4/account/login --header "content-type: application/json" --data "{'unique_id': '${ UNIQUE ID HERE }', 'password':'${ PASSWORD }','email':'${ EMAIL }'}"

However, the huge number of variants submitting the PIN verification are failing (either Unauthorized Access 101, or more typically an Invalid PIN with code 1621 response). Any idea on the correct structure of the curl for that part? I have tried 15 different variants so at this point I figure it is just something simple and I need a different pair of eyes to look at it. Here is a sample of one (that failed) that I had the most hope for:

curl --request POST --url https://rest-prod.immedia-semi.com/api/v4/account/${ ACCT# }/client/${ CLIENT# }/pin/verify --header "content-type: application/json" --header "token-auth:${ TOKEN }" --data '{"pin":"${ PIN }"}'
1 Like

It would be nice to get the actual motion outputs directly, instead of having to bounce them through Alexa.

Even nicer would be the ability to get the temperature and the light level from them.

1 Like

I have created some rough examples using my old TP-Link cloud device as a template. It may be more familiar.

def getTokenExample(eMail, password) {
	def data = [
		unique_id: "00000000-0000-0000-0000-000000000000",
		email: "${eMail}",
 		password: "${password}"
	]
	def params = [
		uri: "https://rest-prod.immedia-semi.com/api/v4/account/login",
		contentType: 'application/json',
		headers: ['Accept':'application/json; version=1, */*; q=0.01'],
		body : new groovy.json.JsonBuilder(data).toString()
	]
	httpPostJson(params) {resp ->		//	Can also try httpPost
		log.trace resp.status
		log.trace resp.data
		//	if successful, the token would be in the response text.  Example
		//	state.token = resp.data.result.token
		//	Region, Account, and Client should also be in the response somewhere.
		//	state.region = ...........
		//	state.account = ..............
		//	state.client = .........................
	}
}

def enterTokenExample() {
	//	Variables are in form ${variableName}
	def token = state.token	//	from getTokenExample
	def region = "enter region from the example"	//	REGION FROM EXAMPLE
	def account = "enter the account from the example"	//	ACCT from example
	def client = "enter client from the example"
	def data = [
		pin: "${PIN}"	//	FROM PHONE.
		//	This is a potenial error point.  The PIN is entered here as a string, does the app expect a number?
		//	if so, it would be pin: PIN
	]
	def params = [
		uri: "https://rest-${region}.immedia-semi.com/api/v4/account/${account}/client/${client}/pin/verify",
		contentType: 'application/json',
		headers: [token-auth: token],
		body : new groovy.json.JsonBuilder(data).toString()
	]
	httpPostJson(params) {resp ->		//	Can also try httpPost
		log.trace resp.status
		log.trace resp.data
	}
}

def fetchDevices() {
	//	Variables are in form ${variableName}
	def token = state.token	//	from getTokenExample
	def region = "enter region from the example"	//	REGION FROM EXAMPLE
	def account = "enter the account from the example"	//	ACCT from example
	def client = "enter client from the example"
	
	def params = [
		uri: "https://rest-${region}.immedia-semi.com/api/v3/accounts/${account}/homescreen",
		contentType: 'application/json',
		headers: [token-auth: token]
	]
	httpGet(params) {resp ->
		log.trace resp.status
		log.trace resp.data
	}
}
2 Likes

Welcome to the community!

You should be able get all these directly from the cloud. The latency for the motion detection will be dependent on how frequently you send the get command to the cloud. This latency will NOT be instantaneous. I can see ever 15 or 30 seconds, but more frequently may cause hub performance issues.

This is a designer issue. However, using Amazon is an alternate that would reduce Hubitat load for motion detection.

Dave

1 Like

Yes you can use motion sensors to trigger an Alexa routine but I can't see how that would enable the ability to arm or disarm blink without using IFTTT.

You create a virtual on-off switch. Publish to Amazon via the Amazon Echo Skill. In Amazon, you create two skills - arm and unarm that are triggered by the virtual device on-off attribute. When triggered, these would arm or disarm the device.

Motion is the reverse. You create skills based on motion active and inactive. They would trigger another switch that links to a Hubitat virtual device which would then trigger the motion. (this is all VERY analogous to the IFTTT method).

I do not see how to arm or disarm blink cameras within an Amazon echo routine. I do not think this is possible. Do you have an example you can show?

Edit : typos

You cannot set an action to arm or disarm blink systems in an Alexa Routine.

2 Likes

Not to argue. You see actual results. However, from the Amazon.com page below:
"Works with Alexa – View live streams, motion clips, arm and disarm your system, and set up smart reorders for batteries through select Alexa-enabled devices. " I would surely contact Blink support. They are surely falling short on their promise since Alexa Routines are one of the strengths of amazon connection.

You are correct. Wanted to understand @djgutheinz said it could be done. Really wish Amazon would allow.

Thanks. Getting lots of help, and I appreciate it... I just wish I understood what was going wrong better. Using your enterTokenExample as a test, I get an error in the def params, for the headers:
illegal colon after argument expression; solution: a complex label expression before a colon must be parenthesized @ line 321, column 29

Tried changing it to:

headers: "[ token-auth: ${ token }]",

This does not get a compile error, but results in an error in the log:
java.lang.ClassCastException: org.codehaus.groovy.runtime.GStringImpl cannot be cast to java.util.Map on line 326

Line 326 corresponds to:

httpPostJson(params) {resp -> 

As a related example, here is my latest Params line (this one gets a 408 - Request Timeout response):

Params = [ uri: "https://rest-${ state.Tier }.immedia-semi.com/api/v4/account/${ state.AccountID }/client/${ state.Client }/pin/verify", contentType: "application/json", headers: "[token-auth: ${ state.AuthToken }]", body: "{\"pin\":\"${ PIN }\"}" ]
1 Like

Try this:

headers: [(token-auth): state.AuthToken ]
Or
headers: [(token-auth): "${state.AuthToken}" ]

2 Likes

Thanks, but neither of those work. The problem then is that it indicates:
java.lang.NullPointerException: Cannot invoke method minus() on null object

BUT... What you folks were leading to made me stumble on the correct solution and I got a successful PIN validation! What that line should have been is:
headers: [ "token-auth": "${ state.AuthToken }" ]

So the now-working key line is:

Params = [ uri: "https://rest-${ state.Tier }.immedia-semi.com/api/v4/account/${ state.AccountID }/client/${ state.Client }/pin/verify", contentType: "application/json", headers: ["token-auth": "${ state.AuthToken }" ], body: "{\"pin\":\"${ PIN }\"}" ]

Seeing that verification was a nice boost in the morning here. Of course now I need to get to work, but I should be able to get some more done this evening. Sorry about the delay everyone! Have to add a lot of thank yous to this driver.

5 Likes

Thanks to all that have contributed to this so far.
It will be so nice to get a working solution for this technology that does not require third party assistance such as IFTTT.

3 Likes

I do not know how "rough" people want the driver when they start playing with it. Right now it can:

  1. Request an email with a PIN from Blink and then Verify that PIN once you enter it (this process should only really need to be done once unless the device is deleted or somehow botched up)
  2. Arm/disarm a specific system (or all for the account)
  3. Enable/disable motion detection on a specific camera (or all for the account)
  4. Get some general system information

Things it DOES NOT do that I am still working on (that people mentioned interest in):

  1. Any type of visual (video or still)
  2. Report motion detection (not sure how useful this will be as this is a POLLING method, not a notification like you get with your phone, and the polling interval is fairly long)
  3. Specific camera info (battery & temperature for example)
3 Likes

Well that is perfect for my current usage. I just want to be able to arm/disarm systems. :slight_smile: I currently have 3 systems, will I be able to arm/disarm them individually?

Many thanks for all your hard work.

Yup, arm/disarm is possible individually (you enter the NetworkID assigned to them by Blink... which is not the most obvious thing but as far as I know you cannot dynamically edit commands or preference settings).

If you leave it blank it sets them all.

So I may try to clean up some and get some more features working then post the "early" version in a new project thread tonight.

2 Likes

Sounds great. How do you find out the NetworkIDs, will this be a feature of the app or driver?

1 Like

Initial versions of the 2 required drivers are now posted in a separate thread:
[PROJECT] Driver for Blink API

As I mentioned, it is pretty rough still (I got some more working though).

@darren.rockach: The NetworkIDs & CameraIDs are found in the driver in a couple places:

  1. It should create State Variables named "Network" and "Camera" (and others) that each contain a list of the IDs for those devices in your account.
  2. Each child device is named with the ID as the number in the name.
  3. Each child device should have a State Variable "ID" within it.
  4. Each camera child device should have a State Variable "NetworkID" within it that has the Network it belongs to.

I will continue to watch this thread, but for changes/feature requests/bugs/whatnot around the new drivers, please post in the project thread.

3 Likes

You are freakin’ amazing! The setup and activation worked perfectly and I was able to delete my ifttt account :tada:

1 Like