pipedreamint_RBS305
@dangermikeb
code:
data:privatelast updated:4 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 1,000,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
message_parse
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
}
25
// Purpose of this step is to convert the sensor message which is in 1 long String into an Array so that the readings can be easily accessed in subsequent steps
// the String looks like: 'Event: Air Temperature/Humidity, ATH Event: Humidity Report-on-Change Increase, Temperature: 18.4, Humidity: 90.5, Packet Counter: 7, Protocol Version: 1'
// the returned value will look like
// ATH Event: Temperature Report-on-Change Decrease
// Event: Air Temperature/Humidity
// Humidity: 12.8
// Packet Counter: 14
// Protocol Version: 1
//Temperature: -0.4
//
// Shout out to Sergey Batishchev in the Pipedream Slack channel for javascript conversion code AND the explanation
//


var str2 = steps.trigger.event.body.decoded.payload.Message;
console.dir(str2)
//var ouput = str2.split(",").map(  (pair) => pair.split(":")).reduce( (acc, pair) => (acc[pair[0].trim()] = pair[1].trim(), acc), {});
return(str2.split(",").map(  (pair) => pair.split(":")).reduce( (acc, pair) => (acc[pair[0].trim()] = pair[1].trim(), acc), {}))
//full string --> split to array of smaller "Event: Air Temperature/Humidity" 
//--> map to array of name/value pair arrays 
//--> reduce to single result object (and trim leading/trailing whitespaces) 
//console.dir(output)
steps.
calc_absolute_humidity
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
}
14
// this step calculates the Absolute Humidty based on the ambient temperature and relative humidity sensor readings
var  dewpoint = require('dewpoint');
 
// Dacula is 309m above sea level
var xdp = new dewpoint(309);
 
// t = temperature in °C, rh = rel. humidity in %
var y = xdp.Calc(steps.message_parse.$return_value.Temperature, steps.message_parse.$return_value.Humidity);
var x = y.x; // absolute humidity in g water per kg dry air
var dp = y.dp; // dew point temperature (in °C)
console.dir(x)
return x
steps.
calc_dewpoint
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
}
15
// this step calculates the dewpoint based on the ambient temperature and relative humidity sensor readings
// this step uses the same code as the previous step, but returns dewpoint instead of the absolute humidity
var  dewpoint = require('dewpoint');
 
// Dacula is 309m above sea level
var xdp = new dewpoint(309);
 
// t = temperature in °C, rh = rel. humidity in %
var y = xdp.Calc(steps.message_parse.$return_value.Temperature, steps.message_parse.$return_value.Humidity);
var x = y.x; // absolute humidity in g water per kg dry air
var dp = y.dp; // dew point temperature (in °C)
console.dir(dp)
return dp
steps.
C_to_F_ambientTemp
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
}
10
// This function converts the sensor's ambient temperature from degrees C to degrees F
const { toFahrenheitFmt } = require('celsius');
 
//var Ftemp = toFahrenheitFmt(event.body.decoded.payload.temp); // 97
var Ftemp = toFahrenheitFmt(steps.message_parse.$return_value.Temperature); // 97
console.dir(Ftemp)
return Ftemp
steps.
C_to_F_dewpoint
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
}
9
// This function converts the previously calculated dewpoint from degrees C to degrees F
const { toFahrenheitFmt } = require('celsius');
 
var dpF = toFahrenheitFmt(steps.calc_dewpoint.$return_value)
console.dir(dpF)
return dpF // return dewpoint converted to F
steps.
convert_out_of_unix_time
auth
to use OAuth tokens and API keys in code via theauths object
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps) => {
1
2
3
4
5
6
7
8
9
10
11
12
}
13
// the time information in the trigger event is in unix time. This steps converts from unix time to UTC time 
const UT = require("unixtimejs");

// get current unixtime:
//var ut = UT.now(); // eg: 1517433903
// unixtime -> UTCString
//var utcString = UT.toUTCString(event.body.reported_at); // "Wed, 31 Jan 2018 21:25:03 GMT"

var utcString = UT.toUTCString(event.body.reported_at/1000); // "Wed, 31 Jan 2018 21:25:03 GMT"
console.dir(utcString); 
return utcString
steps.
add_single_row_to_sheet
Add a single row of data to Google Sheets
auth
(auths.google_sheets)
params
Columns

Enter the data to insert into each column. Click + to add columns in structured mode, or turn structured mode off to enter array of column values as an expression — e.g., {{[1,2,3]}}

[0]:
 
array ·params.columns
Spreadsheet ID

The spreadsheet ID can be extracted from its URL. E.g., the spreadsheet ID in the URL docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 is abc1234567.

 
1mweDONSnGMtVV1j1-X3NXnkMMnre9IxlTwq8v-rys2E
string ·params.spreadsheetId
Sheet Name

Enter the name of the tab in the spreadsheet where you want to add data. The default name for a new sheet is Sheet1.

 
Sheet1
string ·params.sheetName
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
}
28
const { columns } = params

// validate input
if (!columns || !columns.length) {
  throw new Error("Please enter an array of elements in the `Columns` parameter above")
} else if (!Array.isArray(columns)) {
  throw new Error("Column data is not an array. Please enter an array of elements in the `Columns` parameter above.")
} else if (Array.isArray(columns[0])) {
  throw new Error("Column data is a multi-dimensional array. A one-dimensional is expected. If you're trying to send multiple rows to Google Sheets, search for the action to add multiple rows to Sheets, or try modifying the code for this step.")
}

const config = {
  method: "post",
  url: `https://sheets.googleapis.com/v4/spreadsheets/${params.spreadsheetId}/values/${params.sheetName}:append`,
  params: {
    includeValuesInResponse: true,
    valueInputOption: "USER_ENTERED"
  },
  headers: {
    Authorization: `Bearer ${auths.google_sheets.oauth_access_token}`,
  }, 
  data: {
   values: [columns],
  }
}
return (await require("@pipedreamhq/platform").axios(this, config)).updates
steps.
add_single_row_to_sheet_SensorCompare
Add a single row of data to Google Sheets
auth
(auths.google_sheets)
params
Columns

Enter the data to insert into each column. Click + to add columns in structured mode, or turn structured mode off to enter array of column values as an expression — e.g., {{[1,2,3]}}

[0]:
 
array ·params.columns
Spreadsheet ID

The spreadsheet ID can be extracted from its URL. E.g., the spreadsheet ID in the URL docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 is abc1234567.

 
1mweDONSnGMtVV1j1-X3NXnkMMnre9IxlTwq8v-rys2E
string ·params.spreadsheetId
Sheet Name

Enter the name of the tab in the spreadsheet where you want to add data. The default name for a new sheet is Sheet1.

 
Sheet1
string ·params.sheetName
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
}
28
const { columns } = params

// validate input
if (!columns || !columns.length) {
  throw new Error("Please enter an array of elements in the `Columns` parameter above")
} else if (!Array.isArray(columns)) {
  throw new Error("Column data is not an array. Please enter an array of elements in the `Columns` parameter above.")
} else if (Array.isArray(columns[0])) {
  throw new Error("Column data is a multi-dimensional array. A one-dimensional is expected. If you're trying to send multiple rows to Google Sheets, search for the action to add multiple rows to Sheets, or try modifying the code for this step.")
}

const config = {
  method: "post",
  url: `https://sheets.googleapis.com/v4/spreadsheets/${params.spreadsheetId}/values/${params.sheetName}:append`,
  params: {
    includeValuesInResponse: true,
    valueInputOption: "USER_ENTERED"
  },
  headers: {
    Authorization: `Bearer ${auths.google_sheets.oauth_access_token}`,
  }, 
  data: {
   values: [columns],
  }
}
return (await require("@pipedreamhq/platform").axios(this, config)).updates