TEST12222222
TESThttps://flows.nodered.org/add/flow#
[{"id":"aqara_cube_flow","type":"tab","label":"Aqara T1 Pro 控制流程","disabled":false,"info":"Aqara 魔方 T1 Pro 控制流程"},{"id":"event_listener","type":"server-events","z":"aqara_cube_flow","name":"監聽魔方事件","server":"server","event_type":"state_changed","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":130,"y":120,"wires":[["filter_cube_events"]]},{"id":"filter_cube_events","type":"switch","z":"aqara_cube_flow","name":"過濾魔方事件","property":"data.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"sensor.aqara_cube_t1_pro_abc123","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":310,"y":120,"wires":[["get_cube_action"]]},{"id":"get_cube_action","type":"function","z":"aqara_cube_flow","name":"獲取動作類型","func":"// 確保狀態已更改才處理\nif (msg.data && msg.data.new_state && msg.data.old_state) {\n // 獲取魔方動作\n const action = msg.data.new_state.state;\n // 添加動作類型到消息中\n msg.action = action;\n // 添加時間戳記,用於延遲檢測\n msg.timestamp = Date.now();\n return msg;\n}\nreturn null;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":120,"wires":[["action_debounce"]]},{"id":"action_debounce","type":"function","z":"aqara_cube_flow","name":"動作防抖處理","func":"// 獲取節點上下文\nconst context = context || {};\ncontext.lastAction = context.lastAction || \"\";\ncontext.lastTimestamp = context.lastTimestamp || 0;\n\n// 獲取當前信息\nconst currentAction = msg.action;\nconst currentTimestamp = msg.timestamp;\n\n// 設置防抖延遲(毫秒)\nconst debounceDelay = 800;\n\n// 檢查是否在延遲時間內\nif (currentTimestamp - context.lastTimestamp < debounceDelay) {\n // 如果與上次動作相同或太接近時間,不處理\n return null;\n}\n\n// 更新上下文信息\ncontext.lastAction = currentAction;\ncontext.lastTimestamp = currentTimestamp;\n\n// 允許動作繼續處理\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":120,"wires":[["action_switch"]]},{"id":"action_switch","type":"switch","z":"aqara_cube_flow","name":"動作判斷","property":"action","propertyType":"msg","rules":[{"t":"eq","v":"flip90","vt":"str"},{"t":"eq","v":"flip180","vt":"str"},{"t":"eq","v":"rotate","vt":"str"},{"t":"eq","v":"slide","vt":"str"},{"t":"eq","v":"tap","vt":"str"},{"t":"eq","v":"shake","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":880,"y":120,"wires":[["flip90_action"],["flip180_action"],["rotate_action"],["slide_action"],["tap_action"],["shake_action"]]},{"id":"flip90_action","type":"api-call-service","z":"aqara_cube_flow","name":"翻轉90°動作","server":"server","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.flip90_switch"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1100,"y":60,"wires":[["action_notification"]]},{"id":"flip180_action","type":"api-call-service","z":"aqara_cube_flow","name":"翻轉180°動作","server":"server","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.flip180_switch"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1100,"y":100,"wires":[["action_notification"]]},{"id":"rotate_action","type":"api-call-service","z":"aqara_cube_flow","name":"旋轉動作","server":"server","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.rotate_switch"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1100,"y":140,"wires":[["action_notification"]]},{"id":"slide_action","type":"api-call-service","z":"aqara_cube_flow","name":"滑動動作","server":"server","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.slide_switch"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1100,"y":180,"wires":[["action_notification"]]},{"id":"tap_action","type":"api-call-service","z":"aqara_cube_flow","name":"敲擊動作","server":"server","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.tap_switch"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1100,"y":220,"wires":[["action_notification"]]},{"id":"shake_action","type":"api-call-service","z":"aqara_cube_flow","name":"搖晃動作","server":"server","version":5,"debugenabled":false,"domain":"switch","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.shake_switch"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1100,"y":260,"wires":[["action_notification"]]},{"id":"action_notification","type":"api-call-service","z":"aqara_cube_flow","name":"通知動作執行","server":"server","version":5,"debugenabled":false,"domain":"persistent_notification","service":"create","areaId":[],"deviceId":[],"entityId":[],"data":"{\"title\":\"Aqara 魔方動作\",\"message\":\"執行了 {{action}} 動作\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1310,"y":120,"wires":[[]]}]