Difference between revisions of "My NextServiceMgr"

The Unofficial SmartThings Blog
Jump to navigation Jump to search
(Issue #5: I want to upgrade the code but I don't know how)
(Issue #14: My Next devices are not updating or my auth tokens are lost)
 
(One intermediate revision by the same user not shown)
Line 436: Line 436:
 
5. [Chrome] You will find `user_id` and `access_token`  in the response to the request.
 
5. [Chrome] You will find `user_id` and `access_token`  in the response to the request.
  
6. [Chrome->ST] ''MyNextManagerV2''- App settings: Copy over the Nest login information to the corresponding nest_* fields in App Settings (ST IDE) for MyNextManagerV2.
+
6. [Chrome->ST] ''MyNextManagerV2''- App settings/Settings section: Copy over the Nest login information to the corresponding nest_* fields in App Settings/Settings (ST IDE) for MyNextManagerV2.
  
 
FYI,the login info for Nest account users looks like the following:
 
FYI,the login info for Nest account users looks like the following:
Line 444: Line 444:
  
  
7. [ST IDE] ''MyNextManagerV2''- App settings: After copying and pasting the login info, press "update" at the bottom of the ST IDE to save your variables.
+
7. [ST IDE] ''MyNextManagerV2''- App settings/Settings: After copying and pasting the login info, press "update" at the bottom of the ST IDE to save your variables.
  
 
Do not copy the double quotes in the ST IDE variables.  
 
Do not copy the double quotes in the ST IDE variables.  
Line 450: Line 450:
 
'''To insert the Settings values - middle of the page'''
 
'''To insert the Settings values - middle of the page'''
  
See screenshot from the App Settings section in the IDE below
+
See screenshot from the App Settings/Settings section in the IDE below
  
 
[[File:Nest_Google_Settings_variables.png|1000px]]
 
[[File:Nest_Google_Settings_variables.png|1000px]]
Line 503: Line 503:
 
7. [Chrome] One network call (beginning with `iframerpc`) will appear in the Dev Tools window. Click on it.
 
7. [Chrome] One network call (beginning with `iframerpc`) will appear in the Dev Tools window. Click on it.
  
8. [Chrome] In the Headers tab, under General, copy the entire `Request URL` (beginning with `https://accounts.google.com`, ending with `nest.com`). This is your `"google_issue_token"` in the App settings of MyNextManagerV2.
+
8. [Chrome] In the Headers tab, under General, copy the entire `Request URL` (beginning with `https://accounts.google.com`, ending with `nest.com`). This is your `"google_issue_token_url"` in the App settings of MyNextManagerV2.
  
 
See screenshot below
 
See screenshot below
Line 522: Line 522:
  
  
12. [Chrome->ST IDE] This is your "cookie" in the App Settings section of ''MyNextManagerV2'' smartapp (ST IDE). In order to copy the whole cookie, you'd need to split it into different google_cookie_p* fields in the Settings section as the SmartThings platform doesn't support long text variables. If the text is too long, SmartThings will report an exception (500) when you try to save a too long cookie field.  
+
12. [Chrome->ST IDE] This is your "cookie" in the App Settings/Settings section of ''MyNextManagerV2'' smartapp (ST IDE). In order to copy the whole cookie, you'd need to split it into different google_cookie_p* fields in the Settings section as the SmartThings platform doesn't support long text variables. If the text is too long, SmartThings will report an exception (500) when you try to save a too long cookie field.  
  
 
'''To insert the Settings values - middle of the page'''
 
'''To insert the Settings values - middle of the page'''
Line 531: Line 531:
  
  
13. [Chrome->ST IDE]  ''MyNextManagerV2''-App Settings: Make sure that all your google_cookie_p* fields contain the whole cookie from Google.
+
13. [Chrome->ST IDE]  ''MyNextManagerV2''-App Settings/Settings: Make sure that all your google_cookie_p* fields contain the whole cookie from Google.
  
14. [ST IDE] ''MyNextManagerV2''-App Settings: After copying and pasting the login info, press "update" at the bottom of the ST IDE to save your variables.
+
14. [ST IDE] ''MyNextManagerV2''-App Settings/Settings: After copying and pasting the login info, press "update" at the bottom of the ST IDE to save your variables.
  
 
* And, then after doing the copy & paste, go back to the ''MyNextManagerV2'' smartapp under Automation/Smartapps in the ST classic mobile app to reset the Nest auth tokens (connection) by going through the flow by pressing "Next" at the upper right corner till "save".
 
* And, then after doing the copy & paste, go back to the ''MyNextManagerV2'' smartapp under Automation/Smartapps in the ST classic mobile app to reset the Nest auth tokens (connection) by going through the flow by pressing "Next" at the upper right corner till "save".

Latest revision as of 15:02, 20 May 2020



Category: My Apps

Author:Yves Racine

ST Community handle: http://community.smartthings.com/users/yvesracine/activity

Company Link: http://www.ecomatiqhomes.com#!home/mainPage



If you like MyNextServiceMgr and related Next devices, please support the developer by clicking on the paypal link below:

https://paypal.me/ecomatiqhomes



Summary

MyNextServiceMgr: the smartapp is the Service Manager for all Next devices (Tstat, Protects, Cams): it instantiates the Nest device(s) and polls them on a regular basis"

Supported Features

  • Multiple devices can be selected to be exposed to SmartThings.
  • Do a poll at regular intervals (input parameter)
  • Notify you if there is any issue with the ST/Nest connection (optional).
  • Can send summary reports via Ask Alexa and/or nofications about your Next devices' usage (weekly, daily).

Prerequisites

  • Nest devices fully operational and connected via wi-fi to Nest
 Please note that all Nest devices are supported except the Nest thermostat E in the UK (with the heat link) and the Nest Secure Alarm. The Nest 
 Hello only appears as a Nest Cam (not other special features).


  • SmartThings hub fully operational
  • Some ST basic skills to add custom DTH and smartapps (see troubleshooting section, item 1)
  • Use of the SmartThings classic mobile app for instantiation of the custom devices (only the basic attributes will display within the new Samsung Connect mobile app as ST is working on the required migration steps).
  • Nest setup completed for your Nest devices under your Nest Primary account (don't use any Nest secondary accounts for the integation with SmartThings!!).
  • Location set for your ST account under the ST classic mobile app

Under the ST classic mobile app, click on the 3-horizontal lines- "hamburger"- menu in the upper left corner, and then the "gear'" icon to review your location and save it. You can refer to the SmartThings' documentation for more details.

https://support.smartthings.com/hc/en-us/articles/205956850-How-to-edit-Location-settings

  • Determine your shard, please consult this thread:

https://community.smartthings.com/t/faq-how-to-find-out-what-shard-cloud-slice-ide-url-your-account-location-is-on/53923

Or the SmartThings documentation here for more details:

http://docs.smartthings.com/en/latest/publishing/index.html#ensure-proper-location

UI and integration setup workflow

MyNextManagerP1.pngMyNextManagerStruct.jpg MyNextManagerP6.pngMyNextManagerP7.png MyNextManagerV2 sensors.jpgMyNextManagerP9.png

MyNextManagerP10.png MyNextManagerP11.pngMyNextManagerP12.png MyNextManagerP13.png

Code location: https://github.com/yracine/device-type-myNext/tree/master/smartapps

Instructions for installation (readme): https://github.com/yracine/device-type-myNext/blob/master/README.md

Troubleshooting

See troubleshooting section under the different Next devices


.................................................................................................................................

Issue #1: I don't know how to create a custom smartapp

.................................................................................................................................

See the explanations of a fellow community member here:

http://community.smartthings.com/t/faq-an-overview-of-using-custom-code-in-smartthings/16772

http://thingsthataresmart.wiki/index.php?title=Using_Custom_Code

And, here are some basic explanations with screenshots.

N.B. To create a DTH (Device Type Handler), it's basically the same steps above, but you need to click on My Device Handlers in the upper menu of the IDE, copy and paste the code, hit the create button and after, save & publish.

  • a) Point your browser to you SmartThings IDE for your country (i.e. http://ide.smartthings.com or whatever your shard is, refer to the prerequisites at the readme) and Log In.

Loginscreen.jpg

  • b) Once you are logged in, find the My SmartApps link on the top of the page. Clicking My SmartApps will allow you to produce a new SmartApp.

MySmartApps.png

  • c) Find the button on this page labeled +New SmartApp and click it.

+NewSmartApp.png

  • d) Since you already have the code in your computer’s clipboard, find the tab along the top section called From Code. In the area provided, paste (typically CTRL+V) the code you copied from GitHub. Click Create in the bottom left corner of the page.

NewSmartAppCreate.png

  • e) This will bring up another page, with the code now formatted within the IDE. If the code was copied correctly, there are no other steps except to save and publish the code. In the upper right corner of the page, find and click Save. Now, click Publish (For Me), and you should receive a confirmation that the code has been published successfully.

SavePublish.png

  • f) To enable OAuth, first find and click the App Settings button in the upper right corner of the page.

To access the App Settings section

MyNextManagerV2 AppSettings.png

From here, find the OAuth section toward the bottom of the page.


OAuthBtn.png

  • g) Clicking the OAuth link will reveal a button labeled Enable OAuth in Smart App. Click this button. The screen will change, giving you a unique code for your Client ID and Client Secret. These are the foundations of the security of your app and should be kept secret. You do not need to memorize or write down these codes; nor do you need to add any other information to this page. OAuth simply needs to be enabled for

OAuth.jpg


For the steps required for the login info, please refer to the screenshots below:

https://thingsthataresmart.wiki/index.php?title=My_NextServiceMgr#Issue_.2314:_My_Next_devices_are_not_updating_or_my_auth_tokens_are_lost

.................................................................................................................................

Issue #2: I created the smartapp in the IDE, but I don't know where to execute it

.................................................................................................................................

For the initial setup, under the ST classic mobile app, click on the Marketspace item in the bottom menu, and then, on the smartapps link and finally, MyApps (last item in the list).

