-
Notifications
You must be signed in to change notification settings - Fork 2
/
flows.json
344 lines (344 loc) · 11.9 KB
/
flows.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
[
{
"id": "9a231541.649cf8",
"type": "tab",
"label": "德业除湿机器",
"disabled": false,
"info": ""
},
{
"id": "faa01185.4163e",
"type": "mqtt in",
"z": "9a231541.649cf8",
"name": "德业除湿机状态接受",
"topic": "/status/hex",
"qos": "0",
"datatype": "json",
"broker": "6792a04d.5d64c",
"nl": false,
"rap": true,
"rh": 0,
"x": 170,
"y": 160,
"wires": [
[
"db2042d3.304",
"97bcee90.9958e"
]
]
},
{
"id": "f2078c90.cb02e",
"type": "debug",
"z": "9a231541.649cf8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 590,
"y": 160,
"wires": []
},
{
"id": "eaaae109.2aef2",
"type": "mqtt out",
"z": "9a231541.649cf8",
"name": "德业除湿机命令发送",
"topic": "/command/hex",
"qos": "0",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "6792a04d.5d64c",
"x": 600,
"y": 400,
"wires": []
},
{
"id": "432bd4f4.1fd1ac",
"type": "function",
"z": "9a231541.649cf8",
"name": "设置命令",
"func": "// var buf = Buffer.from(\"080201001e0000000000\",\"hex\");\n// msg.payload = buf;\n\nvar power_status_hex_str = flow.get(\"power_status_hex_str\");\nvar fan_level_hex_str = flow.get(\"fan_level_hex_str\");\nvar device_mode_hex_str = flow.get(\"device_mode_hex_str\");\nvar target_humidity_hex_str = flow.get(\"target_humidity_hex_str\");\n\nif (msg.topic === \"cmnd/dehumidifier/deye1/power\") {\n // 开关机\n if (msg.payload === \"ON\") {\n // 设置开机\n if (power_status_hex_str === \"0\"){\n // 如果是普通关机状态,则变为普通开机状态\n power_status_hex_str = \"1\";\n } else if (power_status_hex_str === \"6\"){\n // 如果是童锁关机状态,则变为童锁开机状态\n power_status_hex_str = \"7\";\n } else {\n return null;\n }\n } else {\n // 设置关机\n if (power_status_hex_str === \"1\" || power_status_hex_str === \"B\" ){\n // 如果是普通开机或者有定时关机的开机状态,则变为普通关机状态\n power_status_hex_str = \"0\";\n } else if (power_status_hex_str === \"6\"){\n // 如果是童锁开机状态,则变为童锁关机状态\n power_status_hex_str = \"7\";\n } else {\n return null;\n }\n }\n} else if (msg.topic === \"cmnd/dehumidifier/deye1/humidity\") {\n var h_dec = parseInt(msg.payload);\n target_humidity_hex_str = h_dec.toString(16);\n if(target_humidity_hex_str.length === 1) {\n target_humidity_hex_str = \"0\"+target_humidity_hex_str;\n }\n} else if (msg.topic === \"cmnd/dehumidifier/deye1/mode\") {\n if(msg.payload === \"manual\") {\n device_mode_hex_str = \"0\";\n } else if (msg.payload === \"laundry\") {\n device_mode_hex_str = \"1\";\n }\n}\n\nvar newmsg = {};\nnewmsg.payload = Buffer.from(\"08020\"+power_status_hex_str+fan_level_hex_str+device_mode_hex_str+target_humidity_hex_str+\"0000000000\",\"hex\");\nreturn newmsg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 480,
"wires": [
[
"b0237a33.481968",
"eaaae109.2aef2"
]
]
},
{
"id": "db2042d3.304",
"type": "function",
"z": "9a231541.649cf8",
"name": "解析状态",
"func": "var data = msg.payload.data;\n\n// 这个几个状态需要额外共享给命令设置\nvar power_status_hex_str = data.substr(5,1);\nvar fan_level_hex_str = data.substr(8,1);\nvar device_mode_hex_str = data.substr(9,1);\nvar target_humidity_hex_str = data.substr(10,2);\n\nflow.set(\"power_status_hex_str\", power_status_hex_str);\nif (fan_level_hex_str !== \"0\") {\n flow.set(\"fan_level_hex_str\", fan_level_hex_str);\n}\nflow.set(\"device_mode_hex_str\", device_mode_hex_str);\nflow.set(\"target_humidity_hex_str\", target_humidity_hex_str);\n\nvar fan_status_dec = parseInt(data.substr(4,1),16);\nvar power_status_dec = parseInt(power_status_hex_str,16);\nvar device_status_dec = parseInt(data.substr(7,1),16);\nvar fan_level_dec = parseInt(fan_level_hex_str,16);\nvar device_mode_dec = parseInt(device_mode_hex_str,16);\nvar target_humidity_dec = parseInt(target_humidity_hex_str,16);\nvar current_humidity_dec =parseInt(data.substr(32,2),16);\nvar current_temperature_dec = parseInt(data.substr(30,2),16)-40;\n\n// power status\nvar power_status = \"ON\";\nif(power_status_dec===1 || power_status_dec===11 || power_status_dec===7){\n power_status = \"ON\";\n} else {\n power_status = \"OFF\";\n}\n\n// water tank\nvar water_full = \"OFF\";\nif(fan_status_dec === 4) {\n water_full = \"ON\";\n}\n\n// fan status\nvar fan_status = \"OFF\";\nif(fan_status_dec === 8) {\n fan_status = \"ON\";\n}\n\n// device status 压缩机状态\nvar device_status = \"OFF\";\nif(device_status_dec === 8) {\n device_status = \"ON\";\n}\n\n// device mode\nvar device_mode = \"manual\";\nif(device_mode_dec === 0) {\n device_mode = \"manual\";\n} else if(device_mode_dec === 1) {\n device_mode = \"laundry\";\n}\n\nvar payload = {\n \"power_status\":power_status,\n \"water_full\":water_full,\n \"fan_status\":fan_status,\n \"device_status\":device_status,\n \"fan_level\":fan_level_dec,\n \"device_mode\":device_mode,\n \"target_humidity\":target_humidity_dec,\n \"current_humidity\":current_humidity_dec,\n \"current_temperature\":current_temperature_dec\n};\nvar newmsg = {};\nnewmsg.payload=payload;\nreturn newmsg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 420,
"y": 160,
"wires": [
[
"f2078c90.cb02e",
"94718caf.c7d93"
]
]
},
{
"id": "94718caf.c7d93",
"type": "mqtt out",
"z": "9a231541.649cf8",
"name": "状态转发",
"topic": "stat/dehumidifier/deye1/state",
"qos": "1",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "e41cf4ef.9d8f88",
"x": 600,
"y": 220,
"wires": []
},
{
"id": "f3f23877.370f68",
"type": "mqtt in",
"z": "9a231541.649cf8",
"name": "开关设置",
"topic": "cmnd/dehumidifier/deye1/power",
"qos": "2",
"datatype": "auto",
"broker": "e41cf4ef.9d8f88",
"nl": false,
"rap": true,
"rh": 0,
"x": 140,
"y": 480,
"wires": [
[
"3babc107.278a8e",
"432bd4f4.1fd1ac"
]
]
},
{
"id": "3babc107.278a8e",
"type": "debug",
"z": "9a231541.649cf8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 370,
"y": 640,
"wires": []
},
{
"id": "6eadadc0.c49fa4",
"type": "mqtt in",
"z": "9a231541.649cf8",
"name": "湿度设置",
"topic": "cmnd/dehumidifier/deye1/humidity",
"qos": "2",
"datatype": "auto",
"broker": "e41cf4ef.9d8f88",
"nl": false,
"rap": true,
"rh": 0,
"x": 140,
"y": 560,
"wires": [
[
"432bd4f4.1fd1ac",
"3babc107.278a8e"
]
]
},
{
"id": "f072ae40.cd11e",
"type": "mqtt in",
"z": "9a231541.649cf8",
"name": "模式设置",
"topic": "cmnd/dehumidifier/deye1/mode",
"qos": "2",
"datatype": "auto",
"broker": "e41cf4ef.9d8f88",
"nl": false,
"rap": true,
"rh": 0,
"x": 140,
"y": 640,
"wires": [
[
"432bd4f4.1fd1ac",
"3babc107.278a8e"
]
]
},
{
"id": "97bcee90.9958e",
"type": "debug",
"z": "9a231541.649cf8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 410,
"y": 80,
"wires": []
},
{
"id": "13c0e4e8.5030cb",
"type": "inject",
"z": "9a231541.649cf8",
"name": "自动刷新",
"props": [],
"repeat": "15",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 140,
"y": 400,
"wires": [
[
"ae5a796a.40db18"
]
]
},
{
"id": "ae5a796a.40db18",
"type": "function",
"z": "9a231541.649cf8",
"name": "刷新命令",
"func": "msg.payload = Buffer.from(\"0001\",\"hex\");\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 360,
"y": 400,
"wires": [
[
"eaaae109.2aef2",
"b052e44f.1ee688"
]
]
},
{
"id": "b052e44f.1ee688",
"type": "debug",
"z": "9a231541.649cf8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 550,
"y": 320,
"wires": []
},
{
"id": "b0237a33.481968",
"type": "debug",
"z": "9a231541.649cf8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 550,
"y": 480,
"wires": []
},
{
"id": "6792a04d.5d64c",
"type": "mqtt-broker",
"name": "deye",
"broker": ".mqtt.iot.gz.baidubce.com",
"port": "1883",
"tls": "",
"clientid": "",
"usetls": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": false,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
},
{
"id": "e41cf4ef.9d8f88",
"type": "mqtt-broker",
"name": "",
"broker": "192.168.1.x",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": false,
"protocolVersion": "4",
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"birthMsg": {},
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"closeMsg": {},
"willTopic": "",
"willQos": "0",
"willPayload": "",
"willMsg": {},
"sessionExpiry": ""
}
]