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.
// 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);
});
Keen to hear your advice!
Thanks!