If you still do not see your smartapp, please make sure that you have published it in the IDE!


For any subsequent execution, under the ST classic mobile app, click on automations>smartapps in the bottom menu. The list of installed smartapps will then appear.


P.S. If you don't see your smartapp, it could be that you're not using the right shard for the installation. Refer to

https://community.smartthings.com/t/faq-how-to-find-out-what-shard-cloud-slice-ide-url-your-account-location-is-on/53923

Or the SmartThings documentation here:

http://docs.smartthings.com/en/latest/publishing/index.html#ensure-proper-location

.................................................................................................................................

Issue #3: java.lang.NullPointerException: Cannot get property 'X' on null object

.................................................................................................................................


Just update your smartapp by going through all the smartapp setup pages by pressing 'Next' till 'Done'.

The smartapp was recently modified to include some defensive code to ensure that the smartapp is rescheduled. This is intended to alleviate some of the ST scheduling issue as discussed in these threads:


http://community.smartthings.com/t/scheduler-and-polling-quits-after-some-minutes-hours-or-days/16997

http://community.smartthings.com/t/schedule-not-working/3895

http://community.smartthings.com/t/is-it-me-or-schedules-not-firing-this-evening/10176


.................................................................................................................................

Issue #4: java.util.concurrent.TimeoutException: Execution time exceeded 20 app execution seconds

.................................................................................................................................


ST has introduced some generic rate limiting rules for all smartapps and device handlers. For cloud-to-cloud integrations, these rate limiting constraints are sometimes too low, and this exception can be raised from time to time.

There are some threads about it in the ST community forum:

http://community.smartthings.com/t/rate-limiting-too-restrictive-max-execution-time-exceptions/17985

http://community.smartthings.com/t/execution-times-increasing/19979

http://community.smartthings.com/t/unschedule-api-execution-time-too-long/11232

.................................................................................................................................

Issue #5: I want to upgrade the code but I don't know how

.................................................................................................................................

To get the new minor releases, you just need to use the original sellfy download link that was sent to you when you made your contribution.

Most of the time (unless specified otherwise), you just need to copy and paste the smartapp's code from the zip file.

Click on the smartapp that you want to update in the IDE. Go to

https://graph.api.smartthings.com/ide/apps (or whatever your shard is).

Paste the code into the code window (and make sure to copy all the lines)

And save & publish.

The same principle applies for the DTHs (Device Type Handlers).


.................................................................................................................................

Issue #6 - My new Ask Alexa's Message Queues are not showing up in the smartapp

.................................................................................................................................


You'd need to execute the MyNextServiceMgr smartapp under Automation/Smartapps in the ST mobile app by doing "Next" till "Done" to subscribe to the new AskAlexaMQHandler. The new handler will then be able to process any Queue refresh value from Ask Alexa.


You can then go to the AskAlexa smartapp, and make any queue changes... The updated queue values will be then sent to the smartapp.

................................................................................................................................

Issue #7: I want to be notified of any exceptions coming from ST and/or Nest

.................................................................................................................................

If you want to be notified of any serious ST/Nest exceptions, you can set the following flag to true in MyNextServiceMgr(in Other Settings -last page):


   section("Handle/Notify any exception proactively [default=false, you will not receive any exception notification]") {
      "Handle exceptions proactively?"
   }


The smartapp will then send you notifications when exceptions occur.


.............................................................................................................................

Issue #8: There is a groovyx.net.http.HttpResponseException: Too Many Requests exception in my logs

.............................................................................................................................

There are also variants of this message for devices: "(...) Nest Throtting in progress (...)" in the list of Events or the logs (IDE).

There could be different reasons why you have this exception thrown by Nest.

  • 1) Not using the caching in the smartapp

If you disable the following option in the smartapp:

   section("To refresh your current structures, don't use the cache [default=cache is used for better performances") {	
       "use of cached structures including devices?"
   }        

This means that every request to Nest will be sent without using any caching. This could be an issue as indicated in 2).

  • 2) Polling interval is too agressive for your use cases

If your polling interval is 1-5 minutes, you may encounter this exception as Nest can throttle your requests when too many are sent in a given timeframe. Nest APIs have 1 call per minute and 10 PUTs per hour limitations.

You may then need to increase the polling interval to 5-10 minutes, especially if you have many Nest devices under your account.

Refer to the Nest doucmentation about the Nest rate limiting:

https://developers.nest.com/guides/api/data-rate-limits




.............................................................................................................................

Issue #9: I'd like to uninstall My Next devices

.................................................................................................................................

a) Like any SmartThings device, first you'd need to unselect My Next device(s) from all smartapps and/or routines (ex. Amazon echo).

If you have Amazon echo, you need to deactivate the automatic discovery of devices first (i.e., in the ST classic mobile app, 'Allow access to all Devices, Scenes and Routines' in the Amazon smartapp under Automation/smartapps), before trying to remove any devices.

To know which smartapps are using My Next devices, go to

https://graph.api.smartthings.com/device/list (or whathever your shard is)

or click on the smartapps tab on the device itself under the ST classic mobile app.

b) Click on each of My Next devices instantied under your ST account

And note all smartapps under the list "In Use By".

c) Then, you'd need to unselect the device(s) from the smartapps or routines using the ST mobile app.

d) Finally, you can remove the MyNextServiceMgr smartapp by pressing on the corresponding 'button' inside it.


If you have any delete issues, you can also delete the devices directly from the ST or Samsung mobile by clicking on the device, pressing the 'gear button (upper right), and then remove at the bottom.


.............................................................................................................................

Issue #10: I want detailed Logging/Notifications or I want to enable Ask Alexa Notifications

......................................................................................................................................

In order to have detailed Logging/Notifications, you'd need to do the following:

  • a) Notifications & Other Settings Setup> On the last setup page, set the following flag to true
   "Detailed Logging & Notifications?"
  • b) Set the filtering level (ERROR, WARNING, DEBUG, TRACE): the TRACE level is the more detailed tracing you can get.
   "log filtering [Level 1=ERROR only,2=<Level 1+WARNING>,3=<2+INFO>,4=<3+DEBUG>,5=<4+TRACE>]?",required:false, metadata: [values: [1,2,3,4,5]]


  • c) To receive push notifications, answer 'Yes' to the following input parameter
   "Send a push notification?", metadata: [values: ["Yes", "No"]]


  • d) To receive the notifications configured above through Ask Alexa, set the following flag to true


   "Ask Alexa verbal Notifications?"


This way, you will get the same level of notifications (ERROR, WARNING, DEBUG,TRACE) verbally via the Ask Alexa smartapp.



...............................................................................................................................

Issue #11: I cannot create any objects under the new Samsung app

.................................................................................................................................


No custom DTHs can be created under the new Samsung mobile app for the moment as indicated in the prerequisites. You'd need to use the ST classic app to execute MyNextManager in order to create the Next devices. After creating the devices, follow the steps indicated in the installation pdf file included in the zip to force a refresh of the cache in order to make them appear correctly in the new Samsung app.


...............................................................................................................................

Issue #13: Some of my devices under the new Samsung app are disconnected

.................................................................................................................................


If some of your Next devices are disconnected under the new Samsung app, you may have created many of the same devices by executing MyNextManager many times... Under the new Samsung mobile app, you then need to clean them up by pressing the "edit" button next to your location and removing them.


...............................................................................................................................


Issue #14: My Next devices are not updating or my auth tokens are lost

.................................................................................................................................


For your first setup or if some of your Next devices are not updating because you may have lost your auth tokens, please follow the steps below.


  • MAKE SURE TO get the right login info (a or b) as explained below, because if you are
   a) Nest Account user or 
   b) Google Account User (migrated Nest account to Google)
   the instructions set ARE NOT THE SAME
  • Log off first from any Nest active session
  • Start the Chrome browser in incognito mode or clear your cache first.
  • Please take note that, during the steps described below, you need to log in to home.nest.com in order to get the right login info!!



a) LOGIN INFO REQUIRED FOR NEST ACCOUNT Users (NOT migrated to a Google account)


Notes:

  • Once you log in to your Nest account as described in the steps below, please keep the connection active to avoid any disconnect in ST (do not log off, but you can close your browser and even turn off your desktop/mobile), and don't change your Nest account password or 2FA settings.
  • If you lose your auth tokens, then you'd need to redo the steps below and copy over the new nest access_token and user id back to the ST IDE. You can then reset the Nest connection by executing MyNextManagerV2 under Automation/Smartapps in the ST classic mobile app by pressing "Next" till "Save").
  • You don't need to re-install the devices, just reset the Nest connection.
  • Google recently introduced reCAPTCHA when logging to Nest. That means username and password cannot be used directly any more. Instead, you have to obtain `user_id ` and `access_token` for your account by logging in manually.


7 Steps (for nest users not migrated to a Google Account): ___________________________________________________________________


1. [Chrome] To do that, open `developer tools` in your Chrome browser, switch to the `Network` tab,

2. [Chrome] Hit preserve Logs in the Network tab

See screenshot below

HomeNestLogindeveloperMode.png

3. [Chrome] Log in to home.nest.com and look for the request similar to https://home.nest.com/session?_=157XXXXXX.

4. [Chrome] In the Network tab, you can use the filter "session" to get the exact info needed.

See screenshot below


HomeNestNetworkWindow.png


5. [Chrome] You will find `user_id` and `access_token` in the response to the request.

6. [Chrome->ST] MyNextManagerV2- App settings/Settings section: Copy over the Nest login information to the corresponding nest_* fields in App Settings/Settings (ST IDE) for MyNextManagerV2.

FYI,the login info for Nest account users looks like the following:

nest_user_id=4783742 nest_access_token=b.4783742.xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


7. [ST IDE] MyNextManagerV2- App settings/Settings: After copying and pasting the login info, press "update" at the bottom of the ST IDE to save your variables.

Do not copy the double quotes in the ST IDE variables.

