Migrate Elder care app & Google sheets logger

Sure, no problem, we’re really close to making it work!

Nayelyz,

I started the server.js script with node server.js and started ngrok with ngrok http 3000.

Then went to Developer Workspace and created a project

I tried to deploy it but got errors in the node server.js terminal

wptracy@wptracy:~$ cd GoogleSheetsLogging/
wptracy@wptracy:~/GoogleSheetsLogging$ ls
'elder care app secrets.txt'   package.json        README.md
 node_modules                  package-lock.json   server.js
wptracy@wptracy:~/GoogleSheetsLogging$ node server.js 
Open: http://127.0.0.1:3000
2023-01-12T11:32:55.889Z warn: Unexpected CONFIRMATION request for app 7937a9ee-c1e0-4495-b3b1-423feb330839, received {"lifecycle":"CONFIRMATION","executionId":"63DE2707121F4DDEA005BB2193A1482A-FC7W","appId":"7937a9ee-c1e0-4495-b3b1-423feb330839","locale":"en","version":"0.1.0","confirmationData":{"appId":"7937a9ee-c1e0-4495-b3b1-423feb330839","confirmationUrl":"https://api.smartthings.com/apps/7937a9ee-c1e0-4495-b3b1-423feb330839/confirm-registration?token=eeaa3658-eee5-49cd-ae2e-99230cddb1c2"},"settings":{}}

So I opened the link https://api.smartthings.com/apps/7937a9ee-c1e0-4495-b3b1-423feb330839/confirm-registration?token=eeaa3658-eee5-49cd-ae2e-99230cddb1c2 in a browser and got {“targetUrl”:“https://e2ea-98-43-186-186.ngrok.io”}

Then I was able to deploy.

I opened the smartthings app on my Samsung and installed the App called Elder Care

I got these errors (see screen shots) but opened the smartapp Elder Care anyway and got the other screenshot that says it will never expire.

I checked my iPhone to view the smartapp but it’s not there. It’s like what I described earlier about a smartapp shows up on the iPhone but not the Samsung. This time it’s the other way around. I installed the app on the Samsung but it doesn’t show up on the iPhone. I’m logged in to the same account on both phones. What do I need to do to fix the problem of smatapps not showing up on both phones.

How do I configure the variables that are in the server.js. Do I need a config file populated with the variables like who to SMS if the smarapp triggers?

If so, how do I integrate the config file and how does the smartapp on the phone call the server.js on the raspberry pi.

Do I need the keep node server.js running all the time?

I don’t think I need ngrok in the picture now that the app is deployed via Developer Workspace.

I deployed the app to the Samsung, and I did all this work on my x64 ubuntu server, not the rasspberry pi.
I think I just need to copy the x64 ubuntu project folder to the raspberry pi and do the npm install and node server.js. Is that right?

Ooops. I opened the server.js and discovered that this is a googlesheetslogging script, not an Elder Care script. I guess I need to substitute the googleSheet key with my google sheet key, and maybe some other stuff like contact sensors … How did you get your script to log to your google sheet.

I have a google sheet url.

Do I just change this line in server.js and substitute AKfycb2C8Zo-MunAqjjh_Z9pm2E2bmRLy with my secret url key?

    section.textSetting('urlKey').defaultValue("AKfycbwkNjHobma8Z62C8Zo-MunAqjj2E2bmRLy...").required(true);


I killed the smartthing app on iPhone and Samsung and restarted them. Now they both show both smartapps.

But, now the Elder Care smartapp doesn’t work.

I opened my Developer Workspace and I see logging when I try to open the smartapp.

