-
Notifications
You must be signed in to change notification settings - Fork 27
/
nodered_flow.json
150 lines (150 loc) · 4.19 KB
/
nodered_flow.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
[
{
"id": "7ff4fc88.583d84",
"type": "tab",
"label": "Alarm Clock Display",
"disabled": false,
"info": ""
},
{
"id": "757846ba.6750c8",
"type": "mqtt in",
"z": "7ff4fc88.583d84",
"name": "",
"topic": "dash_buttons/nightstand",
"qos": "2",
"datatype": "auto",
"broker": "b558af9.9ad0b5",
"x": 142,
"y": 92,
"wires": [["29889c2f.a58454", "14b91a9a.a69d55"]]
},
{
"id": "29889c2f.a58454",
"type": "function",
"z": "7ff4fc88.583d84",
"name": "Format MQTT message",
"func": "const time = new Date();\n\nflow.set('last_time', time);\n\nreturn {\n payload: Math.round(time.getTime() / 1000),\n topic: \"template-displays/alarm-clock/lights-out-time\",\n retain: true\n};",
"outputs": 1,
"noerr": 0,
"x": 422,
"y": 95,
"wires": [["115a9fe5.c6d5b", "baf5586.da1b9a8"]]
},
{
"id": "115a9fe5.c6d5b",
"type": "mqtt out",
"z": "7ff4fc88.583d84",
"name": "",
"topic": "",
"qos": "",
"retain": "true",
"broker": "b558af9.9ad0b5",
"x": 894,
"y": 240,
"wires": []
},
{
"id": "baf5586.da1b9a8",
"type": "debug",
"z": "7ff4fc88.583d84",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 835,
"y": 56,
"wires": []
},
{
"id": "e552d2ab.2f8d7",
"type": "inject",
"z": "7ff4fc88.583d84",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 122,
"y": 182,
"wires": [["29889c2f.a58454"]]
},
{
"id": "14b91a9a.a69d55",
"type": "function",
"z": "7ff4fc88.583d84",
"name": "Relative Time & %age MQTT messages",
"func": "const lastTime = flow.get('last_time');\nconst diff = (new Date()) - lastTime;\nconst MIN_INTERVAL = 15; // minutes\n\n// Convert to nearest INTERVAL minutes\nconst diffMins = diff / 1000 / 60;\nconst dHours = Math.floor(diffMins / 60);\nconst dMins = diffMins % 60;\nconst dMins15MinRound = Math.floor(dMins / MIN_INTERVAL) * MIN_INTERVAL;\n\nconst sleepProgress = Math.min(100, 100*(diffMins / (7*60.0)))\n\nreturn [[\n{\n payload: `${dHours}h ${dMins15MinRound}m`,\n topic: \"template-displays/alarm-clock/lights-out-time-relative\",\n retain: true\n},\n{\n payload: sleepProgress*1.0,\n topic: \"template-displays/alarm-clock/sleep-time-percent\",\n retain: true\n}\n]]",
"outputs": 1,
"noerr": 0,
"x": 435,
"y": 215,
"wires": [["baf5586.da1b9a8", "115a9fe5.c6d5b"]]
},
{
"id": "edad0a89.1902b8",
"type": "inject",
"z": "7ff4fc88.583d84",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "300",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 128,
"y": 259,
"wires": [["14b91a9a.a69d55"]]
},
{
"id": "6eaa4a54.4190d4",
"type": "mqtt in",
"z": "7ff4fc88.583d84",
"name": "",
"topic": "template-displays/bart/+",
"qos": "2",
"datatype": "auto",
"broker": "b558af9.9ad0b5",
"x": 138,
"y": 362,
"wires": [["ec6fa3dd.094a"]]
},
{
"id": "ec6fa3dd.094a",
"type": "function",
"z": "7ff4fc88.583d84",
"name": "Filter relevant values",
"func": "const FORWARDED_VARS = [\n 'forecast_high',\n 'forecast_low',\n 'forecast_temp',\n 'weather_icon',\n 'outside_temp',\n 'sf_forecast_temp'\n];\n\nconst topicParts = msg.topic.split('/');\nconst variable = topicParts[topicParts.length - 1];\n\nif (FORWARDED_VARS.includes(variable)) {\n msg.topic = `template-displays/alarm-clock/${variable}`;\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"x": 441,
"y": 358,
"wires": [["baf5586.da1b9a8", "115a9fe5.c6d5b"]]
},
{
"id": "b558af9.9ad0b5",
"type": "mqtt-broker",
"z": "",
"name": "",
"broker": "my=-broker",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
}
]