# Hourly rain forecast

**URL:** <https://community.homey.app/t/hourly-rain-forecast/109972>\
**Category:** Questions & Help\
**Tags:** homeyscript, advancedflow\
**Created:** [May 16, 2024, 12:31pm UTC](https://community.homey.app/t/hourly-rain-forecast/109972 "2024-05-16T12:31:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pairis](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/pairis/32/56439_2.png) [@Pairis](https://community.homey.app/u/Pairis)\
**Post date:** [May 16, 2024, 12:31pm UTC](https://community.homey.app/t/hourly-rain-forecast/109972/1 "2024-05-16T12:31:43Z")

</div>

Hi all,

I am looking for a way to automatically retract the sunscreen when it’s about to rain.

So, the flow would start when the screen is extracted and would check the weather for the next hour every 5 or 10 minutes or so.

Obviously, a rain sensor would be the best option, but as they are quite expensive I figured doing it through software would be the the next best thing 🙂.

I’ve used the KNMI app, but that is only giving me general day and later forecast information.

I need to get to the hourly info.

Therefore, I started to play with Homeyscript with the weerlive API.

That API is giving my the data that I need, but I script is new to me.

```auto
// Define the API key and location
const apiKey = '';
const location = '';

// Construct the API URL
const url = `https://weerlive.nl/api/weerlive_api_v2.php?key=${apiKey}&locatie=${location}`;

// Send a GET request using fetch
fetch(url)
  .then(response => {
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }
    return response.json(); // Parse the response as JSON
  })
  .then(data => {
    console.log(data); // Log the JSON response
    // Access specific data points to verify parsing
    const liveweer = data.liveweer[0];
    console.log(`Location: ${liveweer.plaats}`);
    console.log(`Temperature: ${liveweer.temp}°C`);
    console.log(`Summary: ${liveweer.samenv}`);
  })
  .catch(error => {
    console.error('There has been a problem with your fetch operation:', error);
  });

```

![Naamloos](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/7/67d08e9dcd1291ec8b5604198eac5e9afc44cbfb.png)

Keen to hear your advice!

Thanks!

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [May 16, 2024, 12:58pm UTC](https://community.homey.app/t/hourly-rain-forecast/109972/2 "2024-05-16T12:58:53Z")

</div>

To use that card’s output, you still have to declare the return value.  
(console.log is only for testing)  
Like shown in the demo code when you instert the card as new card.

 ![Screenshot_20240516-150514_Firefox](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/2/926a57df2b829e61379594e7da2f007834762564.jpeg)

BUT, your code does not return solely a number, but a string.  
So, you should use the “Run code and return text-tag” card instead.

The return value should be something like

```auto
return (`Location: ${liveweer.plaats}, Temperature: ${liveweer.temp}°C, Summary: ${liveweer.samenv}`);

```

But, probably your JSON paths aren’t correct yet, see my post quoting [Robert’s post from 2019](https://community.homey.app/t/get-value-from-homeyscript-in-a-variable-that-can-be-used-in-advanced-flow/107990/13)

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [May 16, 2024, 2:03pm UTC](https://community.homey.app/t/hourly-rain-forecast/109972/3 "2024-05-16T14:03:03Z")

</div>

Perhaps OpenWeatherMap is an option for you?  
You can add hourly forecast devices like this:

 ![grafik](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/5/a5db9262dd23af9901bf762c3025de82f90f9f9c.png) ![grafik](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/d/cd5db7c41f87e5ee0a130beeec2a94cdfe05204c.png)

And you can build a DIY sensor with a rain board and a simple binary sensor (like Aqara) - only as example:

 ![20240516_160010](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/8/c8c6e1abc37eb5a672a0b0554d8294102d745e33.jpeg)  
I use this to let Alexa speak if it starts to rain and the roof window is open.

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [May 16, 2024, 4:22pm UTC](https://community.homey.app/t/hourly-rain-forecast/109972/4 "2024-05-16T16:22:20Z")

</div>

Yeah, saw this as well

> [@Regensensor](https://community.homey.app/t/regensensor/13312/8):
>
> Raindrop sensor icm aqara water sensor

> [@Regensensor](https://community.homey.app/t/regensensor/13312/10):
>
> Printplaatjes zijn €0,55 pst via ome ali. Heb er al 5 besteld. Prima dus als ze het maar een jaartje uithouden.

---

<div class="post-metadata">

**Author:** ![Henk\_Bartels](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/henk_bartels/32/12762_2.png) [@Henk\_Bartels](https://community.homey.app/u/Henk_Bartels)\
**Post date:** [May 16, 2024, 6:40pm UTC](https://community.homey.app/t/hourly-rain-forecast/109972/5 "2024-05-16T18:40:35Z")

</div>

If you live in the Netherlands or Belgium u can also use the app ‘Buienradar’.

---

<div class="post-metadata">

**Author:** ![Rogier\_Verheugen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rogier_verheugen/32/77406_2.png) [@Rogier\_Verheugen](https://community.homey.app/u/Rogier_Verheugen)\
**Post date:** [May 16, 2024, 6:41pm UTC](https://community.homey.app/t/hourly-rain-forecast/109972/6 "2024-05-16T18:41:58Z")

</div>

![Buienradar](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/8/9897260c1a1783143b9df55d2be048460d9b18ee.png)

Does this work for you? Everytime I’m suprised how accurated the ‘Buienradar’ app is. In the settings of the app I have set my home address.

---

<div class="post-metadata">

**Author:** ![Pairis](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/pairis/32/56439_2.png) [@Pairis](https://community.homey.app/u/Pairis)\
**Post date:** [May 16, 2024, 7:09pm UTC](https://community.homey.app/t/hourly-rain-forecast/109972/7 "2024-05-16T19:09:21Z")

</div>

> [@Henk\_Bartels](#):
>
> If you live in the Netherlands or Belgium u can also use the app ‘Buienradar’.

Yes, I did not know!

> [@Rogier\_Verheugen](#):
>
> Does this work for you?

Very interesting @Rogier_Verheugen! Will definitely use this as inspiration!

Also really like the PiPup step!!

Thanks!!

---

<div class="post-metadata">

**Author:** ![Pairis](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/pairis/32/56439_2.png) [@Pairis](https://community.homey.app/u/Pairis)\
**Post date:** [May 16, 2024, 7:10pm UTC](https://community.homey.app/t/hourly-rain-forecast/109972/8 "2024-05-16T19:10:44Z")

</div>

Love the DIY suggestions too!

Enough homework haha!
