# IF next week's forecast is clear → THEN schedule an activity

**URL:** <https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372>\
**Category:** General\
**Created:** [16 February 2023 05:20 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372 "2023-02-16T05:20:11Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![qdmt](https://community.apilio.com/user_avatar/community.apilio.com/qdmt/32/1442_2.png) [@qdmt](https://community.apilio.com/u/qdmt)\
**Post date:** [16 February 2023 05:20 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/1 "2023-02-16T05:20:11Z")

</div>

**Context**  
There was fantastic weather today despite it being February, a normally deep-winter month in my current location. I would have gone out cycling or jogging, but I had prior commitments to attend to. I am kicking myself because, well, I could have scheduled those commitments on other days had I known the weather was going to be great.

**Challenge**  
I am hoping to pull some weather forecast value, such as average, low, or high temperature (willing to accept any of the three), and if said value exceeds a certain threshold, then create either an iOS Calendar or iOS Reminder event.

**Complication**  
Weather Underground only provides UV index as a value that can be parameterized per se, and values such as temperature is an IFTTT Pro+ ($70/yr) feature. The price alone isn’t as much of the complication as the query itself - which has to be executed with actual code within the query/filter section.

**Question**  
Could Apilio be used, perhaps in conjunction with Pipedream + OpenWeather API to accomplish this goal?

---

<div class="post-metadata">

**Author:** ![pebneter](https://community.apilio.com/user_avatar/community.apilio.com/pebneter/32/56_2.png) [@pebneter](https://community.apilio.com/u/pebneter)\
**Post date:** [16 February 2023 07:10 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/2 "2023-02-16T07:10:31Z")

</div>

Hi @qdmt,

how much days in advance do you need to have the reminder?  
The IFTTT weather applet gives you only tomorrows forecast.  
[https://ifttt.com/weather/triggers/tomorrows\_weather\_at\_time](https://ifttt.com/weather/triggers/tomorrows_weather_at_time)  
If that is enough, you can forward one or multiple forecast values to Apilio and trigger logic based on them.  
There is also a service to create iOS calendar entries through IFTTT.

So given the restriction that it is only one day in advance, this is certainly doable.

---

<div class="post-metadata">

**Author:** ![DanT](https://community.apilio.com/user_avatar/community.apilio.com/dant/32/9_2.png) [@DanT](https://community.apilio.com/u/DanT)\
**Post date:** [16 February 2023 09:19 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/3 "2023-02-16T09:19:12Z")

</div>

Also, and I’m not saying this is relevant but might be an interesting condition for you, I use a service called [Forecast.Solar](https://forecast.solar/) which gives me what I find is a pretty reliable sunny weather forecast, down to 1hr resolution at your location. The output is in estimated solar power production so can easily be used for numeric comparisons.

---

<div class="post-metadata">

**Author:** ![qdmt](https://community.apilio.com/user_avatar/community.apilio.com/qdmt/32/1442_2.png) [@qdmt](https://community.apilio.com/u/qdmt)\
**Post date:** [16 February 2023 13:13 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/4 "2023-02-16T13:13:44Z")

</div>

Thanks Pebneter - I was hoping for greater flexibility on the days out, say, at least 3+ days out. In practice, I might like it checking every 7 days for the next 7 days, and plot in the candidate calendar days.

That said, I can try testing and working with 1 day out with the IFTTT weather applet in the meantime.

---

<div class="post-metadata">

**Author:** ![qdmt](https://community.apilio.com/user_avatar/community.apilio.com/qdmt/32/1442_2.png) [@qdmt](https://community.apilio.com/u/qdmt)\
**Post date:** [16 February 2023 13:15 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/5 "2023-02-16T13:15:44Z")

</div>

Thanks Dan - that has the same impression I got from OpenWeather API. I will try digging into this further as well.

---

<div class="post-metadata">

**Author:** ![qdmt](https://community.apilio.com/user_avatar/community.apilio.com/qdmt/32/1442_2.png) [@qdmt](https://community.apilio.com/u/qdmt)\
**Post date:** [17 February 2023 22:53 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/6 "2023-02-17T22:53:53Z")

</div>

Apologies, @DanT or @pebneter, hoping to grab a hint about what to do next. This is what I’ve done so far:

**Core:**

- Activated pipedreams
- Activated OpenWeatherAPI, tested API key successfully for 7 day forecast (in both browser & pipedreams)
- Upgraded Apilio to enable API access

**Code:**  
_Node 1:_  
Setting aside for now the actual trigger (“Node 0”, which I presume I can trigger in IFTTT on a date/time basis to run weekly), in PipedIream, I have the following in my first node:

```auto
import { axios } from "@pipedream/platform"
export default defineComponent({
  props: {
    openweather_api: {
      type: "app",
      app: "openweather_api",
    }
  },
  async run({steps, $}) {
    return await axios($, {
      url: `https://api.openweathermap.org/data/3.0/onecall`,
      params: {
        lat: `mylat`,
        lon: 'mylon',
        cnt: '7',
        units: 'metric',
        appid: `${this.openweather_api.$auth.api_key}`,
      },
    })
  },
})

```

_Node 2:_  
This is followed by the Apilio node, which evaluates successfully once the account was upgraded:

```auto
import { axios } from "@pipedream/platform"
export default defineComponent({
  props: {
    apilio: {
      type: "app",
      app: "apilio",
    }
  },
  async run({steps, $}) {
    return await axios($, {
      url: `https://api.apilio.com/api/v1/boolean_variables`,
      auth: {
        username: `${this.apilio.$auth.username}`,
        password: `${this.apilio.$auth.password}`,
      },
    })
  },
})

```

**Back in Apilio** , I created:  
_SunInForecast_ - a boolean variable, currently set in False state  
_ExpectingNiceWeather_ - condition linked to SunInForecast, must be true  
_NotExpectingNiceWeather_ - condition linked to SunInForecast, must be false

I presume then back in Pipedreams, I have to create a PUT request to store each of the 7 days temperature? Recall that I seek to ultimately schedule potential days to go cycling if the temperature is “good” (say, the feels\_like parameter is \> 5 degrees celsius.) Alternatively, the date/time trigger could run on a daily basis and evaluate the 7th day out on a rolling basis (e.g., each day, check the 7th day out - so each day is evaluated on its own as opposed to analyzing 7 days at a time.)

Here’s an example response from OpenWeather evaluated via Pipedreams:

```auto
steps.code{1}

$return_value{8}

lat:mylat

lon:-mylon

timezone:`mytimezone`

timezone_offset:-99999

current{15}

dt:16766734234529

sunrise:167234234024

sunset:234234

temp:5.38

feels_like:12.38

pressure:1212

humidity:12

dew_point:-5.00

uvi:0

clouds:30

-more-

minutely[61]

hourly[48]

daily[8]

0{20}

1{18}

2{18}

3{18}

4{18}

5{19}

dt:12312312

sunrise:123123123

sunset:123123

moonrise:12312312312

moonset:1671232320

moon_phase:0.06
temp{3}

feels_like{6}

pressure:1212

humidity:23

```

---

<div class="post-metadata">

**Author:** ![DanT](https://community.apilio.com/user_avatar/community.apilio.com/dant/32/9_2.png) [@DanT](https://community.apilio.com/u/DanT)\
**Post date:** [18 February 2023 08:31 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/7 "2023-02-18T08:31:58Z")

</div>

Wow looks great but I think @pebneter is best qualified to help with this.

---

<div class="post-metadata">

**Author:** ![qdmt](https://community.apilio.com/user_avatar/community.apilio.com/qdmt/32/1442_2.png) [@qdmt](https://community.apilio.com/u/qdmt)\
**Post date:** [18 February 2023 14:28 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/8 "2023-02-18T14:28:03Z")

</div>

Hah, thanks @DanT. The things I do on a Friday night 🕶

---

<div class="post-metadata">

**Author:** ![qdmt](https://community.apilio.com/user_avatar/community.apilio.com/qdmt/32/1442_2.png) [@qdmt](https://community.apilio.com/u/qdmt)\
**Post date:** [18 February 2023 15:44 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/9 "2023-02-18T15:44:16Z")

</div>

Just some update to my progress:

Back in Apilio, I created a numeric variable _feelslikevar_  
In Pipedream, I have an Apilio HTTP request configuration as follows:

- PUT
- [https://api.apilio.com/api/v1/numeric\_variables/UUID-of-feelslikevar](https://api.apilio.com/api/v1/numeric_variables/UUID-of-feelslikevar)
- Authorization via Apilio-Pipedream integration
- Headers:
- 
  - user-agent: pipedream/1

- 
  - Authorization: basic {{apilio.username}}.{{apilio.password}} (this is resolved automatically via the Pipedream/Apilio node)

- 
  - content-type: application/json

Now, when I try the following for params in Pipedream:  
Query Name: numeric\_variable  
Query Value: {{steps.code.$return\_value.daily[7].feels\_like.morn}}

Result: error 500

If I change Query Name to feelslikevar, I get error 400:  
_param is missing or the value is empty: numeric\_variable_

---

<div class="post-metadata">

**Author:** ![pebneter](https://community.apilio.com/user_avatar/community.apilio.com/pebneter/32/56_2.png) [@pebneter](https://community.apilio.com/u/pebneter)\
**Post date:** [18 February 2023 16:05 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/10 "2023-02-18T16:05:15Z")

</div>

Hi @qdmt ,

in the logs I see an invalid request.  
I think the problem is that pipe dream builds the request in a wrong way.  
Remove the “Query Name”/“Query Value”, because it get’s appended to the URL.  
But you need to specify a body content as JSON like this:  
`{"numeric_variable": {"value": 5}}`

I guess you found the link to the API spec?

> **[Apilio REST API](https://documenter.getpostman.com/view/13480928/TzCHAVD2#f3075534-42b7-4d76-8de4-e95c78be85a0)**
>
> The API is a REST oriented interface to retrieve various states and update existing objects.
> 
> This API allows you to:
> \- Get and update values of variables
> \- Get details and the current evaluation value of conditions
> \- Trigger Logicblock evaluations
> \-...

---

<div class="post-metadata">

**Author:** ![pebneter](https://community.apilio.com/user_avatar/community.apilio.com/pebneter/32/56_2.png) [@pebneter](https://community.apilio.com/u/pebneter)\
**Post date:** [18 February 2023 16:07 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/11 "2023-02-18T16:07:11Z")

</div>

Btw. you could also use the webhooks feature instead of the REST API - maybe it is a bit easier to implement in Pipedream: [How to use webhooks to update variables and trigger logicblocks in Apilio](https://community.apilio.com/t/how-to-use-webhooks-to-update-variables-and-trigger-logicblocks-in-apilio/1607)

---

<div class="post-metadata">

**Author:** ![qdmt](https://community.apilio.com/user_avatar/community.apilio.com/qdmt/32/1442_2.png) [@qdmt](https://community.apilio.com/u/qdmt)\
**Post date:** [18 February 2023 16:50 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/12 "2023-02-18T16:50:10Z")

</div>

Thanks very much, @pebneter. Yes, I do have the Apilio REST api spec open that I’m trying to get Pipedream to mimic as closely as possible.

With your advice, I am getting closer:  
Putting the following test value of 5 in the body works:  
{“numeric\_variable”: {“value”: 5}}

But putting the path of the OpenWeatherAPI value per below evaluates to a param is missing or value is empty 400 error.  
{“numeric\_variable”: {“value”: {{steps.code.$return\_value.daily[7].feels\_like.morn}}}}

---

<div class="post-metadata">

**Author:** ![pebneter](https://community.apilio.com/user_avatar/community.apilio.com/pebneter/32/56_2.png) [@pebneter](https://community.apilio.com/u/pebneter)\
**Post date:** [19 February 2023 18:59 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/13 "2023-02-19T18:59:40Z")

</div>

I found one request in the logs that looks like this:

` [2023-02-18T23:12:57.339677 #2] INFO -- : method=PUT path=/api/v1/numeric_variables/cf591dd----------4849dd format=html controller=Api::V1::NumericVariablesController action=update status=400 duration=20.63 view=0.21 db=9.54 params={"_json"=>"JSON.stringify({\"numeric_variable\": {\"value\": -16.89})`  
I think there are extra curly brackets around the value that should not be there?

---

<div class="post-metadata">

**Author:** ![qdmt](https://community.apilio.com/user_avatar/community.apilio.com/qdmt/32/1442_2.png) [@qdmt](https://community.apilio.com/u/qdmt)\
**Post date:** [20 February 2023 05:54 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/14 "2023-02-20T05:54:07Z")

</div>

Just figured it out. There were all sorts of issues and was just about to give up in favour of the webhook approach, but went through line by line and landed at this piece that successfully updates the numeric variable on Apilio side.

```auto
import {axios} from "@pipedream/platform";

export default defineComponent({
  async run({ steps, $ }) {
    const feelslikeresponse =
      steps.OpenWeatherAPI.$return_value.daily[7].feels_like.morn;

    let data = JSON.stringify({
      "numeric_variable":{
        "value":feelslikeresponse
      }
    })

    const { config } = await axios($,{
      method: "put",
      url: "(myUUID)",
      headers: {
        "Content-Type": "application/json",
        Authorization:
          "Basic (headercode)",
      },
      data : data
    });
       return feelslikeresponse;
  },
});

```

But not in the clear just yet…now on to the fun logic building on Apilio to actually act on the numeric variable update 🙂

---

<div class="post-metadata">

**Author:** ![pebneter](https://community.apilio.com/user_avatar/community.apilio.com/pebneter/32/56_2.png) [@pebneter](https://community.apilio.com/u/pebneter)\
**Post date:** [20 February 2023 06:23 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/15 "2023-02-20T06:23:37Z")

</div>

This is great!  
Thanks for sharing your solution. 👏

---

<div class="post-metadata">

**Author:** ![qdmt](https://community.apilio.com/user_avatar/community.apilio.com/qdmt/32/1442_2.png) [@qdmt](https://community.apilio.com/u/qdmt)\
**Post date:** [20 February 2023 08:00 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/16 "2023-02-20T08:00:44Z")

</div>

Appreciate the help! Tested it through IFTTT & logic evaluation worked great. Thanks again. I will post a full write up & guide on the Use Case forum.

---

<div class="post-metadata">

**Author:** ![pebneter](https://community.apilio.com/user_avatar/community.apilio.com/pebneter/32/56_2.png) [@pebneter](https://community.apilio.com/u/pebneter)\
**Post date:** [20 February 2023 16:36 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/17 "2023-02-20T16:36:36Z")

</div>

Awesome - looking forward to it!

---

<div class="post-metadata">

**Author:** ![DanT](https://community.apilio.com/user_avatar/community.apilio.com/dant/32/9_2.png) [@DanT](https://community.apilio.com/u/DanT)\
**Post date:** [21 February 2023 10:14 UTC](https://community.apilio.com/t/if-next-weeks-forecast-is-clear-then-schedule-an-activity/2372/18 "2023-02-21T10:14:23Z")

</div>

well done for persevering, it’s always worth the learning curve in the end (if it works) ; )
