Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Snow if weather snowy #6

Open
emrahaslan opened this issue Sep 3, 2020 · 8 comments
Open

Run Snow if weather snowy #6

emrahaslan opened this issue Sep 3, 2020 · 8 comments

Comments

@emrahaslan
Copy link

Not Issue.

Is It possible to run this module only if current weather is snowy ?

@emrahaslan emrahaslan changed the title Run Snow ith weather Run Snow if weather snowy Sep 12, 2020
@Black-Zero
Copy link

+1 searching for this feature ^^
I just thought about the same idea...

@Jessendelft
Copy link

Jessendelft commented Jan 27, 2021

This is answered here:
https://forum.magicmirror.builders/topic/1232/mmm-snow-yet-another-snow-module/14

Basically, you can use MMM-Remote-Control to show & hide the module. You need some device though to check upon the weather & call the HTTP GET addresses.

@Black-Zero
Copy link

This is answered here:
https://forum.magicmirror.builders/topic/1232/mmm-snow-yet-another-snow-module/14

Basically, you can use MMM-Remote-Control to show & hide the module. You need some device though to check upon the weather & call the HTTP GET addresses.

Thank you for your hint :)

@schrammalama
Copy link

schrammalama commented Feb 2, 2021

I made a solution:
<!doctype html>

<title>Current Weather</title>

<script lang="text/javascript"> function weatherBalloon( cityID ) { var key = 'Your openweathermap api key'; fetch('https://api.openweathermap.org/data/2.5/weather?id=' + cityID+ '&appid=' + key) .then(function(resp) { return resp.json() }) // Convert data to json .then(function(data) { drawWeather(data); }) .catch(function() { // catch any errors }); }

window.onload = function() {
weatherBalloon( Your CityID );
}
function drawWeather( d ) {
var celcius = Math.round(parseFloat(d.main.temp)-273.15);
var fahrenheit = Math.round(((parseFloat(d.main.temp)-273.15)*1.8)+32);

document.getElementById('description').innerHTML = d.weather[0].description;
document.getElementById('temp').innerHTML = celcius + '&deg;';
document.getElementById('location').innerHTML = d.name;

}
var myVar = setInterval(myFunction, 1000000);
function myFunction() {
location.reload();
}
if (document.getElementById('description').innerHTML == "light snow") {
(function() {
document.getElementById('description').innerHTML = function() {
var wnd = window.open("http://Your Remote Control ip address:8080/api/module/MMM-Snow/show");
setTimeout(function() {
wnd.close();
}, 5000);
};
})();
} else {
var wnd = window.open("http://Your Remote Control ip address:8080/api/module/MMM-Snow/hide");
setTimeout(function() {
wnd.close();
}, 5000);
}
</script>

@schrammalama
Copy link

schrammalama commented Feb 3, 2021

My previous post was flawed, the script to get value of 'description' was running before the openweathermap api changed the value, resulting in it always running hide, even if there is snow. Here is the change made:

This was moved from a separate function to be a part of the drawWeather function so it could pull directly from the json data instead of from an .innerHTML value:

if (d.weather[0].description == "light snow") { var wnd = window.open("http://"Remote control ip address":8080/api/module/MMM-Snow/show"); setTimeout(function() { wnd.close(); }, 5000); } else { var wnd = window.open("http://Remote control ip address" :8080/api/module/MMM-Snow/hide"); setTimeout(function() { wnd.close(); }, 5000); }

Here is the final code:
Snow.txt

@Black-Zero
Copy link

Hello,

thank you schrammalama for your effort. May I ask you, how I should integrate this code into my MagicMirror?

Thank you very much!

@schrammalama
Copy link

It is an html page, run mm is one workspace then run the page in another workplace, if you run it in the same workplace it will come in front of the mm whenever it refreshes

@schrammalama
Copy link

schrammalama commented Feb 5, 2021

also i am working on working the code into the module, once finished i will put it up on the module list page and all you will have to do is install the module

https://github.com/schrammalama/MMM-Snow-Automatic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants