『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 1876|回复: 2

[流程系列] nodered配合小度,对网课在家的小朋友使用TTS播放课程表

[复制链接]

1

主题

30

帖子

259

积分

中级会员

Rank: 3Rank: 3

积分
259
金钱
229
HASS币
0
发表于 2022-12-16 10:54:16 | 显示全部楼层 |阅读模式
本帖最后由 bowen666 于 2022-12-16 14:14 编辑

使用场景:按课程表,定时播放指定的课程内容,上下课
使用条件:小度音箱dlna
原理:根据指定时间输出不同的内容,比如星期一的8:20提醒开始上语文课 9:00提醒下课
流程图:
微信图片_20221216104935.png

[{"id":"f9d1fe75cc692816","type":"function","z":"1222e09262d4b4b6","name":"判断时间","func":"//检测每分钟的前5秒\nvar date=new Date();\nvar hours = date.getHours();\nvar minutes = date.getMinutes();\nvar sec=date.getSeconds();\nvar week = date.getDay();\n\nif (sec > 0 && sec <= 5) {\n    //0是星期天\n    if (week == 1 || week == 2 || week == 3 || week == 4 || week == 5) {\n        if (hours == 7 && minutes == 40) {\n            msg.payload = "处理";\n        }\n        else if (hours == 8 && minutes == 10) {\n            msg.payload = "处理";\n        }\n        if (hours == 8 && minutes == 20) {\n            msg.payload = "处理";\n        }\n        else if (hours == 9 && minutes == 0) {\n            msg.payload = "处理";\n        }\n        else if (hours == 9 && minutes == 30) {\n            msg.payload = "处理";\n        }\n        else if (hours == 10 && minutes == 10) {\n            msg.payload = "处理";\n        }\n        else if (hours == 10 && minutes == 40) {\n            msg.payload = "处理";\n        }\n        else if (hours == 11 && minutes == 20) {\n            msg.payload = "处理";\n        }\n        else if (hours == 13 && minutes == 50) {\n            msg.payload = "处理";\n        }\n        else if (hours == 14 && minutes == 20) {\n            msg.payload = "处理";\n        }\n        else if (hours == 14 && minutes == 30) {\n            msg.payload = "处理";\n        }\n        else if (hours == 15 && minutes == 10) {\n            msg.payload = "处理";\n        }\n        else if (hours == 15 && minutes == 40) {\n            msg.payload = "处理";\n        }\n        else if (hours == 16 && minutes == 20) {\n            msg.payload = "处理";\n        }\n        else if (hours == 16 && minutes == 50) {\n            msg.payload = "处理";\n        }\n        else if (hours == 17 && minutes == 30) {\n            msg.payload = "处理";\n        }\n        else {\n            msg.payload = "不处理";\n        }\n    }\n    else {\n        msg.payload = "不处理";\n    }\n}\nelse {\n    msg.payload = "不处理";\n}\n\n\n\n\n//msg.payload = str + 时分 + ",准备上,"  + "课"\n//msg.payload=时分;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":100,"wires":[["4d960a290ed8a311"]]},{"id":"558bc4d43b2a18b4","type":"inject","z":"1222e09262d4b4b6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":100,"wires":[["f9d1fe75cc692816"]]},{"id":"db1f3d16a624dbb5","type":"debug","z":"1222e09262d4b4b6","name":"debug 处理","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":60,"wires":[]},{"id":"4d960a290ed8a311","type":"switch","z":"1222e09262d4b4b6","name":"判断处理","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"处理","vt":"str"},{"t":"eq","v":"不处理","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":420,"y":100,"wires":[["e1b41995b3f8ae9f","db1f3d16a624dbb5"],[]]},{"id":"eabcdf51e9581d86","type":"debug","z":"1222e09262d4b4b6","name":"debug 不处理","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":120,"wires":[]},{"id":"9a03c9ed945d34c6","type":"comment","z":"1222e09262d4b4b6","name":"课程表tts","info":"","x":100,"y":20,"wires":[]},{"id":"290c38dd614eb4e1","type":"debug","z":"1222e09262d4b4b6","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":460,"wires":[]},{"id":"9d967535f1ea1778","type":"switch","z":"1222e09262d4b4b6","name":"playing","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"playing","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":240,"wires":[["3a2c757e05918bf8"]]},{"id":"f2eeafcbe1de4661","type":"switch","z":"1222e09262d4b4b6","name":"idle","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"idle","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":450,"y":280,"wires":[["42dc574441f0c002"]]},{"id":"3a2c757e05918bf8","type":"api-call-service","z":"1222e09262d4b4b6","name":"先发个恩,改变播放状态","server":"176a6104.28316f","version":5,"debugenabled":false,"domain":"tts","service":"edge_tts_say","areaId":[],"deviceId":[],"entityId":["media_player.xiao_du_zhi_neng_yin_xiang_7125"],"data":"{\t   "message":"恩",\t   "language":"zh-CN-XiaoyiNeural",\t   "options":{"volume":"10"}\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":690,"y":240,"wires":[["42dc574441f0c002"]]},{"id":"9f8e0f2a4121e055","type":"api-call-service","z":"1222e09262d4b4b6","name":"小度tts","server":"176a6104.28316f","version":5,"debugenabled":false,"domain":"tts","service":"edge_tts_say","areaId":[],"deviceId":[],"entityId":["media_player.xiao_du_zhi_neng_yin_xiang_7125"],"data":"{\t   "message":payload,\t   "language":"zh-CN-XiaoyiNeural"\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":450,"y":480,"wires":[["3bd08e8b86219f4d"]]},{"id":"3bd08e8b86219f4d","type":"delay","z":"1222e09262d4b4b6","name":"","pauseType":"delay","timeout":"6","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":600,"y":500,"wires":[["39cbdfb5000699ad"]]},{"id":"39cbdfb5000699ad","type":"api-call-service","z":"1222e09262d4b4b6","name":"调整音量到0.5","server":"176a6104.28316f","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":["b31ba5534329f685561a84201e05c803"],"entityId":["media_player.xiao_du_zhi_neng_yin_xiang_7125"],"data":"{\t    "volume_level": "0.5"\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":760,"y":500,"wires":[[]]},{"id":"42dc574441f0c002","type":"function","z":"1222e09262d4b4b6","name":"再判断课程表","func":"var a = new Array("日", "一", "二", "三", "四", "五", "六");\nvar date = new Date();\nvar week=date.getDay();\n//var week = new Date().getDay();\nvar str = "今天星期" + a[week] + ",";\nvar hours = date.getHours();\nvar minutes = date.getMinutes();\nvar 时分 = hours.toString() + "点" + minutes.toString() + "分";\nvar 星期一课程表 = new Array("语文", "数学", "数学", "数学", "语文");\nvar 星期二课程表 = new Array("数学", "语文", "体育", "语文", "数学");\nvar 星期三课程表 = new Array("语文", "数学", "数学", "音乐", "语文");\nvar 星期四课程表 = new Array("数学", "语文", "语文", "语文", "数学");\nvar 星期五课程表 = new Array("语文", "数学", "数学", "美术", "语文");\nvar 今天课程\nvar 星期时分课程 = str + "现在是" + 时分 + ",接下来的课程是,"\n//判断星期\nswitch (week) {\n    case 1: 今天课程 = 星期一课程表;\n        break\n    case 2: 今天课程 = 星期二课程表;\n        break\n    case 3: 今天课程 = 星期三课程表;\n        break\n    case 4: 今天课程 = 星期四课程表;\n        break\n    case 5: 今天课程 = 星期五课程表;\n        break\n\n}\n\n//判断时间\n\n    if (hours == 7 && minutes == 40) {\n        msg.payload = 星期时分课程 + "早读" + ","\n    }\n    else if (hours == 8 && minutes == 10) {\n        msg.payload = "下课了,休息一会儿吧!"\n    }\n    if (hours == 8 && minutes == 20) {\n        msg.payload = 星期时分课程 + 今天课程[0] + ","\n    }\n    else if (hours == 9 && minutes == 0) {\n        msg.payload = "下课了,休息一会儿吧!"\n    }\n    else if (hours == 9 && minutes == 30) {\n        msg.payload = 星期时分课程 + 今天课程[1] + ","\n    }\n    else if (hours == 10 && minutes == 10) {\n        msg.payload = "下课了,休息一会儿吧!,去做做运动吧!"\n    }\n    else if (hours == 10 && minutes == 40) {\n        msg.payload = 星期时分课程 + 今天课程[2] + ","\n    }\n    else if (hours == 11 && minutes == 20) {\n        msg.payload = "放学了,记得写作业!"\n    }\n    else if (hours == 13 && minutes == 50) {\n        msg.payload = 星期时分课程 + "练字" + ","\n    }\n    else if (hours == 14 && minutes == 20) {\n        msg.payload = "下课了,休息一会儿吧!"\n    }\n    else if (hours == 14 && minutes == 30) {\n        msg.payload = 星期时分课程 + 今天课程[3] + ","\n    }\n    else if (hours == 15 && minutes == 10) {\n        msg.payload = "下课了,休息一会儿吧!"\n    }\n    else if (hours == 15 && minutes == 40) {\n        msg.payload = 星期时分课程 + 今天课程[4] + ","\n    }\n    else if (hours == 16 && minutes == 20) {\n        msg.payload = "下课了,休息一会儿吧!"\n    }\n    else if (hours == 16 && minutes == 50) {\n        msg.payload = 星期时分课程 + "亲子阅读" + ","\n    }\n    else if (hours == 17 && minutes == 30) {\n        msg.payload = "放学了,记得写作业!"\n    }\n    else {\n        msg.payload="不处理";\n    }\n//msg.payload = str + 时分 + ",准备上,"  + "课"\n//msg.payload=时分;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":140,"y":400,"wires":[["ef93f5d874eeea56"]]},{"id":"e1b41995b3f8ae9f","type":"api-current-state","z":"1222e09262d4b4b6","name":"获取小度的播放状态","server":"176a6104.28316f","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"media_player.xiao_du_zhi_neng_yin_xiang_7125","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":180,"y":240,"wires":[["9d967535f1ea1778","f2eeafcbe1de4661"]]},{"id":"0fbe2226d46a83c8","type":"debug","z":"1222e09262d4b4b6","name":"debug 18","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":460,"y":200,"wires":[]},{"id":"ef93f5d874eeea56","type":"switch","z":"1222e09262d4b4b6","name":"处理","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"不处理","vt":"str"},{"t":"eq","v":"不处理","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":400,"wires":[["3d33ea48738d4603"],[]]},{"id":"3d33ea48738d4603","type":"api-call-service","z":"1222e09262d4b4b6","name":"调整音量到0.9","server":"176a6104.28316f","version":5,"debugenabled":false,"domain":"media_player","service":"volume_set","areaId":[],"deviceId":["b31ba5534329f685561a84201e05c803"],"entityId":["media_player.xiao_du_zhi_neng_yin_xiang_7125"],"data":"{\t    "volume_level": "0.9"\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":480,"y":400,"wires":[["9f8e0f2a4121e055"]]},{"id":"176a6104.28316f","type":"server","name":"Home Assistant","addon":true}]
flows.rar (2.55 KB, 下载次数: 29)

回复

使用道具 举报

20

主题

266

帖子

1884

积分

金牌会员

Rank: 6Rank: 6

积分
1884
金钱
1618
HASS币
0
发表于 2022-12-16 13:25:47 | 显示全部楼层
能分享个文件吗?代码导入提示错误
回复

使用道具 举报

1

主题

30

帖子

259

积分

中级会员

Rank: 3Rank: 3

积分
259
金钱
229
HASS币
0
 楼主| 发表于 2022-12-16 14:15:27 | 显示全部楼层
kaka0992 发表于 2022-12-16 13:25
能分享个文件吗?代码导入提示错误

好的 试试文件导入到nodered
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-23 04:21 , Processed in 0.050881 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表