Weather Workflow
@raymondcamden
code:
data:privatelast updated:3 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
active
last updated:-last event:-
steps.
checkweather
auth
to use OAuth tokens and API keys in code via theauths object
params
Type

Determines if you are checking the current temperature or weather conditions.

string ·params.type
Condition

Determines if the workflow continues. For temperature checks, any setting is ok, but most likely you will use less than or greater than. For weather checks, only "equals" makes sense.

string ·params.condition
Value

This is the actual value to use when checking. For temperatures it should be a number (temperature in Fahrenheit). For weather checks, the type of weather condition.

 
string ·params.value
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, params) => {
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
let check = params.type;
let condition = params.condition;
let value = params.value;
console.log('check', check, 'condition', condition, 'value', value);

if(check === 'temperature') {
  let temp = steps.trigger.event.observations.location[0].observation[0].temperature;
  //convert temp to F
  let tempF = Math.floor((temp * 9/5) + 32);
  value = parseInt(value, 10);
  if(condition === 'less than or equal' && tempF > value) $end('Temperature not low enough');  
  if(condition === 'greater than or equal' && tempF < value) $end('Temperature not high enough');  
  if(condition === 'equal' && tempF !== value) $end('Temperature not equal'); 
  // export the temp
  this.temperature = tempF;
} else {
  // assume condition is equal as nothing else makes sense
  let weather = steps.trigger.event.observations.location[0].observation[0].skyDescription.toLowerCase();
  // lowercase value too
  value == value.toLowerCase();
  if(value !== weather) $end(`Condition ${weather} not equal to ${value}`);
  // export the weather
  this.weather = weather;
}