智能系统 篇一:#homeassistant# 帮我做个决定吧!拥抱NodeRED之自动随机回答TTS给小爱音箱

2024-04-02 09:43:12 1点赞 15收藏 0评论

在homeassistant中NodeRED是必不可少的工具之一,Node-RED提供了一种可视化的方式来创建自动化流程,而Home Assistant则提供了广泛的智能家居设备支持和自动化功能。结合两者,可以实现更复杂、更灵活的智能家居控制和自动化,在往后的教程中我会提到各类品牌,如米家、涂鸦等利于平台从而得到全屋贯通智能

其中在Home Assistant中使用Node-RED有几个主要优点:

  • 可视化编程: Node-RED提供了一个直观的用户界面,让用户可以通过拖拽节点、连接它们来创建自动化流程,而不需要深入编程知识。这使得创建复杂的自动化变得更加容易和直观。

  • 丰富的节点库: Node-RED社区开发了大量的节点,涵盖了各种各样的功能和设备。在Home Assistant中,这些节点可以与Home Assistant的实体进行交互,包括传感器、开关、灯光等,从而实现更多样化的自动化场景。

  • 灵活性: 通过Node-RED,用户可以更加灵活地定制自己的自动化流程。无论是简单的条件触发还是复杂的逻辑判断,都可以通过Node-RED的节点来实现。

  • 与其他服务的集成: 除了与Home Assistant的集成外,Node-RED还可以轻松地集成其他云服务和第三方平台,例如IFTTT、Twitter、Facebook等,从而实现更多样化的自动化场景。

  • 实时调试和监控: Node-RED提供了实时的调试和监控功能,可以帮助用户快速定位和解决问题,提高自动化流程的稳定性和可靠性。

    下面图片包含以下几个节点:

    1. Inject 节点 (3bc2f45862550d42):用于触发流程的启动,你可以在这里配置触发流程的条件或时间。

    2. Function 节点 (2999211792721746):通过 JavaScript 编写的函数,用于生成随机的洗碗任务,并将其作为消息的 payload 返回。函数内部定义了一个包含了三个任务的数组 tasks,然后根据随机数来选择一个任务,确保了不同的任务被选中的几率相等。

    3. API 调用服务节点 (ccfc6ff3d22fad18):用于调用 Home Assistant 中的服务,这里是调用 text.set_value 服务来将随机选中的洗碗任务发送到指定的实体 text.xiaomi_l17a_331c_play_text

    4. Home Assistant 服务器节点 (22e610f8da6c05ed):用于连接到 Home Assistant 服务器,配置了连接信息和一些选项。

效果展示图效果展示图

今天谁洗碗代码(为了保证公平性,增加了老婆的洗碗次数)

