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: https://github.com/fronzbot/blinkpy
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 \
https://rest.prod.immedia-semi.com/api/v2/login \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Host: prod.immedia-semi.com' \
-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' \
-F email=[EMAIL_THAT_YOU_USE_IN_THE_BLINK_APP]
Then you will need to get the NETWORK_ID and CAMERA_ID, to do that use this CURL:
curl -X GET \
https://rest-e001.immedia-semi.com/api/v3/accounts/[ACCOUNT_ID]/homescreen \
-H 'Host: prod.immedia-semi.com' \
-H 'TOKEN_AUTH: SECRET_TOKEN' \
-H 'cache-control: no-cache'
Now use that info in this CURL to Enable the camera:
curl -X POST https://rest-e001.immedia-semi.com/network/[NETWORK_ID]/camera/[CAMERA_ID]/enable -H 'Host: prod.immedia-semi.com' -H 'TOKEN_AUTH: [SECRET_TOKEN]' -H 'cache-control: no-cache'> /dev/null 2>&1
and this one to Disable the camenra:
curl -X POST https://rest-e001.immedia-semi.com/network/[NETWORK_ID]/camera/[CAMERA_ID]/disable -H 'Host: prod.immedia-semi.com' -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 ==
#!/bin/bash
curl -X POST https://rest-e001.immedia-semi.com/network/[NETWORK_ID]/camera/[CAMERA_ID]/disable -H 'Host: prod.immedia-semi.com' -H 'TOKEN_AUTH: SECRET_TOKEN' -H 'cache-control: no-cache'> /dev/null 2>&1
sleep 5s
curl -X POST https://rest-e001.immedia-semi.com/network/[NETWORK_ID]/camera/[CAMERA_ID]/disable -H 'Host: prod.immedia-semi.com' -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/disable_blink.sh",10000)
val results = executeCommandLine ("/srv/openhab2-conf/scripts/enable_blink.sh",10000)
And to finalize, here’s a little demo video showing this working: https://www.dropbox.com/s/1zdpgzhuihp6a4e/blink.mp4?dl=0
Enjoy and hope this helps someone.