Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A node-RED flow that uses the Dark Sky API based on notes in this post: http://tech.scargill.net/node-red-weather/
[
{
"id": "a39dbd83.b5365",
"type": "tab",
"label": "Weather"
},
{
"id": "2c44271c.a08d58",
"type": "inject",
"z": "a39dbd83.b5365",
"name": "Every 15mins",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "900",
"crontab": "",
"once": true,
"x": 120,
"y": 80,
"wires": [
[
"5fcdba16.31aa94"
]
]
},
{
"id": "5fcdba16.31aa94",
"type": "http request",
"z": "a39dbd83.b5365",
"name": "GET Darksky JSON",
"method": "GET",
"ret": "obj",
"url": "https://api.darksky.net/forecast/[YOUR_API_KEY]/[YOUR_LATITUDE],[YOUR_LONGITUDE]?units=[YOUR_UNITS]",
"tls": "",
"x": 320,
"y": 80,
"wires": [
[
"87627343.8e1f3",
"a56c3d.2d77b3c",
"84e849bc.a27ef8",
"45891793.3b42a8",
"fa912223.b52d8",
"d893972b.692a78",
"6b913d54.3f3da4",
"798c0e54.aad58"
]
]
},
{
"id": "84e849bc.a27ef8",
"type": "function",
"z": "a39dbd83.b5365",
"name": "Day 0 icon",
"func": "try {\nmsg.payload=msg.payload.currently.icon;\nnode.send(msg);\n}\ncatch(e) {}",
"outputs": 1,
"noerr": 0,
"x": 550,
"y": 260,
"wires": [
[
"d61da2f1.262ec"
]
]
},
{
"id": "f2826729.6c1268",
"type": "ui_template",
"z": "a39dbd83.b5365",
"group": "d8a153f5.076c7",
"name": "CSS",
"order": 9,
"width": 0,
"height": 0,
"format": "<style>\n .filled {\n height: 100% !important;\n padding: 0 !important;\n margin: 0 !important;\n }\n .nr-dashboard-template {\n padding: 0;\n margin: 0;\n }\n .rounded {\n border-radius: 12px 12px 12px 12px;\n }\n .bigfont {\n font-size: 18px;\n }\n .smallfont {\n font-size: 12px;\n }\n</style>\n \n<script>\n $('.vibrate').on('click', function() {\n navigator.vibrate(100);\n });\n\n function restore_bg(x) {\n $(this).css(\"background-color\", x);\n };\n\n $('.touched').on('mousedown', function() {\n var x = $(this).css(\"background-color\");\n $(this).css(\"background-color\", \"yellow\");\n\n setTimeout(restore_bg.bind(this, x), 200);\n navigator.vibrate(80);\n });\n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"x": 750,
"y": 200,
"wires": [
[]
]
},
{
"id": "45891793.3b42a8",
"type": "function",
"z": "a39dbd83.b5365",
"name": "Day 1 icon",
"func": "try {\nmsg.payload=msg.payload.daily.data[1].icon;\nnode.send(msg);\n}\ncatch(e) {}",
"outputs": 1,
"noerr": 0,
"x": 550,
"y": 300,
"wires": [
[
"53c3ad38.8ceaa4"
]
]
},
{
"id": "d61da2f1.262ec",
"type": "ui_template",
"z": "a39dbd83.b5365",
"group": "d8a153f5.076c7",
"name": "Day 0",
"order": 3,
"width": "1",
"height": "1",
"format": "<script src=\"/myjs/skycons.js\"></script>\n \n<canvas id=\"icon0\" width=\"48\" height=\"48\"></canvas>\n \n<script>\nvar skycons0 = new Skycons({\"monochrome\": false, \n \"colors\": { \n \"main\": \"#779966\", \n \"moon\":\"#666666\",\n \"fog\": \"#555522\",\n \"fogbank\": \"#884488\",\n \"cloud\": \"#999999\",\n \"snow\": \"#aaaaaa\",\n \"leaf\":\"#00ff00\",\n \"rain\": \"#0000ff\",\n \"sun\": \"#ff3300\"\n } });\nskycons0.play();\n \n (function(scope) {\n scope.$watch('msg.payload', function(data) {\n if (data==\"clear-day\") skycons0.set(\"icon0\", Skycons.CLEAR_DAY);\n if (data==\"clear-night\") skycons0.set(\"icon0\", Skycons.CLEAR_NIGHT);\n if (data==\"partly-cloudy-day\") skycons0.set(\"icon0\", Skycons.PARTLY_CLOUDY_DAY);\n if (data==\"partly-cloudy-night\") skycons0.set(\"icon0\", Skycons.PARTLY_CLOUDY_NIGHT);\n if (data==\"cloudy\") skycons0.set(\"icon0\", Skycons.CLOUDY);\n if (data==\"rain\") skycons0.set(\"icon0\", Skycons.RAIN);\n if (data==\"sleet\") skycons0.set(\"icon0\", Skycons.SLEET);\n if (data==\"snow\") skycons0.set(\"icon0\", Skycons.SNOW);\n if (data==\"wind\") skycons0.set(\"icon0\", Skycons.WIND);\n if (data==\"fog\") skycons0.set(\"icon0\", Skycons.FOG);\n });\n })(scope);\n \n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"x": 750,
"y": 260,
"wires": [
[]
]
},
{
"id": "53c3ad38.8ceaa4",
"type": "ui_template",
"z": "a39dbd83.b5365",
"group": "d8a153f5.076c7",
"name": "Day 1",
"order": 4,
"width": "1",
"height": "1",
"format": "<canvas id=\"icon1\" width=\"48\" height=\"48\"></canvas>\n \n<script>\nvar skycons1 = new Skycons({\"monochrome\": false, \n \"colors\": { \n \"main\": \"#779966\", \n \"moon\":\"#666666\",\n \"fog\": \"#555522\",\n \"fogbank\": \"#884488\",\n \"cloud\": \"#999999\",\n \"snow\": \"#aaaaaa\",\n \"leaf\":\"#00ff00\",\n \"rain\": \"#0000ff\",\n \"sun\": \"#ff3300\"\n } });\nskycons1.play();\n \n (function(scope) {\n scope.$watch('msg.payload', function(data) {\n if (data==\"clear-day\") skycons1.set(\"icon1\", Skycons.CLEAR_DAY);\n if (data==\"clear-night\") skycons1.set(\"icon1\", Skycons.CLEAR_NIGHT);\n if (data==\"partly-cloudy-day\") skycons1.set(\"icon1\", Skycons.PARTLY_CLOUDY_DAY);\n if (data==\"partly-cloudy-night\") skycons1.set(\"icon1\", Skycons.PARTLY_CLOUDY_NIGHT);\n if (data==\"cloudy\") skycons1.set(\"icon1\", Skycons.CLOUDY);\n if (data==\"rain\") skycons1.set(\"icon1\", Skycons.RAIN);\n if (data==\"sleet\") skycons1.set(\"icon1\", Skycons.SLEET);\n if (data==\"snow\") skycons1.set(\"icon1\", Skycons.SNOW);\n if (data==\"wind\") skycons1.set(\"icon1\", Skycons.WIND);\n if (data==\"fog\") skycons1.set(\"icon1\", Skycons.FOG);\n });\n })(scope);\n \n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"x": 750,
"y": 300,
"wires": [
[]
]
},
{
"id": "6e5c459a.023b6c",
"type": "ui_template",
"z": "a39dbd83.b5365",
"group": "d8a153f5.076c7",
"name": "Day 2",
"order": 5,
"width": "1",
"height": "1",
"format": "<canvas id=\"icon2\" width=\"48\" height=\"48\"></canvas>\n \n<script>\nvar skycons2 = new Skycons({\"monochrome\": false, \n \"colors\": { \n \"main\": \"#779966\", \n \"moon\":\"#666666\",\n \"fog\": \"#555522\",\n \"fogbank\": \"#884488\",\n \"cloud\": \"#999999\",\n \"snow\": \"#aaaaaa\",\n \"leaf\":\"#00ff00\",\n \"rain\": \"#0000ff\",\n \"sun\": \"#ff3300\"\n } });\nskycons2.play();\n \n (function(scope) {\n scope.$watch('msg.payload', function(data) {\n if (data==\"clear-day\") skycons2.set(\"icon2\", Skycons.CLEAR_DAY);\n if (data==\"clear-night\") skycons2.set(\"icon2\", Skycons.CLEAR_NIGHT);\n if (data==\"partly-cloudy-day\") skycons2.set(\"icon2\", Skycons.PARTLY_CLOUDY_DAY);\n if (data==\"partly-cloudy-night\") skycons2.set(\"icon2\", Skycons.PARTLY_CLOUDY_NIGHT);\n if (data==\"cloudy\") skycons2.set(\"icon2\", Skycons.CLOUDY);\n if (data==\"rain\") skycons2.set(\"icon2\", Skycons.RAIN);\n if (data==\"sleet\") skycons2.set(\"icon2\", Skycons.SLEET);\n if (data==\"snow\") skycons2.set(\"icon2\", Skycons.SNOW);\n if (data==\"wind\") skycons2.set(\"icon2\", Skycons.WIND);\n if (data==\"fog\") skycons2.set(\"icon2\", Skycons.FOG);\n });\n })(scope);\n \n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"x": 750,
"y": 340,
"wires": [
[]
]
},
{
"id": "f5b455b2.f9fc68",
"type": "ui_template",
"z": "a39dbd83.b5365",
"group": "d8a153f5.076c7",
"name": "Day 3",
"order": 6,
"width": "1",
"height": "1",
"format": "<canvas id=\"icon3\" width=\"48\" height=\"48\"></canvas>\n \n<script>\nvar skycons3 = new Skycons({\"monochrome\": false, \n \"colors\": { \n \"main\": \"#779966\", \n \"moon\":\"#666666\",\n \"fog\": \"#555522\",\n \"fogbank\": \"#884488\",\n \"cloud\": \"#999999\",\n \"snow\": \"#aaaaaa\",\n \"leaf\":\"#00ff00\",\n \"rain\": \"#0000ff\",\n \"sun\": \"#ff3300\"\n } });\nskycons3.play();\n \n (function(scope) {\n scope.$watch('msg.payload', function(data) {\n if (data==\"clear-day\") skycons3.set(\"icon3\", Skycons.CLEAR_DAY);\n if (data==\"clear-night\") skycons3.set(\"icon3\", Skycons.CLEAR_NIGHT);\n if (data==\"partly-cloudy-day\") skycons3.set(\"icon3\", Skycons.PARTLY_CLOUDY_DAY);\n if (data==\"partly-cloudy-night\") skycons3.set(\"icon3\", Skycons.PARTLY_CLOUDY_NIGHT);\n if (data==\"cloudy\") skycons3.set(\"icon3\", Skycons.CLOUDY);\n if (data==\"rain\") skycons3.set(\"icon3\", Skycons.RAIN);\n if (data==\"sleet\") skycons3.set(\"icon3\", Skycons.SLEET);\n if (data==\"snow\") skycons3.set(\"icon3\", Skycons.SNOW);\n if (data==\"wind\") skycons3.set(\"icon3\", Skycons.WIND);\n if (data==\"fog\") skycons3.set(\"icon3\", Skycons.FOG);\n });\n })(scope);\n \n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"x": 750,
"y": 380,
"wires": [
[]
]
},
{
"id": "a4c4c331.e346e",
"type": "ui_template",
"z": "a39dbd83.b5365",
"group": "d8a153f5.076c7",
"name": "Day 4",
"order": 7,
"width": "1",
"height": "1",
"format": "<canvas id=\"icon4\" width=\"48\" height=\"48\"></canvas>\n \n<script>\nvar skycons4 = new Skycons({\"monochrome\": false, \n \"colors\": { \n \"main\": \"#779966\", \n \"moon\":\"#666666\",\n \"fog\": \"#555522\",\n \"fogbank\": \"#884488\",\n \"cloud\": \"#999999\",\n \"snow\": \"#aaaaaa\",\n \"leaf\":\"#00ff00\",\n \"rain\": \"#0000ff\",\n \"sun\": \"#ff3300\"\n } });\nskycons4.play();\n \n (function(scope) {\n scope.$watch('msg.payload', function(data) {\n if (data==\"clear-day\") skycons4.set(\"icon4\", Skycons.CLEAR_DAY);\n if (data==\"clear-night\") skycons4.set(\"icon4\", Skycons.CLEAR_NIGHT);\n if (data==\"partly-cloudy-day\") skycons4.set(\"icon4\", Skycons.PARTLY_CLOUDY_DAY);\n if (data==\"partly-cloudy-night\") skycons4.set(\"icon4\", Skycons.PARTLY_CLOUDY_NIGHT);\n if (data==\"cloudy\") skycons4.set(\"icon4\", Skycons.CLOUDY);\n if (data==\"rain\") skycons4.set(\"icon4\", Skycons.RAIN);\n if (data==\"sleet\") skycons4.set(\"icon4\", Skycons.SLEET);\n if (data==\"snow\") skycons4.set(\"icon4\", Skycons.SNOW);\n if (data==\"wind\") skycons4.set(\"icon4\", Skycons.WIND);\n if (data==\"fog\") skycons4.set(\"icon4\", Skycons.FOG);\n });\n })(scope);\n \n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"x": 750,
"y": 420,
"wires": [
[]
]
},
{
"id": "905961b5.dd943",
"type": "ui_template",
"z": "a39dbd83.b5365",
"group": "d8a153f5.076c7",
"name": "Day 5",
"order": 8,
"width": "1",
"height": "1",
"format": "<canvas id=\"icon5\" width=\"48\" height=\"48\"></canvas>\n \n<script>\nvar skycons5 = new Skycons({\"monochrome\": false, \n \"colors\": { \n \"main\": \"#779966\", \n \"moon\":\"#666666\",\n \"fog\": \"#555522\",\n \"fogbank\": \"#884488\",\n \"cloud\": \"#999999\",\n \"snow\": \"#aaaaaa\",\n \"leaf\":\"#00ff00\",\n \"rain\": \"#0000ff\",\n \"sun\": \"#ff3300\"\n } });\nskycons5.play();\n \n (function(scope) {\n scope.$watch('msg.payload', function(data) {\n if (data==\"clear-day\") skycons5.set(\"icon5\", Skycons.CLEAR_DAY);\n if (data==\"clear-night\") skycons5.set(\"icon5\", Skycons.CLEAR_NIGHT);\n if (data==\"partly-cloudy-day\") skycons5.set(\"icon5\", Skycons.PARTLY_CLOUDY_DAY);\n if (data==\"partly-cloudy-night\") skycons5.set(\"icon5\", Skycons.PARTLY_CLOUDY_NIGHT);\n if (data==\"cloudy\") skycons5.set(\"icon5\", Skycons.CLOUDY);\n if (data==\"rain\") skycons5.set(\"icon5\", Skycons.RAIN);\n if (data==\"sleet\") skycons5.set(\"icon5\", Skycons.SLEET);\n if (data==\"snow\") skycons5.set(\"icon5\", Skycons.SNOW);\n if (data==\"wind\") skycons5.set(\"icon5\", Skycons.WIND);\n if (data==\"fog\") skycons5.set(\"icon5\", Skycons.FOG);\n });\n })(scope);\n \n</script>",
"storeOutMessages": true,
"fwdInMessages": true,
"x": 750,
"y": 460,
"wires": [
[]
]
},
{
"id": "fa912223.b52d8",
"type": "function",
"z": "a39dbd83.b5365",
"name": "Day 2 icon",
"func": "try {\nmsg.payload=msg.payload.daily.data[2].icon;\nnode.send(msg);\n}\ncatch(e) {}",
"outputs": 1,
"noerr": 0,
"x": 550,
"y": 340,
"wires": [
[
"6e5c459a.023b6c"
]
]
},
{
"id": "d893972b.692a78",
"type": "function",
"z": "a39dbd83.b5365",
"name": "Day 3 icon",
"func": "try {\nmsg.payload=msg.payload.daily.data[3].icon;\nnode.send(msg);\n}\ncatch(e) {}",
"outputs": 1,
"noerr": 0,
"x": 550,
"y": 380,
"wires": [
[
"f5b455b2.f9fc68"
]
]
},
{
"id": "6b913d54.3f3da4",
"type": "function",
"z": "a39dbd83.b5365",
"name": "Day 4 icon",
"func": "try {\nmsg.payload=msg.payload.daily.data[4].icon;\nnode.send(msg);\n}\ncatch(e) {}",
"outputs": 1,
"noerr": 0,
"x": 550,
"y": 420,
"wires": [
[
"a4c4c331.e346e"
]
]
},
{
"id": "798c0e54.aad58",
"type": "function",
"z": "a39dbd83.b5365",
"name": "Day 5 icon",
"func": "try {\nmsg.payload=msg.payload.daily.data[5].icon;\nnode.send(msg);\n}\ncatch(e) {}",
"outputs": 1,
"noerr": 0,
"x": 550,
"y": 460,
"wires": [
[
"905961b5.dd943"
]
]
},
{
"id": "87627343.8e1f3",
"type": "function",
"z": "a39dbd83.b5365",
"name": "Days",
"func": "(function() {\n var days = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];\n\n var months = ['January','February','March','April','May','June','July','August','September','October','November','December'];\n\n Date.prototype.getMonthName = function() {\n return months[ this.getMonth() ];\n };\n Date.prototype.getDayName = function() {\n return days[ this.getDay() ];\n };\n \n Date.prototype.addDays = function(days) {\n this.setDate(this.getDate() + parseInt(days));\n return this;\n };\n})();\n\nmsg = {};\nvar now = new Date();\nmsg.d0 = now.getDayName();\nmsg.d1 = new Date().addDays(1).getDayName(); //+1 days\nmsg.d2 = new Date().addDays(2).getDayName(); //+2 days\nmsg.d3 = new Date().addDays(3).getDayName(); //+3 days\nmsg.d4 = new Date().addDays(4).getDayName(); //+4 days\nmsg.d5 = new Date().addDays(5).getDayName(); //+5 days\n\nmsg.payload=msg.d0;\nvar month = now.getMonthName();\n node.status({text:msg.payload});\n \nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 570,
"y": 80,
"wires": [
[
"5bd255a3.367cec"
]
]
},
{
"id": "5bd255a3.367cec",
"type": "ui_template",
"z": "a39dbd83.b5365",
"group": "d8a153f5.076c7",
"name": "Days",
"order": 1,
"width": "6",
"height": "1",
"format": "<div layout=\"row\" layout-align=\"space-between\" style=\"text-align: left; margin:8px 0 0 8px;\">\n<span style=\"width:16%;margin-left:4px;\">{{msg.d0}}</span>\n<span style=\"width:16%;margin-left:4px;\">{{msg.d1}}</span>\n<span style=\"width:16%;margin-left:4px;\">{{msg.d2}}</span>\n<span style=\"width:16%;margin-left:4px;\">{{msg.d3}}</span>\n<span style=\"width:16%;margin-left:4px;\">{{msg.d4}}</span>\n<span style=\"width:16%;margin-left:4px;\">{{msg.d5}}</span>\n</div>",
"storeOutMessages": true,
"fwdInMessages": true,
"x": 750,
"y": 80,
"wires": [
[]
]
},
{
"id": "a56c3d.2d77b3c",
"type": "function",
"z": "a39dbd83.b5365",
"name": "T° Hi/Lo",
"func": "msg.tmin1=Math.round(msg.payload.daily.data[0].temperatureMin);\nmsg.tmin2=Math.round(msg.payload.daily.data[1].temperatureMin);\nmsg.tmin3=Math.round(msg.payload.daily.data[2].temperatureMin);\nmsg.tmin4=Math.round(msg.payload.daily.data[3].temperatureMin);\nmsg.tmin5=Math.round(msg.payload.daily.data[4].temperatureMin);\nmsg.tmin6=Math.round(msg.payload.daily.data[5].temperatureMin);\n\nmsg.tmax1=Math.round(msg.payload.daily.data[0].temperatureMax);\nmsg.tmax2=Math.round(msg.payload.daily.data[1].temperatureMax);\nmsg.tmax3=Math.round(msg.payload.daily.data[2].temperatureMax);\nmsg.tmax4=Math.round(msg.payload.daily.data[3].temperatureMax);\nmsg.tmax5=Math.round(msg.payload.daily.data[4].temperatureMax);\nmsg.tmax6=Math.round(msg.payload.daily.data[5].temperatureMax);\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 560,
"y": 140,
"wires": [
[
"30a9e086.32454"
]
]
},
{
"id": "30a9e086.32454",
"type": "ui_template",
"z": "a39dbd83.b5365",
"group": "d8a153f5.076c7",
"name": "T° Hi/Lo",
"order": 2,
"width": "6",
"height": "1",
"format": "<div layout=\"row\" layout-align=\"space-between\" style=\"text-align: left; margin:-3px 0 0 4px;\">\n <div style=\"width:16%;margin-left:6px;\">\n <div><span>&#8679;</span>{{msg.tmax1 + \"°\"}}</div>\n <div><span>&#8681;</span>{{msg.tmin1 + \"°\"}}</div>\n </div>\n <div style=\"width:16%;margin-left:6px;\">\n <div><span>&#8679;</span>{{msg.tmax2 + \"°\"}}</div>\n <div><span>&#8681;</span>{{msg.tmin2 + \"°\"}}</div>\n </div>\n <div style=\"width:16%;margin-left:6px;\">\n <div><span>&#8679;</span>{{msg.tmax3 + \"°\"}}</div>\n <div><span>&#8681;</span>{{msg.tmin3 + \"°\"}}</div>\n </div>\n <div style=\"width:16%;margin-left:6px;\">\n <div><span>&#8679;</span>{{msg.tmax4 + \"°\"}}</div>\n <div><span>&#8681;</span>{{msg.tmin4 + \"°\"}}</div>\n </div>\n <div style=\"width:16%;margin-left:6px;\">\n <div><span>&#8679;</span>{{msg.tmax5 + \"°\"}}</div>\n <div><span>&#8681;</span>{{msg.tmin5 + \"°\"}}</div>\n </div>\n <div style=\"width:16%;margin-left:6px;\">\n <div><span>&#8679;</span>{{msg.tmax6 + \"°\"}}</div>\n <div><span>&#8681;</span>{{msg.tmin6 + \"°\"}}</div>\n </div>\n</div>",
"storeOutMessages": true,
"fwdInMessages": true,
"x": 740,
"y": 140,
"wires": [
[]
]
},
{
"id": "d8a153f5.076c7",
"type": "ui_group",
"z": "",
"name": "The Week Ahead",
"tab": "6eb3fbb3.d8f724",
"disp": true,
"width": "6"
},
{
"id": "6eb3fbb3.d8f724",
"type": "ui_tab",
"z": "",
"name": "Weather Forecast",
"icon": "wb_sunny",
"order": 4
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.