[{"id":"2999211792721746","type":"function","z":"cf80b3dcfcbe8e68","name":"到底谁洗碗","func":"var tasks = [n "我洗碗",n "今天都别洗",n "老婆洗碗"n];nnvar randomIndex;nnvar randomNumber = Math.floor(Math.random() 4);nnif (randomNumber === 0) {n randomIndex = 2; n} else {n randomIndex = Math.floor(Math.random() 3);n}nnmsg.payload = tasks[randomIndex];nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":460,"wires":[["ccfc6ff3d22fad18"]]},{"id":"3bc2f45862550d42","type":"inject","z":"cf80b3dcfcbe8e68","name":"这里可以用hass实体比如button、switch","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":460,"wires":[["2999211792721746"]]},{"id":"ccfc6ff3d22fad18","type":"api-call-service","z":"cf80b3dcfcbe8e68","name":"","server":"22e610f8da6c05ed","version":5,"debugenabled":false,"domain":"text","service":"set_value","areaId":[],"deviceId":[],"entityId":["text.xiaomi_l17a_331c_play_text"],"data":"{"value":msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":680,"y":460,"wires":[[]]},{"id":"22e610f8da6c05ed","type":"server","name":"Home Assistant API","version":5,"addon":false,"rejectUnauthorizedCerts":false,"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}]

今天吃什么喝什么(可以调整概率性,比如想减肥)

[{"id":"574288d8.f53128","type":"function","z":"cf80b3dcfcbe8e68","name":"今天吃什么喝什么","func":"var dishes = [n "烤鸭",n "炸酱面",n "豆汁",n "凉面",n "油糕",n "炒肝儿",n "京酱肉丝",n "京酱面",n "打卤面",n "糖火烧",n "京酱焖肉",n "小笼包",n "生煎包",n "上海菜",n "别吃了!",n "上海面食",n "酱油蟹",n "粽子",n "蟹黄包",n "面点",n "各种盖饭",n "江菜",n "本帮菜",n "烧腊",n "点心",n "广东菜",n "海鲜",n "海底捞",n "炖品",n "粥品",n "糖水",n "广东烧味",n "广式糖水",n "广式糖水",n "火锅",n "串串香",n "川菜",n "凉菜",n "担担面",n "麻辣香锅",n "麻辣火锅",n "水煮鱼",n "酸辣粉",n "四川小吃",n "火锅",n "重庆小面",n "四川火锅",n "串串香",n "酸辣粉",n "重庆小吃",n "重庆火锅",n "渝菜",n "辣子鸡",n "鲜榨果汁",n "煎饼果子",n "炸串",n "炸鸡",n "炒饭",n "烤串",n "水饺",n "香肠",n "油条",n "麻辣烫",n "牛肉面",n "东北大烩菜",n "焖面",n "鸡架",n "锅包肉",n "涮羊肉",n "东北酸菜",n "冻酸奶",n "卤肉饼",n "卤煮",n "驴肉火烧",n "羊肉泡馍",n "肉夹馍",n "凉皮",n "腊汁肉夹馍",n "西安小吃",n "油泼面",n "擀面皮",n "莜面饸饹",n "酸菜鱼",n "板面",n "油焖笋",n "甜皮鸭",n "砂锅粥",n "醉鸭",n "酸笋鱼",n "糍粑",n "萝卜丝饼",n "鸭脖",n "宫保鸡丁盖饭",n "鱼香肉丝盖饭",n "麻婆豆腐盖饭",n "青椒肉丝盖饭",n "鸡蛋番茄盖饭",n "土豆牛肉盖饭",n "回锅肉盖饭",n "蚝油牛肉盖饭",n "红烧排骨盖饭",n "干煸豆角盖饭",n "黑椒牛柳盖饭",n "麦当劳",n "肯德基",n "汉堡王",n "必胜客",n "德克士",n "胜利家",n "华莱士",n "满记甜品",n "摩尔烤鸭",n "达美乐",n "星巴克"n];nnvar drinks = [n "水",n "可乐",n "雪碧",n "橙汁",n "苹果汁",n "什么都别喝",n "牛奶",n "咖啡",n "奶茶",n "绿茶",n "红茶",n "奶昔",n "椰子汁",n "柠檬水",n "芒果汁",n "冰咖啡",n "冰红茶",n "冰绿茶",n "冰奶茶"n];nnvar randomIndexDishes = Math.floor(Math.random() dishes.length);nvar randomIndexDrinks = Math.floor(Math.random() drinks.length);nnif (Math.random() < 0.1) {n // 10%的概率选择别吃了!n msg.payload = "今天吃: 别吃了!,今天喝: " + drinks[randomIndexDrinks];n} else if (Math.random() < 0.1) {n // 10%的概率选择什么都别喝n msg.payload = "今天吃: " + dishes[randomIndexDishes] + ",今天喝: 什么都别喝";n} else {n // 其他情况随机选择菜品和饮品n msg.payload = "今天吃: " + dishes[randomIndexDishes] + ",今天喝: " + drinks[randomIndexDrinks];n}nnreturn msg;n//减肥版","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":540,"wires":[["ccfc6ff3d22fad18"]]},{"id":"5fdfe39c.a12224","type":"inject","z":"cf80b3dcfcbe8e68","name":"这里可以用hass实体比如button、switch","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":520,"wires":[["574288d8.f53128"]]},{"id":"ccfc6ff3d22fad18","type":"api-call-service","z":"cf80b3dcfcbe8e68","name":"","server":"22e610f8da6c05ed","version":5,"debugenabled":false,"domain":"text","service":"set_value","areaId":[],"deviceId":[],"entityId":["text.xiaomi_l17a_331c_play_text"],"data":"{"value":msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":720,"y":540,"wires":[[]]},{"id":"22e610f8da6c05ed","type":"server","name":"Home Assistant API","version":5,"addon":false,"rejectUnauthorizedCerts":false,"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}]

今天穿什么颜色(娱乐版)

[{"id":"ccfc6ff3d22fad18","type":"api-call-service","z":"cf80b3dcfcbe8e68","name":"","server":"22e610f8da6c05ed","version":5,"debugenabled":false,"domain":"text","service":"set_value","areaId":[],"deviceId":[],"entityId":["text.xiaomi_l17a_331c_play_text"],"data":"{"value":msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":680,"y":600,"wires":[[]]},{"id":"c91ee1d9e90303d0","type":"function","z":"cf80b3dcfcbe8e68","name":"今天穿什么颜色","func":"var colors = [n "绿色",n "蓝色",n "粉色",n "灰色",n "白色",n "黑色",n "棕色"n];nnvar randomIndex;nif (Math.random() < 0.1) {n // 40%的概率选择裸奔n msg.payload = "啥也别选了!直接裸奔吧,这还要我选!";n} else {n // 其他情况随机选择颜色n randomIndex = Math.floor(Math.random() * (colors.length - 1)); // 排除裸奔选项n msg.payload = "今天穿什么颜色好呢?好了我帮你决定吧!今天穿" + colors[randomIndex];n}nnreturn msg;n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":600,"wires":[["ccfc6ff3d22fad18"]]},{"id":"2be8320b5dbb5905","type":"inject","z":"cf80b3dcfcbe8e68","name":"这里可以用hass实体比如button、switch","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":580,"wires":[["c91ee1d9e90303d0"]]},{"id":"22e610f8da6c05ed","type":"server","name":"Home Assistant API","version":5,"addon":false,"rejectUnauthorizedCerts":false,"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}]

感情选择器(无情版本)

[{"id":"e66c842fe84219b3","type":"function","z":"cf80b3dcfcbe8e68","name":"情趣选择器","func":"var choices = [n "要做",n "不要做",n "做不做!干我屁事!"n];nnvar randomIndex = Math.floor(Math.random() * choices.length);nvar randomChoice = choices.splice(randomIndex, 1)[0];nmsg.payload = "我觉得你们应该..." + randomChoice;nreturn msg;n//严肃版本","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":660,"wires":[["ccfc6ff3d22fad18"]]},{"id":"d8111d33dae89f55","type":"inject","z":"cf80b3dcfcbe8e68","name":"这里可以用hass实体比如button、switch","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":660,"wires":[["e66c842fe84219b3"]]},{"id":"ccfc6ff3d22fad18","type":"api-call-service","z":"cf80b3dcfcbe8e68","name":"","server":"22e610f8da6c05ed","version":5,"debugenabled":false,"domain":"text","service":"set_value","areaId":[],"deviceId":[],"entityId":["text.xiaomi_l17a_331c_play_text"],"data":"{"value":msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":660,"y":660,"wires":[[]]},{"id":"22e610f8da6c05ed","type":"server","name":"Home Assistant API","version":5,"addon":false,"rejectUnauthorizedCerts":false,"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}]

今天出去玩?(打工人版)

[{"id":"abc6bb5ee2e8790d","type":"function","z":"cf80b3dcfcbe8e68","name":"今天玩不玩?","func":"var choices = [n "出去玩,旺!",n "不出去玩!不为自己的财务自由奋斗,就要为了别人的财务自由奋斗!"n];nnvar randomIndex = Math.floor(Math.random() * choices.length);nmsg.payload = "今天出去玩不玩?" + choices[randomIndex];nreturn msg;n","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":780,"wires":[["638c89744c11682a"]]},{"id":"4d15951e693b5960","type":"inject","z":"cf80b3dcfcbe8e68","name":"这里可以用hass实体比如button、switch","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":260,"y":780,"wires":[["abc6bb5ee2e8790d"]]},{"id":"638c89744c11682a","type":"api-call-service","z":"cf80b3dcfcbe8e68","name":"","server":"22e610f8da6c05ed","version":5,"debugenabled":false,"domain":"text","service":"set_value","areaId":[],"deviceId":[],"entityId":["text.xiaomi_l17a_331c_play_text"],"data":"{"value":msg.payload}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":700,"y":780,"wires":[[]]},{"id":"22e610f8da6c05ed","type":"server","name":"Home Assistant API","version":5,"addon":false,"rejectUnauthorizedCerts":false,"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}]

以上便是所有代码分享,关注我持续带来更多智能产品和新潮玩法

我们可以想象,在智能家居的环境下,我们可以通过简单的声音或触摸指令控制整个家庭设备,实现智能化的生活体验;在智能健康监测的支持下,我们能够更好地关注自身健康状况,实现全方位的健康管理。而这一切,都离不开科技的不断创新和发展。因此,我们有理由相信,智能科技将为我们带来更加美好的未来。让我们一起紧握时代的脉搏,探索智能科技的无限可能,共同打造智能化生活的美好未来!

展开 收起

MIJIA 米家 MJYDOAYL 自动感应夜灯 白色

MIJIA 米家 MJYDOAYL 自动感应夜灯 白色

17.9元起

MIJIA 米家 1S 增强版 智能台灯 白色

MIJIA 米家 1S 增强版 智能台灯 白色

156元起

MIJIA 米家 3 智能温湿度计 白色

MIJIA 米家 3 智能温湿度计 白色

44.9元起

MIJIA 米家 空调伴侣2 智能插座 白色

MIJIA 米家 空调伴侣2 智能插座 白色

67.23元起

MIJIA 米家 Xiaomi 小米 MIJIA 米家 Xiaomi 小米 MIJIA 米家 智能生态鱼缸

MIJIA 米家 Xiaomi 小米 MIJIA 米家 Xiaomi 小米 MIJIA 米家 智能生态鱼缸

369元起

MIJIA 米家 智能宠物喂食器2

MIJIA 米家 智能宠物喂食器2

360.05元起

MIJIA 米家飞利浦台灯3「米家」

MIJIA 米家飞利浦台灯3「米家」

119元起

MIJIA 米家 台灯Pro 读写版 智能台灯 白色

MIJIA 米家 台灯Pro 读写版 智能台灯 白色

255.55元起

MIJIA 米家 DHKG02ZM 智能开关 双开单控 白色

MIJIA 米家 DHKG02ZM 智能开关 双开单控 白色

59.1元起

MIJIA 米家 台灯Lite 智能护眼台灯

MIJIA 米家 台灯Lite 智能护眼台灯

62.9元起

MIJIA 米家 WXKGO1LM 智能开关 白色

MIJIA 米家 WXKGO1LM 智能开关 白色

34.9元起

MIJIA 米家飞利浦读写台灯「米家」

MIJIA 米家飞利浦读写台灯「米家」

329元起

MIJIA 米家蓝牙温湿度计2「米家」

MIJIA 米家蓝牙温湿度计2「米家」

22.56元起

MIJIA 米家 MJTS003 蓝牙MESH版 LED筒灯 白色

MIJIA 米家 MJTS003 蓝牙MESH版 LED筒灯 白色

36.9元起

MIJIA 米家 小米 智能跳绳 XMSR-P803

MIJIA 米家 小米 智能跳绳 XMSR-P803

94元起

MIJIA 米家 MJGJDO1YL 显示器屏幕挂灯 黑色

MIJIA 米家 MJGJDO1YL 显示器屏幕挂灯 黑色

165元起
0评论

当前文章无评论,是时候发表评论了
提示信息

取消
确认
评论举报

相关好价推荐
查看更多好价

相关文章推荐

更多精彩文章
更多精彩文章
最新文章 热门文章
15
扫一下,分享更方便,购买更轻松