Jan 12 23 6:44:36.469
CONTROL_EVENT
{ "type": "CONTROL_EVENT", "data": "welcome", "lastEventId": "", "origin": "https://spigot-regional-useast2.api.smartthings.com" }
Jan 12 23 6:43:37.667
EXECUTION_RESULT_EVENT
{ "type": "EXECUTION_RESULT_EVENT", "data": "{\"eventTime\":0,\"eventType\":\"EXECUTION_RESULT_EVENT\",\"deviceEvent\":null,\"deviceLifecycleEvent\":null,\"deviceHealthEvent\":null,\"deviceCommandsEvent\":null,\"deviceJoinEvent\":null,\"deviceGroupEvent\":null,\"deviceGroupLifecycleEvent\":null,\"locationLifecycleEvent\":null,\"modeEvent\":null,\"timerEvent\":null,\"favoriteLifecycleEvent\":null,\"sceneLifecycleEvent\":null,\"securityArmStateEvent\":null,\"securityArmFailureEvent\":null,\"paidSubscriptionsEvent\":null,\"installedAppLifecycleEvent\":null,\"smartAppEvent\":null,\"smartAppDashboardCardEvent\":null,\"executionResultEvent\":{\"locationId\":\"883519c1-5d13-434b-a5a0-edf950787f3a\",\"appId\":\"7937a9ee-c1e0-4495-b3b1-423feb330839\",\"installedAppId\":\"705bae45-f8c6-4a3d-a2e5-6cade071b97b\",\"appType\":\"WEBHOOK_SMART_APP\",\"displayName\":\"Elder Care\",\"executionType\":\"CONFIGURATION\",\"statusCode\":200,\"reasonCode\":null,\"reasonMessage\":null,\"executionStartTime\":\"2023-01-12T13:43:37.242Z\",\"executionDuration\":14,\"time\":\"1970-01-01T00:00:00.00Z\",\"error\":{\"code\":\"ConstraintViolationError\",\"message\":\"The request is malformed.\",\"target\":\"\",\"details\":[{\"code\":\"BodyMalformedError\",\"message\":\"The request body is malformed and cannot be processed by server.\",\"target\":\"Root Object\",\"details\":[]}]},\"rateLimit\":{\"status\":\"UNDER\",\"current\":1,\"remaining\":299}},\"hubLifecycleEvent\":null,\"hubHealthEvent\":null,\"hubZwaveStatusEvent\":null,\"hubZwaveExceptionEvent\":null,\"hubZwaveS2AuthRequestEvent\":null,\"hubZwaveSecureJoinResultEvent\":null,\"ruleLifecycleEvent\":null,\"roomLifecycleEvent\":null,\"weatherEvent\":null,\"smartAppLifecycleEvent\":null,\"geoPlaceLifecycleEvent\":null,\"invitationLifecycleEvent\":null,\"deviceSubscriptionsEvent\":null,\"hubMatterDeviceRendezvousEvent\":null}", "lastEventId": "", "origin": "https://spigot-regional-useast2.api.smartthings.com" }
Jan 12 23 6:43:36.206
CONTROL_EVENT
{ "type": "CONTROL_EVENT", "data": "welcome", 

Here are screenshots from iPhone and Samsung


If you’re referring to the “Unexpected CONFIRMATION request” as an error, that is expected. Every time you change the SmartApp’s URL, you need to make this confirmation by copying the URL in the browser.

After that, you need to deploy to test from the Developer Workspace.

You must keep the NodeJS server and Ngrok working all the time, otherwise, your app won’t be reachable. ST sends the subscription events to the Ngrok URL you registered and your server needs to be active to process that request.
SmartApps don’t work locally, this means they are only executed on the PC or device you are running the server, it doesn’t get uploaded to ST or the Hub and you can’t do that manually.
“Deploy to test” basically puts the SmartApp available for installation in the ST app, nothing else.

What variables do you mean? Do you want to add more settings to the app so you can enter more information?
Also, as I mentioned to you in a DM, SmartApps cannot send SMS, only routines can.

What do you mean by an “Elder Care script”? I used the script shared in the original implementation: GitHub - loverso-smartthings/googleDocsLogging: SmartThings Google Sheets Logging
I just followed those instructions.
For the contact sensors, you can select them with a deviceSetting as shown in the example I shared above, you can select multiple devices in one, but, if you have more than 20 devices total (contact and motion sensors) and you want to log their activity in the Google sheet, then, there would be a problem.
SmartApps have a limit of 20 subscriptions, in that case, you should make a capabilitySubscription.

That was just for testing, the original SmartApp asked you to introduce the key in that setting. This means that, when you open the SmartApp, you need to type it in the setting that says “urlKey”.
image

Also, some of the screenshots you shared belong to my.smartthings.com, please, avoid using that page to install/see SmartApps. It should be done from the ST app directly.

which screen shots should I delete

Where did you show how to enter deviceSetting

In the sample, the first setting is of type deviceSetting:

In the SDK repo, you can find a doc on other types you can use:

I deleted them. So you can delete these now.

I’m not understanding. Can you give me an example of how to enter the devices that I want to log to google sheets.

Do you need a list of my devices?

The connection would be broken when the raspberry pi booted. This doesn’t sound like a manageable thing to do. There must be a better way.

ok, in the code I shared, you can see this line:

section.deviceSetting(‘conSensor’).capabilities([‘contactSensor’]).required(false);

What it does is that, when the app executes, it shows a field for you to select one device that has the capability “contactSensor”. If you add .multiple(true) as below, it will let you select more devices.

section.deviceSetting(‘conSensor’).capabilities([‘contactSensor’]).multiple(true).required(false);

Please, share how many devices you’re planning on selecting.

You need to make sure that if this happens, the server gets enabled again. It depends on you where to host it, each option will have its differences and special configuration needed to run a server like this.
I previously mentioned the option of AWS and shared the sample but it might be complex if you don’t have experience programming and using the terminal/console.

Nayelyz,

I started over with deleting the smarapp and creating a new one.
I registered it and deployed it, but it doesn’t show up on the iphone smartthings Automations.

I see live logging in the developer workspace:

Jan 14 23 4:55:38.041
CONTROL_EVENT
{ "type": "CONTROL_EVENT", "data": "welcome", "lastEventId": "", "origin": "https://spigot-regional-useast2.api.smartthings.com" }
Jan 14 23 4:55:04.138
CONTROL_EVENT
{ "type": "CONTROL_EVENT", "data": "welcome", "lastEventId": "", "origin": "https://spigot-regional-useast2.api.smartthings.com" }

The smartapp is not on the iPhone, and it’s not on the Samsung phone.

I don’t know if this has anything to do with it, but I got a notification to update my smartthings hub this AM, so I did.

I also power cycled the HUB. I still can’t put a SmartApp on the phone.

Here is the screenshot.

Where are you looking for the SmartApp, I mean in which menu?
I don’t know why this is happening, I don’t have this issue and other users haven’t report them either, so, please, verify everything is ok on your side.
You should be looking for it here:

The app being missing from the phone is not related to the Hub, so, this is not something that will help you with your SmartApp development/performance unless the devices you selected for the subscriptions are unresponsive.

Nayelyz,

Sorry. I was forgetting to do steps 2 and 3.

I got it deployed and then it asked me for the credentials. I used my google sheets, but an error.

https://docs.google.com/spreadsheets/d/--IS THIS THE CREDENTIAL I’M SUPPOSED TO USE?–/edit#gid=0

An unexpected error occurred
Sorry about that.
We have logged this error for support. If this error persists, email suupport @ with the Reference ID and Error Time included below.

1. Launch the SmartThings app. Your SmartThings app and Developer Workspace must be signed into the same account.
2. Navigate to the *Automations* tab, tap *+*, and tap *Add routine*.
3. Your SmartApp will be listed near the bottom in the *Discover* tab that appears after selecting *Add routine*.
4. Click on it and test its functionality.

Hi, @wptracy

Sorry for the delay

Where did you get asked for some credentials?
For the configuration of the SmartApp and the Google sheets, you need to check these instructions:

Have you followed the steps? In #15, it says which string you need to copy and use in the SmartApp.

The iPhone is what is asking me for credentials. When I click on the smartapp that I installed on the iPhone, it askes me for credentials.

I entered the long string of character like in step 15
“Extract URL key for your new webapp, it is between /s/ and /exec. `AKfycbzY2jj4l7RSpFYfN62xra0HmcXPQXAUI17z6KKHWiT3OYyhUC4”

Please, be more specific, it would be super helpful if you included screenshots.

Are those credentials part of the SmartApp or the mobile app?

Where did you enter the Key? in the code or in the field for this purpose in the SmartApp? Did you verify that the request is using the correct URL?

I’m afraid to use screenshots. You told me not to do that.

The credential I’m trying to enter is on the iPhone smartapp. It’s a popup window when I click on the smartapp.

I entered the key on the iPhone in the smartapp that’s on the iPhone. It’s the key that came from the Google sheets URL.

Ok, so, have you verified the request sent to save the data is correct? That is important to verify the functionality. What happens when you save the SmartApp and there’s an event in the device? Does it get registered in the sheet?

Also, about this, sorry for the confusion, what I meant before is to avoid using the other page to install SmartApps, not to share screenshots.