[{"id":"b5e0e3d8a2040c40","type":"tab","label":"AI生成提示语","disabled":false,"info":"","env":[]},{"id":"0e49a82962811afa","type":"api-call-service","z":"b5e0e3d8a2040c40","name":"小爱音箱播放文本","server":"4b8a1c75bb43f078","version":5,"debugenabled":false,"domain":"text","service":"set_value","areaId":[],"deviceId":[],"entityId":["text.xiaomi_lx06_e22b_play_text"],"data":"{"value":msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":970,"y":360,"wires":[[]]},{"id":"baab6869f11684c5","type":"inject","z":"b5e0e3d8a2040c40","name":"测试","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"open_person":"周杰伦"}","payloadType":"json","x":90,"y":420,"wires":[["d635d2c40c739ee7"]]},{"id":"d635d2c40c739ee7","type":"function","z":"b5e0e3d8a2040c40","name":"设置提示词Prompt","func":"\nconst address = '广州市广州塔';\nconst person = msg.payload.open_person;\nconst prompt = `我家在${address},结合当地的天气,得出当前${person}开门回家的原因,\n写一段非常温馨俏皮的欢迎词,不要输出地址信息,字数限制在60到90字之间`;\nmsg.payload=prompt;\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":360,"wires":[["f5c7a5c2.1a3d58"]]},{"id":"f5c7a5c2.1a3d58","type":"function","z":"b5e0e3d8a2040c40","name":"设置请求参数","func":"// 设置 API 请求参数\nmsg.payload = {\n "model": "qwen-plus-2025-04-28", // 模型名称\n "messages": [\n {"role": "user", "content": msg.payload}\n ],\n "temperature": 0.7, // 随机性参数\n "max_tokens": 200 // 最大响应长度\n};\n\n// 设置请求头(根据实际 API 要求修改)\nmsg.headers = {\n "Content-Type": "application/json",\n "Authorization": "Bearer sk-xxxxx" // 替换为你的 API 密钥\n};\n\n// 设置请求 URL(根据实际 API 地址修改)\nmsg.url = "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions"; // 示例 API 地址\nmsg.method = "POST"; // 通常为 POST 方法\n\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":360,"wires":[["a1d7c3e6.8f2b4"]]},{"id":"a1d7c3e6.8f2b4","type":"http request","z":"b5e0e3d8a2040c40","name":"调用 AI API","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":630,"y":360,"wires":[["e3b2d1c8.9a7f2"]]},{"id":"e3b2d1c8.9a7f2","type":"function","z":"b5e0e3d8a2040c40","name":"处理响应结果","func":"// 解析 API 响应,提取需要的内容\nif (msg.payload && msg.payload.choices && msg.payload.choices.length > 0) {\n // 提取模型返回的内容\n msg.payload = msg.payload.choices[0].message.content;\n} else {\n // 处理错误情况\n msg.payload = "API 调用失败: " + (msg.payload?.error?.message || "未知错误");\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":360,"wires":[["0e49a82962811afa","277ff8cb8af7b464"]]},{"id":"53c9f68e1d24d1e9","type":"comment","z":"b5e0e3d8a2040c40","name":"调用大模型-API KEY","info":"","x":530,"y":320,"wires":[]},{"id":"3b0fe69064e73ab1","type":"link in","z":"b5e0e3d8a2040c40","name":"输出到AI大模型","links":[],"x":125,"y":320,"wires":[["d635d2c40c739ee7"]]},{"id":"5a3f264a5296de77","type":"server-state-changed","z":"b5e0e3d8a2040c40","name":"门锁输入","server":"4b8a1c75bb43f078","version":5,"outputs":1,"exposeAsEntityConfig":"","entityId":"input_text.lock_record01","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":180,"y":160,"wires":[["14ca5923ddeb3d5c","d635d2c40c739ee7"]]},{"id":"14ca5923ddeb3d5c","type":"debug","z":"b5e0e3d8a2040c40","name":"debug 31","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":520,"y":160,"wires":[]},{"id":"277ff8cb8af7b464","type":"debug","z":"b5e0e3d8a2040c40","name":"大模型输出结果","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":280,"wires":[]},{"id":"4b8a1c75bb43f078","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":true,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":": ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"default","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
导入之后做如下动作: