auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// 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)
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// 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
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// 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
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// 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
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// 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
auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
// 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
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]}}
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
.
Enter the name of the tab in the spreadsheet where you want to add data. The default name for a new sheet is Sheet1
.
async
(params, auths) => {
}
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
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]}}
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
.
Enter the name of the tab in the spreadsheet where you want to add data. The default name for a new sheet is Sheet1
.
async
(params, auths) => {
}
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