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

 找回密码
 立即注册
123
返回列表 发新帖
楼主: neroxps

[流程系列] 【Node-RED】 天气推送(支持3Dtouch停止推送)

[复制链接]

40

主题

3056

帖子

1万

积分

超级版主

Nero

Rank: 8Rank: 8

积分
11149
金钱
8042
HASS币
182
 楼主| 发表于 2019-7-8 17:18:52 | 显示全部楼层
fineemb 发表于 2019-7-8 16:23
我还是遇到了问题。尝试用sonos的快照功能实现暂停播放之前的音乐,然后播报tts,完成后继续播放之前的音乐 ...

我没 senos 也不知道你的快照是指什么?
Nero
回复

使用道具 举报

16

主题

217

帖子

2229

积分

论坛技术达人

积分
2229
金钱
1977
HASS币
140
发表于 2019-7-14 00:17:57 | 显示全部楼层
原来是homeassistant的节点安装错了. 终于可以优雅地使用sonos进行TTS播报了.
后面还可以设置根据不同时间进行音量调整
01.jpg


[{"id":"f509ea94.00f4e8","type":"tab","label":"sonos播报天气预警","disabled":false,"info":""},{"id":"d902b9e9.2f11c8","type":"function","z":"f509ea94.00f4e8","name":"推送内容","func":"var message = msg.payload;\nvar subtitle = "注意:" + msg.pr_data.old_state.attributes.friendly_name + "为" + msg.pr + "%";\nmsg.payload = {};\nmsg.payload.data = {"entity_id": "media_player.ban_gong_shi","message":subtitle+". "+message};\nreturn [msg,{}]; \n","outputs":2,"noerr":0,"x":420,"y":280,"wires":[["6aef6808.f41328"],["94278e64.1d56a","41af408a.37231"]]},{"id":"dda03b3e.0ae5b8","type":"api-current-state","z":"f509ea94.00f4e8","name":"分钟级概况","server":"9a56e1b1.84865","outputs":1,"halt_if":"","override_topic":true,"entity_id":"sensor.caiyun_minutely_description","override_payload":true,"x":250,"y":280,"wires":[["d902b9e9.2f11c8"]]},{"id":"eaa823dc.2a9eb","type":"server-state-changed","z":"f509ea94.00f4e8","name":"降雨概率","server":"9a56e1b1.84865","version":1,"entityidfilter":"sensor.caiyun_minutely_probability_*","entityidfiltertype":"regex","outputinitially":false,"state_type":"str","haltifstate":"60","halt_if_type":"num","halt_if_compare":"gt","outputs":2,"output_only_on_state_change":false,"x":60,"y":160,"wires":[["c67f2151.e58a1"],[]]},{"id":"84013166.8e634","type":"function","z":"f509ea94.00f4e8","name":"筛选消息","func":"// 检查全局变量,判断是否推送。\n\n//if (flow.get('notice') === false){\n//    return null;\n//}\n\nfunction compare(property){\n    return function(a,b){\n        var value1 = a[property];\n        var value2 = b[property];\n        return value1 > value2;\n    }\n}\n// 根据 entity_id 来排序,确保先检查30分钟降雨概率传感器\nmsg.data = msg.data.sort(compare('entity_id'));\n\nfor (var datas in msg.data){\n    if ( msg.data[datas].old_state.state < 60 && msg.data[datas].new_state.state > 60 ){\n        msg.pr = msg.data[datas].new_state.state;\n        msg.pr_data= msg.data[datas];\n        break; \n    }\n}\nif (!msg.pr){\n    return null;\n}\nelse{\n    return msg;\n}","outputs":1,"noerr":0,"x":240,"y":220,"wires":[["dda03b3e.0ae5b8"]]},{"id":"c67f2151.e58a1","type":"join","z":"f509ea94.00f4e8","name":"消息汇聚","mode":"custom","build":"array","property":"data","propertyType":"msg","key":"pr_all","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":240,"y":160,"wires":[["84013166.8e634"]]},{"id":"bf61adfa.7fd7d","type":"api-call-service","z":"f509ea94.00f4e8","name":"TTS","server":"9a56e1b1.84865","service_domain":"tts","service":"baidu_say","data":"{"entity_id":"media_player.ban_gong_shi"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":710,"y":240,"wires":[["fc304a2.c6a80b8"]]},{"id":"efc0df2d.cd1d6","type":"inject","z":"f509ea94.00f4e8","name":"测试","topic":"sensor.caiyun_minutely_probability_5","payload":"50","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":70,"y":80,"wires":[["9510dd8b.cdfd8","2faf76ab.cee30a"]]},{"id":"9510dd8b.cdfd8","type":"function","z":"f509ea94.00f4e8","name":"模拟数据2","func":"msg.data = {"entity_id":"sensor.caiyun_minutely_probability_4","old_state":{"entity_id":"sensor.caiyun_minutely_probability_4","state":"45","attributes":{"unit_of_measurement":"%","friendly_name":"180分钟降雨概率","icon":"mdi:weather-pouring","homebridge_hidden":true},"last_changed":"2019-07-07T02:00:23.029663+00:00","last_updated":"2019-07-07T02:00:23.029663+00:00","context":{"id":"f07d188af171494185d7b7c28c0d575a","parent_id":null,"user_id":null}},"new_state":{"entity_id":"sensor.caiyun_minutely_probability_4","state":"55","attributes":{"unit_of_measurement":"%","friendly_name":"180分钟降雨概率","icon":"mdi:weather-pouring","homebridge_hidden":true},"last_changed":"2019-07-07T02:21:40.722299+00:00","last_updated":"2019-07-07T02:21:40.722299+00:00","context":{"id":"94c939155fb44a94a92dd9ddb4330074","parent_id":null,"user_id":null}}};\nreturn msg; ","outputs":1,"noerr":0,"x":200,"y":60,"wires":[["c67f2151.e58a1"]]},{"id":"2faf76ab.cee30a","type":"function","z":"f509ea94.00f4e8","name":"模拟数据1","func":"msg.data = {"entity_id":"sensor.caiyun_minutely_probability_5","old_state":{"entity_id":"sensor.caiyun_minutely_probability_4","state":"35","attributes":{"unit_of_measurement":"%","friendly_name":"60分钟降雨概率","icon":"mdi:weather-pouring","homebridge_hidden":true},"last_changed":"2019-07-07T02:00:23.029663+00:00","last_updated":"2019-07-07T02:00:23.029663+00:00","context":{"id":"f07d188af171494185d7b7c28c0d575a","parent_id":null,"user_id":null}},"new_state":{"entity_id":"sensor.caiyun_minutely_probability_5","state":"65","attributes":{"unit_of_measurement":"%","friendly_name":"180分钟降雨概率","icon":"mdi:weather-pouring","homebridge_hidden":true},"last_changed":"2019-07-07T02:21:40.722299+00:00","last_updated":"2019-07-07T02:21:40.722299+00:00","context":{"id":"94c939155fb44a94a92dd9ddb4330074","parent_id":null,"user_id":null}}};\nreturn msg; ","outputs":1,"noerr":0,"x":200,"y":100,"wires":[["c67f2151.e58a1"]]},{"id":"601a4bb5.eb6134","type":"api-call-service","z":"f509ea94.00f4e8","name":"播放","server":"9a56e1b1.84865","service_domain":"media_player","service":"media_play","data":"{"entity_id":"media_player.ban_gong_shi"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":890,"y":440,"wires":[["ce4f9415.550e58"]]},{"id":"a43538a3.5807c8","type":"api-call-service","z":"f509ea94.00f4e8","name":"还原播放列表","server":"9a56e1b1.84865","service_domain":"sonos","service":"restore","data":"{"entity_id":"media_player.ban_gong_shi"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":580,"y":420,"wires":[["e3fb7cdb.99dec"]]},{"id":"6aef6808.f41328","type":"delay","z":"f509ea94.00f4e8","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":580,"y":240,"wires":[["bf61adfa.7fd7d"]]},{"id":"94278e64.1d56a","type":"api-call-service","z":"f509ea94.00f4e8","name":"快照播放列表","server":"9a56e1b1.84865","service_domain":"sonos","service":"snapshot","data":"{"entity_id":"media_player.ban_gong_shi"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":280,"wires":[[]]},{"id":"1c84f851.26d678","type":"server-state-changed","z":"f509ea94.00f4e8","name":"sonos播放状态改变","server":"9a56e1b1.84865","version":1,"entityidfilter":"media_player.ban_gong_shi","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":90,"y":420,"wires":[["f3793d32.80e38"]]},{"id":"f3793d32.80e38","type":"switch","z":"f509ea94.00f4e8","name":"播放停止","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"paused","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":260,"y":420,"wires":[["2a4ed87d.000298"]]},{"id":"2a4ed87d.000298","type":"switch","z":"f509ea94.00f4e8","name":"TTS播报结束","property":"tts","propertyType":"flow","rules":[{"t":"eq","v":"stop","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":410,"y":420,"wires":[["a43538a3.5807c8"]]},{"id":"fc304a2.c6a80b8","type":"function","z":"f509ea94.00f4e8","name":"设置变量","func":"flow.set("tts","stop")","outputs":1,"noerr":0,"x":840,"y":240,"wires":[[]]},{"id":"ce4f9415.550e58","type":"function","z":"f509ea94.00f4e8","name":"设置变量","func":"flow.set("tts","play")","outputs":1,"noerr":0,"x":980,"y":400,"wires":[[]]},{"id":"41af408a.37231","type":"api-current-state","z":"f509ea94.00f4e8","name":"暂停状态","server":"9a56e1b1.84865","version":1,"outputs":2,"halt_if":"paused","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.ban_gong_shi","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":580,"y":340,"wires":[["6a70523c.d54a4c"],["542c1b06.b2d354"]]},{"id":"6a70523c.d54a4c","type":"function","z":"f509ea94.00f4e8","name":"设置变量","func":"flow.set("sonos","paused")","outputs":1,"noerr":0,"x":740,"y":320,"wires":[[]]},{"id":"542c1b06.b2d354","type":"function","z":"f509ea94.00f4e8","name":"设置变量","func":"flow.set("sonos","player")","outputs":1,"noerr":0,"x":740,"y":360,"wires":[[]]},{"id":"e3fb7cdb.99dec","type":"switch","z":"f509ea94.00f4e8","name":"原来状态","property":"sonos","propertyType":"flow","rules":[{"t":"eq","v":"paused","vt":"str"},{"t":"eq","v":"player","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":760,"y":420,"wires":[["ce4f9415.550e58"],["601a4bb5.eb6134"]]},{"id":"9a56e1b1.84865","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]



回复

使用道具 举报

9

主题

205

帖子

2678

积分

金牌会员

Rank: 6Rank: 6

积分
2678
金钱
2473
HASS币
0
发表于 2019-8-2 18:16:31 | 显示全部楼层
现在ha是越来越牛B了
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-4 16:45 , Processed in 0.047987 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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