Blink Arming - IFTT Alternative using API


#21

I tried the piston you kindly sent me but I don’t understand why it puts “,” in the variables. I noticed in the log that there is a “Homescreen” that I don’t understand what it refers to.

my synchronization module is called “giricri” and within the video cameras section the single device is called “camera”. i don’t see homescreen anywhere.

I do not know what to do! I tried andhe to enter “,” as the blink module name, but it doesn’t work


#22

It appears that the api address was cleared during the import. Shown as empty in the top image. Looking back at previous posts, the address in shown as empty there as well.

The initial POST request should be sending to the expression {api_start}api/v4/account/login . That post generates a auth token and pulls account information which is needed for further requests.

The GET request should be directed to the expression {alt_api_start}api/v3/accounts/{account_id}/homescreen. The pulls information from a portion of the api called the homescreen. This is where the module information is held.

The piston is attempting to create a comma seperated list in that variable. A list of module name and module ids.

If you are certain that the module name is giricri then that is what should have been entered in the original piston as the blinkNames.


#23

I give up! I’ve made a lot of attempts but it doesn’t work. You were very kind in trying to fix the problem.


#24

Having failed to get the initial code working I tried your Auth Test piston.
Here is the log
13/07/2021, 15:28:27 +136ms
+0ms ╔Received event [3 OGC].time = 1626186508610 with a delay of -1474ms
+43ms ║RunTime Analysis CS > 17ms > PS > 7ms > PE > 19ms > CE
+46ms ║Runtime (46869 bytes) successfully initialized in 7ms (v0.3.113.20210203) (44ms)
+46ms ║╔Execution stage started
+58ms ║║Calculating (string) Login: + (string) 408 >> (string) Login: 408
+61ms ║║Calculating (string) Login: 408 + (string) - >> (string) Login: 408 -
+64ms ║║Calculating (string) Login: 408 - + (string) false >> (string) Login: 408 - false
+66ms ║║Calculating (string) Login: 408 - false + (string) >> (string) Login: 408 - false
+69ms ║║Login: 408 - false
+70ms ║║Executed virtual command log (1ms)
+75ms ║║[:]
+76ms ║║Executed virtual command log (1ms)
+81ms ║║Executed virtual command setVariable (3ms)
+86ms ║║Executed virtual command setVariable (2ms)
+91ms ║║Executed virtual command setVariable (2ms)
+96ms ║║Calculating (string) https://rest- + (string) >> (string) https://rest-
+99ms ║║Calculating (string) https://rest- + (string) .immedia-semi.com/ >> (string) https://rest-.immedia-semi.com/
+102ms ║║Executed virtual command setVariable (2ms)
+106ms ║║Executed virtual command setVariable (2ms)
+110ms ║║Executed virtual command setVariable (2ms)
+112ms ║║Cancelling statement #3’s schedules…
+118ms ║║Calculating (string) https://rest-.immedia-semi.com/ + (string) api/v3/accounts/ >> (string) https://rest-.immedia-semi.com/api/v3/accounts/
+121ms ║║Calculating (string) https://rest-.immedia-semi.com/api/v3/accounts/ + (string) 0 >> (string) https://rest-.immedia-semi.com/api/v3/accounts/0
+123ms ║║Calculating (string) https://rest-.immedia-semi.com/api/v3/accounts/0 + (string) /homescreen >> (string) https://rest-.immedia-semi.com/api/v3/accounts/0/homescreen
+131ms ║║Calculating (string) { “TOKEN_AUTH” : " + (string) >> (string) { “TOKEN_AUTH” : "
+134ms ║║Calculating (string) { “TOKEN_AUTH” : " + (string) " } >> (string) { “TOKEN_AUTH” : “” }
+136ms ║║Sending external web request to: rest-.immedia-semi.com/api/v3/accounts/0/homescreen
+138ms ║║Error executing external web request: java.lang.SecurityException: Endpoint https://rest-.immedia-semi.com/api/v3/accounts/0/homescreen is blacklisted.
+139ms ║║Executed virtual command httpRequest (4ms)
+147ms ║║Calculating (string) Homescreen: + (string) 408 >> (string) Homescreen: 408
+149ms ║║Calculating (string) Homescreen: 408 + (string) - >> (string) Homescreen: 408 -
+152ms ║║Calculating (string) Homescreen: 408 - + (string) false >> (string) Homescreen: 408 - false
+154ms ║║Calculating (string) Homescreen: 408 - false + (string) >> (string) Homescreen: 408 - false
+157ms ║║Homescreen: 408 - false
+158ms ║║Executed virtual command log (1ms)
+163ms ║║[:]
+164ms ║║Executed virtual command log (1ms)
+170ms ║║Calculating (integer) 1 - (integer) 1 >> (integer) 0
+174ms ║║Cancelling statement #17’s schedules…
+179ms ║║Calculating (string) + (string) >> (string)
+182ms ║║Calculating (string) + (string) , >> (string) ,
+186ms ║║Executed virtual command setVariable (3ms)
+191ms ║║Calculating (string) + (string) >> (string)
+194ms ║║Calculating (string) + (string) , >> (string) ,
+198ms ║║Executed virtual command setVariable (3ms)
+200ms ║╚Execution stage complete. (154ms)
+201ms ╚Event processed successfully (201ms)
13/07/2021, 15:28:04 +794ms
+1ms ╔Received event [3 OGC].wc_async_reply = httpRequest with a delay of 0ms
+51ms ║RunTime Analysis CS > 25ms > PS > 8ms > PE > 18ms > CE
+54ms ║Runtime (46873 bytes) successfully initialized in 8ms (v0.3.113.20210203) (53ms)
+55ms ║╔Execution stage started
+55ms ║╚Execution stage complete. (1ms)
+56ms ╚Event processed successfully (56ms)
13/07/2021, 15:28:04 +383ms
+0ms ╔Received event [3 OGC].test = 1626186484382 with a delay of 0ms
+54ms ║RunTime Analysis CS > 23ms > PS > 9ms > PE > 23ms > CE
+57ms ║Runtime (46865 bytes) successfully initialized in 9ms (v0.3.113.20210203) (55ms)
+58ms ║╔Execution stage started
+62ms ║║Cancelling statement #61’s schedules…
+70ms ║║Calculating (string) https://rest-prod.immedia-semi.com/ + (string) api/v4/account/login >> (string) https://rest-prod.immedia-semi.com/api/v4/account/login
+100ms ║║Sending external web request to: rest-prod.immedia-semi.com/api/v4/account/login
+224ms ║║Executed virtual command httpRequest (149ms)
+226ms ║║Requesting a wake up for Tue, Jul 13 2021 @ 3:28:28 PM BST (in 24.0s)
+241ms ║╚Execution stage complete. (184ms)
+247ms ║Setting up scheduled job for Tue, Jul 13 2021 @ 3:28:28 PM BST (in 23s)
+280ms ╚Event processed successfully (280ms)

Also, without changes I sometimes get 426 as the statuscode.

I have checked the credentials are OK and the POST and GET requests are as per your code.

Help please as although I have successfully written many pistons this is my first attempt at HTTP requests.


#25

The authorization api on blink’s side has changed, now v5…I also updated the pistons based on some changes to the last webCore update realtive to http request handling…it is slightly complicated

I now have the following pistons:
One dedicated to each virtual switch that I use to arm (on) /disarm (off) the module
One Authorization Piston
One Homescreen Piston

The authorization piston run once a day to re-auth and generate an updated token, the token is then sent to the other pistons.
The homescreen piston is only used initially to pull the module id’s for each module (needed to send commands to blink via the virtual switch pistons).

Authorization Piston:


Notes:
For initial run, you can reduce the every 24 hours every 1 minute so you dont have to wait, just dont forget to change it back
email/password same as in blink app
unique_id can be any string (helps prevent the need to send pin number each time)
reauth (also to prevent the need to send pin number each time, set to false on first run, then true thereafter)
The executed pistons point to the homescreen piston and each virtual device piston, make sure to update those once you have created them all.
To send pin: enter the pin in the pin variable, save, execute test, edit piston and delete the pin string

Homescreen Piston:


Notes:
email/password same as in blink app
Piston is executed when the authorization piston runs
Generate a string list of names and associated module id (6 digit number) which is require to send commands

Module Arming Piston:


Notes:
Select Virtual Switch and enter corresponding module id from the homescreen piston
Triggered from changes in virtual switch state

Hopefully all that makes sense…I have sense rolledback the weird webcore update so I could possibly combine some of these but it is working for me as is.


#26

I’m stuck on running this the first time. Keep getting an Error Retrieving auth. Just to make sure i’m doing this correctly for the unique_id I can put any string in there? and for the Pin i put my Blink Pin and run a test then remove that?

This is what i get when i run the test.


#27

I know nothing of the specifics, but it looks to me that the timer block (the every), which runs every 23 hours, needs to have run once in order to initialise the alt_api_start variable which includes the URL for the HTTP request. To me the error message is suggesting that the variable is still null so that timer may not have run yet, or if it has something has gone wrong.


#28

Actually I looked at the code again, and some of the API url’s didn’t import. I need to rebuild those and then test this again.


#30

I don’t have those cameras, but I do have a question: is the example piston making local http POST requests? Direct from Smartthings to the blink system on your local network?

If so, the model could be utilized for virtually any local http communications. I’m thinking Bravia circa 2015, and linking this to Alexa routines: “alexa, turn on YouTube” would switch the tv to its Home Screen and choose the YouTube app. Or “alexa, put on hockey” could have the tv switch to its cable input, then have it send the correct channel to the cable box (the set has little infrared communicators that allows for this).


#31

This specific example goes to the Blink Cloud API however you can make local requests in the same manner all you need is the IP and knowledge of the individual API.


#32

This has been working for me for the past year yesterday i started having issues.

I found this error in the log

+101ms ║║Calculating (string) https://rest-prod.immedia-semi.com/ + (string) api/v5/account/login >> (string) *****s://rest-prod.immedia-semi.com/api/v5/account/login
+120ms ║║Sending external web request to: rest-prod.immedia-semi.com/api/v5/account/login
+144ms ║║Error executing external web request: groovyx.net.http.HttpResponseException: Bad Gateway
+146ms ║║Executed virtual command httpRequest (36ms)

any ideas?


#33

Seems there is an issue on the Blink side…there is a project on hubitat that is having the same issues.

Below is the thread if you are interested but that developers thought:
"Little further examination of the response behind the scenes... It appears to be referencing an error from cloudfront. When I combine that with the 502 message most of the information online appears geared around there being an SSL misconfiguration between the originating server and the cloudfront services that are used to help distribute it. So MAYBE there really is an error on their end that will be resolved? At this point I think I should "wait and see" a touch."


#34

Thanks for the info!


#35

Apparently Blink was blocking requests due to lack of/invalid User-Agent header field…add the following to the header field of all GET/POST requests

"User-Agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"


#36

Thanks for the information, I saw that in the Hubitat post yesterday. But was not really following what I needed to do. I’ll have to try to find some time this weekend to look at this more, not really good with API’s


#37

Can you offer any help on where I need to put the user agent string? I have tried to figure this out and have not been successful.


#38

When editing the GET/POST request task, at the bottom in the authorization header section.

Should look something like this:


#39

Thanks for the help this looks to be working again for now.