Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. [
  2. {
  3. "id": "ec1e5bf6.b0b6a8",
  4. "type": "http request",
  5. "z": "39b2077c.e1fce8",
  6. "name": "sunrise-sunset api",
  7. "method": "GET",
  8. "ret": "obj",
  9. "url": "http://api.sunrise-sunset.org/json?lat=39.37797&lng=-74.60392&formatted=0",
  10. "tls": "",
  11. "x": 310,
  12. "y": 100,
  13. "wires": [
  14. [
  15. "2c351243.c8fcee",
  16. "c1334b82.13f578"
  17. ]
  18. ]
  19. },
  20. {
  21. "id": "2c351243.c8fcee",
  22. "type": "function",
  23. "z": "39b2077c.e1fce8",
  24. "name": "set global context",
  25. "func": "// detect api errors\nif (msg.payload.status != \"OK\") {\n return msg;\n}\n\nvar sunrise = new Date(msg.payload.results.sunrise);\nvar sunset = new Date(msg.payload.results.sunset);\n\nglobal.set(\"sunrise\", sunrise.toJSON());\nglobal.set(\"sunset\", sunset.toJSON());\n\nreturn { payload: {} };",
  26. "outputs": "1",
  27. "noerr": 0,
  28. "x": 530,
  29. "y": 100,
  30. "wires": [
  31. [
  32. "b5eb7c3c.30bdc"
  33. ]
  34. ]
  35. },
  36. {
  37. "id": "349e5d6f.0ef762",
  38. "type": "inject",
  39. "z": "39b2077c.e1fce8",
  40. "name": "00:00 kick",
  41. "topic": "",
  42. "payload": "",
  43. "payloadType": "date",
  44. "repeat": "",
  45. "crontab": "00 00 * * *",
  46. "once": false,
  47. "x": 110,
  48. "y": 100,
  49. "wires": [
  50. [
  51. "ec1e5bf6.b0b6a8"
  52. ]
  53. ]
  54. },
  55. {
  56. "id": "fcaa38ac.b628e8",
  57. "type": "inject",
  58. "z": "39b2077c.e1fce8",
  59. "name": "boot",
  60. "topic": "",
  61. "payload": "",
  62. "payloadType": "date",
  63. "repeat": "",
  64. "crontab": "",
  65. "once": true,
  66. "x": 130,
  67. "y": 40,
  68. "wires": [
  69. [
  70. "ec1e5bf6.b0b6a8"
  71. ]
  72. ]
  73. },
  74. {
  75. "id": "ec3f963e.71f698",
  76. "type": "interval",
  77. "z": "39b2077c.e1fce8",
  78. "name": "every 5m",
  79. "interval": "5",
  80. "onstart": false,
  81. "msg": "ping",
  82. "showstatus": true,
  83. "unit": "minutes",
  84. "statusformat": "YYYY-MM-D HH:mm:ss",
  85. "x": 560,
  86. "y": 180,
  87. "wires": [
  88. [
  89. "b5eb7c3c.30bdc"
  90. ]
  91. ]
  92. },
  93. {
  94. "id": "b5eb7c3c.30bdc",
  95. "type": "function",
  96. "z": "39b2077c.e1fce8",
  97. "name": "set time of day",
  98. "func": "// input is a trigger, payload does not matter\n\nvar sunrise = new Date(global.get(\"sunrise\"));\nvar sunset = new Date(global.get(\"sunset\"));\nvar now = new Date();\n\nvar sunrise_day = sunrise.getDate();\nvar now_day = now.getDate();\n\nif (sunrise_day != now_day) {\n node.warn(\"stale sunrise data, sunrise_day=\" + sunrise_day + \", now_day=\" + now_day);\n return null;\n}\n\nvar tod;\n\nif (now >= sunrise && now.getHours() < 12) {\n tod = \"morning\";\n} else if (now.getHours() >= 12 && now < sunset) {\n tod = \"afternoon\";\n} else if (now >= sunset && now.getHours() < 23) {\n tod = \"evening\";\n} else {\n tod = \"night\";\n}\n\nnode.status({text: tod});\n\nvar last = context.get(\"tod\");\nif (tod == last) {\n return null;\n}\n\n// local context so we lose state on restart\ncontext.set(\"tod\", tod);\n\n// global context for other consumers\nglobal.set(\"tod\", tod);\n\n// only fires on boot and state change\nreturn { payload: { tod: tod } };",
  99. "outputs": 1,
  100. "noerr": 0,
  101. "x": 740,
  102. "y": 140,
  103. "wires": [
  104. [
  105. "c1334b82.13f578",
  106. "54bcc22a.d9574c"
  107. ]
  108. ]
  109. },
  110. {
  111. "id": "c1334b82.13f578",
  112. "type": "debug",
  113. "z": "39b2077c.e1fce8",
  114. "name": "tod_debug",
  115. "active": true,
  116. "console": "false",
  117. "complete": "true",
  118. "x": 750,
  119. "y": 40,
  120. "wires": []
  121. },
  122. {
  123. "id": "54bcc22a.d9574c",
  124. "type": "mqtt out",
  125. "z": "39b2077c.e1fce8",
  126. "name": "",
  127. "topic": "state/tod",
  128. "qos": "",
  129. "retain": "",
  130. "broker": "c77e45a7.481c88",
  131. "x": 920,
  132. "y": 140,
  133. "wires": []
  134. },
  135. {
  136. "id": "c77e45a7.481c88",
  137. "type": "mqtt-broker",
  138. "z": "",
  139. "broker": "127.0.0.1",
  140. "port": "1883",
  141. "clientid": "",
  142. "usetls": false,
  143. "compatmode": true,
  144. "keepalive": "60",
  145. "cleansession": true,
  146. "willTopic": "",
  147. "willQos": "0",
  148. "willPayload": "",
  149. "birthTopic": "",
  150. "birthQos": "0",
  151. "birthPayload": ""
  152. }
  153. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement