Pages

Sunday, October 6, 2019

Cascading IFTTT actions

As much as I'm learning about IFTTT and it's flexibility, this comes with a cautionary tale.  It is possible to create a cascading chain of IFTTT actions that are not intended to fire in series.  It pays to review your current Applets to ensure this behavior is not happening.  Recently, I had such a situation and this post is meant to test it's resolution.

Managing Social Media Posts

In an effort to troubleshoot and see how far I can go to manage my social media, I delved into a trick I used to do with IFTTT, Blogger, Facebook, Twitter, and LinkedIn.  A while ago, I set up some Applets on IFTTT that fired when I updated this blog page.  What it was supposed to do was auto-publish the new blog post across Facebook, Twitter, and LinkedIn without my having to copy and paste the link on each service separately.  As of March 2019, LinkedIn changed their API and I was oblivious to this, or too busy to research how to correct it.  As I don't blog much (thanks Sharon for pointing THAT one out...), I haven't been bothered by it much.  Today, after being excited enough to post a very extensive blog post, I saw the IFTTT fire, but it only reached Twitter and Facebook.  It was then I found that LinkedIn was broken.  I still have the connection in place though between Twitter and LinkedIn, so anything I post should go to both places, however, I found that now I have to add an extra step.  I have just updated my Applet on IFTTT and this post will test whether adding the hashtag will work to cascade the post across all three again.

Update:  Well, it didn't work.  LinkedIn is being very obstinate about automatic posting.  In addition, they removed the ability to link your account with Blogger (at least for non-Premium accounts), therefore, my workaround is to add my Blog as a publication under my LinkedIn profile and hope people scroll down that far to see it.

Smarthome Connectivity

Since moving into the new house, I've become acutely aware of how Siri, Google, and Alexa are important from the standpoint of a person with vision difficulties.  At first, it was simply a means to engage the time by reading audiobooks and providing the ability to access web searches without the need to be able to see the computer screen.  This has ultimately evolved into a search into enabling such a person to have more control over a world that is becoming ever darker in their eyes.

First a bit of a backstory for those that are not aware.  A very special person in my life is slowly losing his sight, and about two years ago the first signs that he needed help started to appear.  My wife and I got a call that he attempted to drive home after visiting the eye doctor and realized that he was unable to do so safely.  We found him parked on a median in the middle of the road.  Shortly thereafter, he announced that he was no longer capable of driving himself.  This was an extra burden on our already hectic lives, but we did so more than willingly, but a side conversation between the wife and I had to occur.  We needed to discuss the feasibility of continuing to care for him in his home or seek an alternate residential situation for him.

This is one of the hardest conversations to have with the person involved as many children of aging parents will tell you.  We scheduled the conversation and I went to look for potential houses that would be able to fit all of us under the same roof.  This was a very tall order as the wife and I already had plans to find a piece of property that was large enough that our children could also fall back on if they needed to in their young adult years.  We were both wanting several acres of property with trees, but for someone with failing sight, the gradient terrain had to be considered.  I actually found a potential property prior to our conversation and pulled some numbers.

The conversation went far better than we both had thought, and the decision was made to have my father and us source a property together.  I'll skip the next few months of financial conversations, moving, and the like as they aren't relevant nor do they add to the intent of this post.  It is now about a year since the move and my father currently has both Google and Alexa on the table that he sits at every day.  His enjoyment is visible to us as they allow him to interact with the wider world, enjoy sci-fi and fantasy audiobooks (a long-standing hobby of his), and even give us a phone call without needing to manually dial a number on a phone.

One of the pain points of the property though is it came with a private gatehouse that has caused me some grief in setting up with an intercom/gate opener.  There really is only one manufacturer for these devices, because Craftsman and Liftmaster are both owned by Chamberlain.  All of these devices are becoming connected through their technology called "MyQ" and my new gate opener came with this technology.  At the original install, I did not hook it up as I view Internet-connected devices as inherently vulnerable, but my fathers' situation could not be ignored.

The manual intercom system that came with the house was a dinosaur, being some 34 years old, and badly needed replacement.  I sourced and purchased an updated system that added two capabilities to the old one, that of video and RFID entry.  The day I installed that system and made it work was very cool.  Unfortunately, my father had trouble finding the button to open the gate as the touchscreen monitors inside no longer had the tactile feel of a push button.  It was then I realized that no modern closed-circuit system would work for him.

Then came the lightning.  During a heavy thunderstorm, a lightning bolt hit a tree outside the gatehouse and it took out a good bit of technology that I had installed into the house, including the brand new intercom system and gate opener.  I ordered replacement parts, and all but the doorbell on the gate were replaced.  The doorbell from downstairs was relocated to the gatehouse as it was still working so that we could return to functionality, but I was missing the front door and downstairs door doorbells.  Two months have gone by and the part I purchased to replace the failed doorbell has yet to come in from China (Thanks a lot Trump).  I'm now realizing that the tariffs have impacted me in a way I didn't expect. 

Along this journey, I decided to leverage the MyQ technology built into my gate opener and purchased a Liftmaster branded Internet Gateway and set that up.  I can now open my gate from my smartphone, which is good because several manual button openers have become lost.  This solved the problem for most of the family, and we had a temporary solution for my father of taping a paperclip to the interior monitors next to the gate button that he could feel, but I wasn't satisfied with this solution.  I wanted him to be able to open the gate by asking Google or Alexa to do it.

Here's the part of the story that gets technical and was frustrating for me to work out.  The MyQ app can integrate with Google but doesn't have the capability of issuing an open command from Google.  They state this is for security reasons, which is very confusing to me because their app can't be very much more secure.  I suppose, given the layout of most homes, having someone outside yelling "Google, open the door" IS a concern, but in my situation, the gatehouse is a good distance from the house, and that would be futile for someone to attempt. 

I started to explore the problem further and discovered that in addition to the integration with Google, MyQ also integrates with IFTTT.  This is interesting because IFTTT is extremely flexible and has lots of integrations with other smart home devices and systems.  As it turns out, IFTTT can integrate with both Alexa and Google as well as Samsung SmartThings.  SmartThings, in case you have been asleep or not aware, has an open API for development and a large contributing community.  In addition, one of those custom-built SmartApps integrates with MyQ.  (see https://github.com/brbeaird/SmartThings_MyQ).

The first time I visited that link, I came away with my head swimming.  I may be good with computers, but this was not an area that I had any experience with.  My experience lies with enterprise-level cloud computing platforms, not the lower end consumer stuff.  I shoved it into the back of my brain until I had a chance to dust it off and take a closer look.  Today was that day. 

I started by logging into all the relevant web portals and having them all side by side, MyQ, Google Assitant, Amazon skills, IFTTT, SmartThings, and several research windows and started digging.  I quickly realized that my phone was also necessary for some of the stuff and even employed the second computer in the process.  In reading through the article above, and doing a bit of other research as well as some intuition jumps myself, I finally arrived at a satisfactory solution, one that I do not believe is fully documented in a single place on the web.

So here goes.  Requirements/Steps:

1. Accounts for MyQ, Google, Amazon, IFTTT, and SmartThings
2. Integrations setup and functional for IFTTT to Google, Alexa, and SmartThings
3. (optional, but highly recommended) The Community Installer for SmartThings (located here: http://thingsthataresmart.wiki/index.php?title=Community_Installer_(Free_Marketplace))
4. The SmartThings_MyQ SmartApp added to SmartThings (located here: https://github.com/brbeaird/SmartThings_MyQ)
5. Creation of a virtual sensor in SmartThings using this guide:  https://community.smartthings.com/t/how-to-smartthings-myq-smartapp-using-myq-sensors-with-ifttt/149601
6.  IFTTT custom Applets for Google and Alexa (either or both, your choice)

Step 1:  If you are reading this, I would assume you can handle that first requirement on your own, so I'll leave that to you.  If you can't handle that, you really don't have any business doing this on your own, go grab the local techie down the street and hope they know better than you do.

Step 2:  Integration of the services can be frustrating from the MyQ side as the phone app seems to have a way to directly integrate with both Google and IFTTT, but in reality, all it does is open the partner app and leave you hanging.  Fortunately, you don't need to integrate MyQ with anything (even though I did and have left them in place).  The long and the short of it is with the direct MyQ integration, all you have the capability to do is check the status of the device and to close it, NOT open it.  What's more, in my case, I was not able to ever have Google recognize that I even had a device through that integration.  I called Chamberlain and they were also unable to help me get it visible, which I found quite odd.

In any case, handle the IFTTT integration from THEIR side with Google, Alexa, and SmartThings.  This integration is simple as of the time of this writing, you simply have to log in to the web portal, click Explore and search for the three services one at a time.  Under the search box will appear the public Connections that others have written and a Services tab.  Choose the services tab, then the service and follow the bouncing ball to log into the other service.  Google and Alexa are just that simple, SmartThings has an extra step once you log in.  It will bring up a window that will have you authorize the connected devices registered to your account.  For now, it should be blank or have devices that you don't want for this project, just skip it and come back later.

Step 3:  The Community Installer guide is well written and you will have no need to go into the Advanced Installation section. 

Step 4:  Once the Community Installer is installed, switch to the phone and download the "Classic" SmartThings app. This app, at the end of the day, isn't actually necessary beyond the addition of the SmartApp except for testing the SmartThings_MyQ SmartApp piece of the puzzle and will leave you with two apps that can then open your garage/gate from your phone without going through Google or Alexa.  The objective in this step is just to get the SmartThings_MyQ SmartApp functional within SmartThings.  Since I didn't find how to actually use this, I'll include a mini-guide here:

     4.1.  Open the Classic SmartThings app, go to Marketplace>My Apps> ST-Community-Installer
     4.2.  Set the IDE Login Account Type to whatever your login is (Samsung or SmartThings) and hit done.
     4.3.  Scroll all the way down and hit Installer Home, then login to the same account type that you identified in step 4.2
     4.4.  Search for and install the MyQ Lite SmartApp.  Under normal circumstances, you can accept the default choices during install
          4.4.1  TAKE NOTE:  You will be doing this step again to update this community app if you run into a problem in the future, so this is one argument for keeping the SmartThings Classic on your phone!!!

Step 5:  Add the Virtual Sensor.  Although the guide was written relatively recently, the SmartThings portal has changed and some steps are out of date.  For the most part, you can figure out the changes, so go ahead with Steps 1 and 2.  Step three of that guide will lead you down the wrong path though, as MyQ has pulled support for the closing function within IFTTT, so don't do that one.  Instead, skip down and do Step 4 and make sure that part works as laid out there.

Now you want to test the actual MyQ Garage Door Opener supplied by the MyQ Lite app added in Step 2 of the guide.  On your "My Home" in the SmartThings Classic app on your phone, you should have at least two devices, one labeled "DO NOT PRESS - something you typed" and one labeled whatever you're naming your devices in MyQ.  Click on the one from MyQ, a dashboard will open giving you the status of Closed and an Open and Close button.  Hit the Open button, then switch apps to the MyQ app*.  Without doing anything, you can watch the gate/garage open from the MyQ app.  If for whatever reason this isn't working, you've done something wrong when adding the virtual sensor or setting up the integration between MyQ and SmartThings.  Go back and check both of these and ensure they are set up correctly.  If the gate/garage opens, CONGRATULATIONS!  you can now move on to Step 6 and you are virtually home free now.

*Because the device in SmartThings is set to a virtualized sensor instead of the actual sensor from your gate/garage, it's not actually reporting real-time information and as long as you haven't set the "DO NOT PRESS - [whatever]" to "ON", it will report "Closed" in SmartThings, therefore, you have to switch apps to get real-time info from your device.

Step 6:  On to IFTTT:  While this is, by far, the simplest in execution, if you got tripped up on the last step, it will be very frustrating.  Step 3 of the last guide shows you to connect IFTTT to MyQ, but MyQ pulled support for the close actions within IFTTT.  Furthermore, due to a strangeness that I ran into as described above, setting the trigger to MyQ resulted in my not finding a door to trigger!  Here's what I did (and tested successfully).  Keep in mind that my ONLY goal was to set up Google and Alexa to OPEN my gate by voice command and I wasn't interested in any other way to connect this string together.  Having said that, the method described below is probably faulty in some way I haven't discovered yet, but it works and I'm happy with the result.

I built two applets, one for Google, and one for Alexa, they are essentially identical except for the phrase needed to trigger the action.  This is not by design, but rather because Alexa requires an extra word in order to functionally work with IFTTT.  Before building these applets though, you have to edit the connection of IFTTT and SmartThings.  From IFTTT (web version) do:

     6.1  Click on your portrait, go to My Services>SmartThings
     6.2  In the upper right, there should be a Settings button (unless they change things, in which case, look around, it's going to be here somewhere as "Settings" or "Edit" or three dots, or a gear icon...you get the idea), click THAT, then "EDIT" in the Account Info section.
     6.3  You will be taken to the SmartThings/IFTTT integration window you saw before way back in Step 2. (I told you we'd be back later :-), but this time, when you choose your Home, you will see devices, and it's asking for permission to action those devices, so put a checkmark in the box next to the device you just tested at the end of Step 5 and click Authorize.

Great, we are almost done here.  The actual setup of the IFTTT applets is extremely straightforward, just go to your portrait, got to Create, and put Alexa/Google in the search bar (THIS side) with "Say a specific phrase" trigger.  Then put SmartThings in the search bar (THAT side) with a "Switch on" action choosing the gate/garage device you just authorized.

I gave the primary phrase the same content for both Google and Alexa, but Alexa has to go through something else on the backside and doesn't allow for multiple phrases nor a customized confirmation response.  Therefore, I have to say "Alexa trigger open front gate" and she tells me that she is contacting IFTTT, but for Google, I can say "Google, open front gate", "Google, Open sesame" or "Google, Let me in" and she comes back with "Ok, I'm opening your front gate"  I like the way Google does this a lot better because it's much more natural...poor Alexa, you lose this round.

Got those built?  Great, as long as IFTTT recognized your gate/garage as setup in SmartThings, and you don't swallow your own tongue talking to your favorite device, your gate/garage door is going to open when you give it the voice command.  Have some fun, I know I did showing it to my wife and father.

NOTE:  Although I'd love to report that the gate/garage will open immediately, alas, there IS a slight delay while those four cloud services talk to each other and then back down to your device.  Give it some time, be patient, it's no worse than the actual MyQ app in response time, so no worries.  Happy trails!