diff --git a/Code.gs b/Code.gs new file mode 100644 index 0000000..4065392 --- /dev/null +++ b/Code.gs @@ -0,0 +1,48 @@ +function doGet(request) { + if(request != null) { + + var ss = SpreadsheetApp.openById("REPLACE ME WITH SPREADSHEET ID"); + var sheet = ss.getSheetByName("Sheet1"); + var firstRowRange = sheet.getRange(1, 1, 1, sheet.getLastColumn()); + + var sheetHeaders=firstRowRange.getValues(); + // columns start at one, but arrays start at 0, so this is the right number for inserting into an array that will be placed into the columns + var newColumnArrayCount=sheet.getLastColumn(); + + // initialize new row to be inserted before it gets filled with data + var newRow = new Array(sheetHeaders[0].length); + for(var x=0;x Make a Copy +step 2: Name the spreadsheet whatever you want -![alt tag](img/stgsl2.png) - -step 3: Name spreadsheet whatever you want - -![alt tag](img/stgsl3.png) - -step 4: Get your new spreadsheet id from URL,Example: +step 3: Get your new spreadsheet ID from URL. Example: https://docs.google.com/spreadsheets/d/169v40OsFOaGHO6uQwuuMx2hlWK-wvYCzrr93FAWivHk/edit#gid=0 example id is "169v40OsFOaGHO6uQwuuMx2hlWK-wvYCzrr93FAWivHk" ![alt tag](img/stgsl4.png) -step 5: Open script: Click Tools -> Script Editor +step 4: Add the single title "Time" in cell A1. You might consider selecting View -> Freeze -> 1 Row + +step 5: Open script: Click Tools -> Script Editor. ![alt tag](img/stgsl5.png) -Step 6: replace "REPLACE ME WITH SPREADSHEET ID" with sheet id from step 4 +Step 6a: Copy the contents of Code.gs to replace the stub "function myFunction" + +Step 6b: On line 4, Replace "REPLACE ME WITH SPREADSHEET ID" with sheet id from step 3 ![alt tag](img/stgsl6.png) +Step 6c: If you change the name of the sheet, update it on line 5. (defaults to "Sheet1"). + +Step 6d: Name the project (change "Untitiled project") + Step 7: Deploy webapp: Click Publish -> Deploy as web app... ![alt tag](img/stgsl7.png) @@ -49,7 +51,8 @@ ie: https://script.google.com/macros/s/AKfycbzY2jj4l7RSpFYfN62xra0HmcXPQXAUI17z6 Step 13 (Optional): Delete test data from spreadsheet, you should have new values in B1, C1, A2, B2, C2, delete all the test data -Step 14: In smartthings ide create new Smartapp From Code: https://github.com/cschwer/googleDocsLogging/blob/master/smartapps/cschwer/google-sheets-logging.src/google-sheets-logging.groovy +Step 14: In the SmartThings IDE, create a new Smartapp From Code using +smartapps/cschwer/google-sheets-logging.src/google-sheets-logging.groovy Step 15: In Smartthings App go to marketplace -> Smartapps -> My Apps -> Google Sheets Logging diff --git a/smartapps/cschwer/google-sheets-logging.src/google-sheets-logging.groovy b/smartapps/cschwer/google-sheets-logging.src/google-sheets-logging.groovy index d5c69ba..1771aef 100644 --- a/smartapps/cschwer/google-sheets-logging.src/google-sheets-logging.groovy +++ b/smartapps/cschwer/google-sheets-logging.src/google-sheets-logging.groovy @@ -209,7 +209,7 @@ private queueValue(evt, Closure convert) { log.debug "Logging to queue ${keyId} = ${value}" if( atomicState.queue == [:] ) { - def eventTime = URLEncoder.encode(evt.date.format( 'M-d-yyyy HH:mm:ss', location.timeZone )) + def eventTime = URLEncoder.encode(evt.date.format( 'yyyy-M-d HH:mm:ss', location.timeZone )) addToQueue("Time", eventTime) } addToQueue(keyId, value)