To insert the Settings values - middle of the page

See screenshot from the App Settings/Settings section in the IDE below

Nest Google Settings variables.png





b) LOGIN INFO REQUIRED FOR GOOGLE ACCOUNT USERS (MIGRATED NEST USERS)



Notes:

  • Once you log in to your Nest account as described in the steps below, please keep the connection active to avoid any disconnect in ST (do not log off, but you can close your browser and even turn off your desktop/mobile), and don't change your Google account password or 2FA settings.
  • If you lose your auth tokens, then you'd need to redo the steps below and copy over the new google cookie and issue_token_url back to the ST IDE. You can then reset the Nest connection by executing MyNextManagerV2 under Automation/Smartapps in the ST classic mobile app by pressing "Next" till "Save").
  • You don't need to re-install the devices, just reset the Nest connection.


13 Steps (for nest users who have migrated to a Google Account): ___________________________________________________________________


The values of `issue_token` and `cookie` are specific to your Google Account. To get them, follow these steps (only needs to be done once, as long as you stay logged into your Google Account).

1. [Chrome] Open a Chrome browser tab in Incognito Mode (or clear your cache).

2. [Chrome] Open Developer Tools (View/Developer/Developer Tools).


To access the developer mode in the Chrome Browser at the home.nest.com login page

See screenshot below

HomeNestLogindeveloperMode.png

3. [Chrome] Click on 'Network' tab.

4. [Chrome] Make sure 'Preserve Log' is checked in the Network tab.

5. [Chrome] In the 'Filter' box, enter `issueToken`

6. [Chrome] Go to `home.nest.com`, and click 'Sign in with Google'. Log into your account.

7. [Chrome] One network call (beginning with `iframerpc`) will appear in the Dev Tools window. Click on it.

8. [Chrome] In the Headers tab, under General, copy the entire `Request URL` (beginning with `https://accounts.google.com`, ending with `nest.com`). This is your `"google_issue_token_url"` in the App settings of MyNextManagerV2.

See screenshot below

Home google login issue token.PNG


9. [Chrome] In the 'Filter' box, enter `oauth2/iframe` to get login information from Google/Nest under the Network window

10. [Chrome] Several network calls will appear in the Dev Tools window. Click on the last `iframe` call.

11.[Chrome] In the Headers tab, under Request Headers, copy the entire `cookie` (usually it starts with 'OCAK=...' or 'SID=...', but it can start with other values as well - **include the whole string which is several lines long and has many field/value pairs** - do not include the `cookie:` name). You can copy it in your preferred editor to split it in multiple fields of similar length.

See screenshot below

Home google login cookie.PNG


12. [Chrome->ST IDE] This is your "cookie" in the App Settings/Settings section of MyNextManagerV2 smartapp (ST IDE). In order to copy the whole cookie, you'd need to split it into different google_cookie_p* fields in the Settings section as the SmartThings platform doesn't support long text variables. If the text is too long, SmartThings will report an exception (500) when you try to save a too long cookie field.

To insert the Settings values - middle of the page

See screenshot from the App settings section in the IDE below

GoogleIDEAppSettings.PNG


13. [Chrome->ST IDE] MyNextManagerV2-App Settings/Settings: Make sure that all your google_cookie_p* fields contain the whole cookie from Google.

14. [ST IDE] MyNextManagerV2-App Settings/Settings: After copying and pasting the login info, press "update" at the bottom of the ST IDE to save your variables.

  • And, then after doing the copy & paste, go back to the MyNextManagerV2 smartapp under Automation/Smartapps in the ST classic mobile app to reset the Nest auth tokens (connection) by going through the flow by pressing "Next" at the upper right corner till "save".

For Google account users, please make sure of the following when doing the "copy & paste":

  • Make sure that the google cookie is split over several variable fields as it's too long and ST cannot handle it (error 500 thrown in the IDE). You can separate the cookie into different fields by using the already present semicolon (;) as a delimiter. Depending on the length of your cookie, it could take 3 to 6 cookie fields to copy the whole cookie from Google.