How to Access Google Sheet Data from NodeRED
Note
These instructions assume that you already have NodeRED installed somewhere, and are able to access it.
What's Involved
You will be:
- Creating a Google Sheet with data that you want to be able to use in NodeRED
- Authorizing remote access to your worksheet.
- Configuring NodeRED to be able to grab your data.
Step 1: Authorizing Access of Google Sheets
If you don't already have a Google Cloud account (https://console.cloud.google.com) you'll need to establish an account. Once you are able to login to Google Cloud, you can proceed.
After logging into Google Cloud Console, if you don't already have a project created, you'll need to:
- Create a new project. If you do already have a project, select that project. I already have one named "Home Assistant" so I'll use that one.
- You should be looking at your Service Accounts page. Click CREATE SERVICE ACCOUNT.
- Enter a descriptive name here such as "NodeRED Google Sheets". Service Account ID field will auto-populate.
- If you want to describe what this is for, you can do so in the "Service account description" field.
- Click CREATE AND CONTINUE
- Ignore the next two steps and simply continue.
- Click on your newly created service.
- Click on the KEYS tab.
- Click ADD KEY --> Create New Key --> Select JSON.
- A file should automatically download with all of your credentials to your browser's default download location. Save this file.
Step 2: Installing GSheetAdvance in NodeRED.
- While in NodeRED, next to the Deploy button in the upper right corner, click the 3 bars to open the side menu.
- Select Manage Palette.
- In the Nodes tab, search for
gsheet
. If there are no results, switch to theInstall
tab. - Install the GSheetAdvance node (node-red-contrib-google-sheets-advance).
Step 3: Create a new Google Sheet and Share It
- Create a new Google Sheet (sheets.google.com)
- In the upper right-hand corner, Share the sheet.
- Under
General Access
selectanyone with the link
. - Copy the portion of the Google Sheets URL between the
/d/
and/edit
/ - Add some data to the cell A1 and B1 in your Google Sheet so there's something to read.
Step 4: Configure GSheetAdvance
- Drag an instance of GSheetAdvance to one of your flows, or a new flow.
- Double-click the node to open it.
- Where you see
Creds
andnone
, click the plus sign. - In the
Creds
field, paste the contents of the JSON file that you downloaded from Google Console. - Click Add.
- Choose your Method. In this case, go with "Get Cells" so you can practice grabbing data from your Google Sheet.
- In the
SpreadsheetID
field, paste the long string of characters you copied from your Google Sheet. Go back to Step 3 if you forgot. - In the cells field, assuming you didn't label your first tab in Google Sheets, enter exactly what you see here:
Sheet1!A1:B1
, otherwise, replaceSheet1
with the name of your google sheet tab. You can use multiple tabs in a single document for different sets of data. - Name your node instance if you'd like.
- Click done.
Drop an inject node into your flow and connect it to the input of your GSheetAdvance node, and add a Debug node to the output. Set the Debug node to display the entire message object.
Deploy Your Flow
- Open the debug window in NodeRED.
- Click the inject button.
You will see a payload with an array containing your data. Each row will be an array, and each column will represent an item in that array. The first index position is the row, i.e. row 1 will be index 0, and the first column in the row will be the first index position under the row array, and so on.