Skip to content

Instantly share code, notes, and snippets.

@AntoineLemaire
Created December 2, 2020 20:03
Show Gist options
  • Save AntoineLemaire/66712b1d9c76738e5df159c1b6929c43 to your computer and use it in GitHub Desktop.
Save AntoineLemaire/66712b1d9c76738e5df159c1b6929c43 to your computer and use it in GitHub Desktop.
Send Pushbullet notification when temperature is bellow 0 in the next 12h
var pushbullet_access_key = '123456789123456789'; // Can be create here : https://www.pushbullet.com/#settings/account
var accuweather_api_key = 'ABCDEFGHIJKLMNOPQRST'; // Find it https://developer.accuweather.com/user/me/apps
var accuweather_location_key = 123456; // Find it with https://developer.accuweather.com/accuweather-locations-api/apis/get/locations/v1/cities/search
function checkWeather() {
var accuweather_url = 'http://dataservice.accuweather.com/forecasts/v1/hourly/12hour/';
var response =UrlFetchApp.fetch(accuweather_url + accuweather_location_key + '?apikey='+accuweather_api_key+'&metric=true', {
"method": "GET"
})
var data = JSON.parse(response.getContentText());
var minTempValue = null;
var minValueTime = null;
for (let i = 0; i < data.length; i++) {
if (data[i]['Temperature']['Value'] < 0) {
var date = new Date(data[i]['EpochDateTime'] * 1000);
var hours = date.getHours();
var minutes = "0" + date.getMinutes();
// Will display time in 10:30:23 format
var formattedTime = hours + 'h' + minutes.substr(-2);
if (minTempValue == null || minTempValue > data[i]['Temperature']['Value']) {
minTempValue = data[i]['Temperature']['Value'];
minValueTime = formattedTime;
}
}
}
if (minTempValue !== null) {
sendPushBulletNotification(minTempValue, minValueTime);
}
}
function sendPushBulletNotification(minTempValue, minValueTime) {
var options = {
"method" : "post",
"Content-Type" : "application/json",
"headers" : { "Authorization": "Basic "+Utilities.base64Encode(pushbullet_access_key+":") },
"payload" : {
"type" : "note",
"title": "Attention il va faire froid",
"body": "Il faut couvrir la voiture ! Température minimale sur 12h : "+minTempValue+"°C à "+minValueTime+" cette nuit 🥶️",
}
};
var push_bullet_url = "https://api.pushbullet.com/v2/pushes";
UrlFetchApp.fetch(push_bullet_url, options);
return;
}
@AntoineLemaire
Copy link
Author

AntoineLemaire commented Dec 2, 2020

This script for Google Script just send a pushbullet notification when the temperature is bellow 0 during the night to remember me to put a protection on my car, so I won't need to scrape the frost on my windshield

image

@AntoineLemaire
Copy link
Author

To install it :

image
image

image
image

image

@AntoineLemaire
Copy link
Author

To add a trigger for your script (like launch it every day at xxh) :
Click on add a trigger :
image

Select the parameters you want for the trigger
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment