Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ecf3dd4
Add files via upload
cowboysdude Oct 3, 2018
fcb4a9b
Update README.md
cowboysdude Oct 3, 2018
7a1f65e
Update README.md
cowboysdude Oct 3, 2018
22331ba
Update README.md
cowboysdude Oct 3, 2018
6a7cb1b
Update README.md
cowboysdude Oct 3, 2018
13224dd
Add files via upload
cowboysdude Oct 7, 2018
465202a
Create test
cowboysdude Oct 7, 2018
0c3f773
Add files via upload
cowboysdude Oct 7, 2018
d4597b3
Update README.md
cowboysdude Oct 7, 2018
5d79ecf
Update README.md
cowboysdude Oct 7, 2018
2c06994
Delete test
cowboysdude Oct 7, 2018
cd6f4e6
Delete moon_sky_8_194732.jpg
cowboysdude Oct 7, 2018
352094a
Add files via upload
cowboysdude Oct 7, 2018
b7a9d02
Update README.md
cowboysdude Oct 7, 2018
7c523cb
Update README.md
cowboysdude Oct 7, 2018
5d4fde4
Update README.md
cowboysdude Oct 7, 2018
fa0371c
Delete MMM-WeatherBackground.css
cowboysdude Oct 7, 2018
b053a92
Update MMM-WeatherBackground.js
cowboysdude Oct 7, 2018
c8357c0
Update MMM-WeatherBackground.js
cowboysdude Oct 7, 2018
7b90441
Delete scr1.JPG
cowboysdude Oct 7, 2018
dee22dd
Add files via upload
cowboysdude Oct 7, 2018
968ec32
Update MMM-WeatherBackground.js
cowboysdude Oct 9, 2018
8522a49
Update node_helper.js
cowboysdude Oct 9, 2018
2fecfd5
Update package.json
cowboysdude Oct 9, 2018
5ed3f70
Update README.md
mykle1 Oct 12, 2018
36b153e
Merge pull request #1 from mykle1/patch-1
cowboysdude Oct 12, 2018
98600da
Update MMM-WeatherBackground.js
cowboysdude Oct 13, 2018
dcf5d06
Delete node_helper.js
cowboysdude Oct 13, 2018
8a49de6
Add files via upload
cowboysdude Nov 10, 2018
2c21dc7
Add files via upload
cowboysdude Nov 10, 2018
17f5c7a
Update MMM-WeatherBackground.js
cowboysdude Feb 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 103 additions & 60 deletions MMM-WeatherBackground.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,113 @@
//
// MMM-WeatherBackground
//
// Modified by Cowboysdude for MMM-NOAA3

var sunset;
var icon;
"use strict";

Module.register("MMM-WeatherBackground", {
defaults: {
targetDOM: ".fullscreen.below", //null or DomSelector for target. (if null, currentweather will be targeted.)
notification: "CURRENTWEATHER_DATA", //if you use other weather module, modify this.
payloadConverter: (payload)=> {
var iconMap = {
"01d": "sunny",
"02d": "clouds",
"03d": "cloudy",
"04d": "windy",
"09d": "heavy rain",
"10d": "rain",
"11d": "thunderstorm",
"13d": "snow",
"50d": "fog",
"01n": "clear night",
"02n": "cloudy night",
"03n": "cloudy night",
"04n": "cloudy night",
"09n": "night rain",
"10n": "night rain",
"11n": "night thunderstorm",
"13n": "night snow",
"50n": "windy night"
}
return iconMap[payload.data.weather[0].icon] //return value be used for search keyword.

defaults: {
targetDOM: ".fullscreen.below", //null or DomSelector for target. (if null, currentweather will be targeted.)
notification: "WEATHER", //if you use other weather module, modify this.
opacity: '0.3',
payloadConverter: (payload) => {
icon = payload.icon,
sunset = moment(payload.sunset).format('HH'),
now = moment().format('HH'),
console.log("Now time :"+now+" Sunset :"+sunset);
if (now >= sunset) {
var iconMap = {
"breezy": "modules/MMM-WeatherBackground/images/n_bao.jpg",
"broken clouds":"modules/MMM-WeatherBackground/images/n_brokenclouds.jpg",
"clear": "modules/MMM-WeatherBackground/images/n_clear.jpg",
"sleet": "modules/MMM-WeatherBackground/images/n_sleet.jpg",
"mostlycloudy": "modules/MMM-WeatherBackground/images/n_mostlycloudy.jpg",
"partlycloudy": "modules/MMM-WeatherBackground/images/n_partlycloudy.jpg",
"cloudy": "modules/MMM-WeatherBackground/images/n_cloudy.jpg",
"rain": "modules/MMM-WeatherBackground/images/n_rain.jpg",
"drizzle": "modules/MMM-WeatherBackground/images/n_drizzle.jpg",
"tstorms": "modules/MMM-WeatherBackground/images/n_tstorms.jpg",
"snow": "modules/MMM-WeatherBackground/images/n_snow.jpg",
"windy": "modules/MMM-WeatherBackground/images/n_windy.jpg",
"fog": "modules/MMM-WeatherBackground/images/n_fog.jpg",
"overcast": "modules/MMM-WeatherBackground/images/n_overcast.jpg",
"hazy": "modules/MMM-WeatherBackground/images/n_hazy.jpg",
"Clouds":"modules/MMM-WeatherBackground/images/n_cloudy.jpg",
"Light Rain": "modules/MMM-WeatherBackground/images/n_lightrain.jpg",
"Breezy and Mostly Cloudy": "modules/MMM-WeatherBackground/images/n_partlycloudy.jpg",
"chancesnow": "modules/MMM-WeatherBackground/images/n_lightsnow.jpg",
}
return iconMap[icon]

} else {

var iconMap = {
"breezy": "modules/MMM-WeatherBackground/images/bao.jpg",
"brokenclouds":"modules/MMM-WeatherBackground/images/brokenclouds.jpg",
"sunny": "modules/MMM-WeatherBackground/images/clear.jpg",
"clear": "modules/MMM-WeatherBackground/images/clear.jpg",
"cloudy": "modules/MMM-WeatherBackground/images/cloudy.jpg",
"mostlycloudy": "modules/MMM-WeatherBackground/images/mostlycloudy.jpg",
"partlycloudy": "modules/MMM-WeatherBackground/images/partlycloudy.jpg",
"overcast": "modules/MMM-WeatherBackground/images/overcast.jpg",
"wind": "modules/MMM-WeatherBackground/images/windy.jpg",
"rain": "modules/MMM-WeatherBackground/images/rain.jpg",
"tstorms": "modules/MMM-WeatherBackground/images/tstorms.jpg",
"snow": "modules/MMM-WeatherBackground/images/snow.jpg",
"fog": "modules/MMM-WeatherBackground/images/fog.jpg",
"sleet": "modules/MMM-WeatherBackground/images/sleet.jpg",
"hazy": "modules/MMM-WeatherBackground/images/hazy.jpg",
"drizzle": "modules/MMM-WeatherBackground/images/drizzle.jpg",
"Light Rain": "modules/MMM-WeatherBackground/images/lightrain.jpg",
"Breezy and Mostly Cloudy": "modules/MMM-WeatherBackground/images/partlycloudy.jpg",
"chancesnow": "modules/MMM-WeatherBackground/images/lightsnow.jpg",
}
return iconMap[icon]
}
},
},
},

notificationReceived: function(noti, payload, sender) {
switch(noti) {
case "DOM_OBJECTS_CREATED" :
break
case this.config.notification :
var target = (this.config.targetDOM) ? this.config.targetDOM : "#" + sender.data.identifier
Css: function() {
var myElement = document.getElementsByClassName('module');
var i;
for (i = 0; i < myElement.length; i++) {
myElement[i].style.backgroundColor = "rgba(0,0,0," + this.config.opacity + ")";
myElement[i].style.padding = "10px 10px 10px 10px";
}
},

var t = this.config.payloadConverter(payload)
this.loadImage(target, t)
break
}
},
notificationReceived: function(noti, payload, sender) {
switch (noti) {
case "DOM_OBJECTS_CREATED":
break
case this.config.notification:
var target = (this.config.targetDOM) ? this.config.targetDOM : "#" + sender.data.identifier
var t = this.config.payloadConverter(payload)
this.loadImage(target, t)
this.Css()
break
}
},

loadImage: function(target, description) {
var drawImage = function(dom) {
var timer = setTimeout(()=>{
//var w = dom.offsetWidth
//var h = dom.offsetHeight
//var url = `https://source.unsplash.com/${w}x${h}/?"${description}"`
var seed = Date.now()
var url = `https://source.unsplash.com/featured/?"${description}"&s=${seed}`
dom.style.backgroundSize = "cover"
dom.style.transition = "background-image 1s ease 1s"
var url = `url('${url}')`
dom.style.backgroundImage = url
}, 1000)
}
var doms = document.querySelectorAll(target)
if (doms.length <= 0) {
console.log("[WTHBGR] DOM not found.", target)
return;
loadImage: function(target, description) {
var drawImage = function(dom) {
var timer = setTimeout(() => {
var url = description
dom.style.backgroundSize = "cover"
dom.style.transition = "background-image 2s ease 2s"
var url = `url('${url}')`
dom.style.backgroundImage = url
}, 1000)
}
var doms = document.querySelectorAll(target)
if (doms.length <= 0) {
console.log("[NOAA3_WTHBGR] DOM not found.", target)
return;
}
doms.forEach((dom) => {
drawImage(dom)
})
}
doms.forEach((dom)=>{
drawImage(dom)
})
}
})
77 changes: 21 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,34 @@
# MMM-WeatherBackground
MagicMirror Module - for Weather image background from Unsplash. This is a plugin of other weather modules.
MagicMirror Module - for Weather image background. This is a plugin of other weather modules.

## Screenshot
![Screenshot](https://github.com/eouia/MMM-WeatherBackground/blob/master/scr.png?raw=true)
Day
![Screenshot](scr.png)

Night
![Screenshot](scr1.JPG)


## Installation
```shell
cd ~/MagicMirror/modules
git clone https://github.com/eouia/MMM-WeatherBackground
git clone https://github.com/cowboysdude/MMM-WeatherBackground
cd MMM-WeatherBackground
npm install in the MMM-WeatherBackground directory
```

## Configuration
### Simple
```javascript
{
module: "MMM-WeatherBackground",
// don't assign position.
config: {}
},
```
### Defaults & details
```javascript
{
module: "MMM-WeatherBackground",
config: {
targetDOM: ".fullscreen.below", //null or DomSelector for target.
// if null, currentweather will be targeted.
// examples: ".newsfeed", "#SOME_SPECIAL_DOM", ".top.left .module"

// You don't need to care about belows;
notification: "CURRENTWEATHER_DATA", //if you want to use other notification, modify this.
payloadConverter: (payload)=> {
var iconMap = {
"01d": "sunny",
"02d": "clouds",
"03d": "cloudy",
"04d": "windy",
"09d": "heavy rain",
"10d": "rain",
"11d": "thunderstorm",
"13d": "snow",
"50d": "fog",
"01n": "clear night",
"02n": "cloudy night",
"03n": "cloudy night",
"04n": "cloudy night",
"09n": "night rain",
"10n": "night rain",
"11n": "night thunderstorm",
"13n": "night snow",
"50n": "windy night"
}
return iconMap[payload.data.weather[0].icon] //return value be used for search keyword.
//other solution: return payload.data.weather[0].description
},
}
},

```
## Tip
You'd better modify your CSS to enhance visibilties of your modules. Below is just one of examples.
```CSS
.module {
background-color:rgba(0,0,0,0.5)
}
```

Sometimes, unsplash could return mismatched images with keyword.
disabled: false,
module: "MMM-WeatherBackground",
config: {
opacity: "0.3" //This is the color behind the modules so you can see them better. Higher the number the darker the color
// default in module is set to 0.4
}
},
```
That's pretty much the entire config entry that can be put anywhere in your config.js.
## BE AWARE
If you don't get a background let me know what the weather in the module says, perhaps there's no image for it and needs to be updated :)
Binary file added images/chancesnow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/clear.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/cloudy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/drizzle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/flurries.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/fog.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/hazy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/lightsnow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/mostlycloudy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_chancesnow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_changesnow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_clear.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_cloudy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_flurries.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_fog.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_hazy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_lightsnow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_mostlycloudy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_overcast.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_partlycloudy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_rain.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_sleet.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_snow.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/n_tstorms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/overcast.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/partlycloudy.jpg
Binary file added images/rain.jpg
Binary file added images/raining.png
Binary file added images/sleet.jpg
Binary file added images/snow.jpg
Binary file added images/tstorms.jpg
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "mmm-weatherbackground",
"version": "3.0.1",
"description": "MagicMirror Module - for Weather image background from Unsplash. This is a plugin of other weather modules.",
"main": "MMM-WeatherBackground.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"dayjs": "^1.7.7",
"request": "^2.88.0"
},
"devDependencies": {}
}
Binary file modified scr.png
Binary file added scr1.JPG