开关TTS语音反馈【小爱TTS节点首秀】

实现功能

  1. 当打开或关闭列表内的任意开关时, 小爱音箱TTS播报 例如: 客厅灯已开启 客厅灯已关闭.

前置需求

  1. 安装小爱tts节点
  2. 获取小爱音箱的deviceidTIM截图20190902141714.jpg

原理简述

  1. 检测所有小米开关事件
  2. 排除触发时间与当前时间不一致的事件,
  3. 因iob没有获取设备友好名称的方法,只能自己建立一个列表,判断topic是否在列表内. 选择自己需要播报的开关.
  4. 通过小爱tts节点输播报开关状态

{"id":"21e7e102.3105ce","type":"debug","z":"24511613.6f274a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":470,"y":20,"wires":]},{"id":"f6d7af33.18252","type":"ioBroker in","z":"24511613.6f274a","name":"米家开关设备监听","topic":"mihome.0.devices.ctrl_*","payloadType":"value","onlyack":true,"func":"rbe","gap":"","x":150,"y":100,"wires":"21e7e102.3105ce","405c8951.055658"]]},{"id":"945a3651.db9a38","type":"switch","z":"24511613.6f274a","name":"","property":"payload","propertyType":"msg","rules":{"t":"eq","v":"true","vt":"str"},{"t":"eq","v":"false","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":790,"y":100,"wires":"74e9fb3.56a8f04"],"b644684a.eacbd8"]]},{"id":"74e9fb3.56a8f04","type":"function","z":"24511613.6f274a","name":"推送打开消息","func":"msg.payload  = `${msg.name}已开启`;\nreturn msg;","outputs":1,"noerr":0,"x":960,"y":80,"wires":"c22031b3.44798"]]},{"id":"b644684a.eacbd8","type":"function","z":"24511613.6f274a","name":"推送关闭消息","func":"msg.payload = `${msg.name}已关闭`;\nreturn msg;","outputs":1,"noerr":0,"x":960,"y":120,"wires":"c22031b3.44798"]]},{"id":"944299fe.8a7518","type":"function","z":"24511613.6f274a","name":"获取开关名称","func":"var dict = {\n    \"mihome/0/devices/ctrl_ln2_aq1_158d000239c546/channel_1\":\"书房吊灯\",\n    \"mihome/0/devices/ctrl_ln2_aq1_158d000239c546/channel_0\":\"书房筒灯\",\n    \"mihome/0/devices/ctrl_neutral2_158d00014cf47a/channel_0\":\"客厅左键灯\",\n    \"mihome/0/devices/ctrl_neutral2_158d00014cf47a/channel_1\":\"客厅右键灯\",\n    \"mihome/0/devices/ctrl_ln2_aq1_158d00024efd51/channel_0\":\"厨房LED\",\n    \"mihome/0/devices/ctrl_ln2_aq1_158d00024efd51/channel_1\":\"厨房光管\",\n    \"mihome/0/devices/ctrl_ln2_aq1_158d000239c207/channel_0\":\"浴室LED\",\n    \"mihome/0/devices/ctrl_ln2_aq1_158d000239c207/channel_1\":\"浴室光管\",\n    \"mihome/0/devices/ctrl_ln1_aq1_158d0002325353/channel_0\":\"主卧灯\",\n    \"mihome/0/devices/ctrl_ln2_aq1_158d00024efc9e/channel_0\":\"阳台灯\",\n    \"mihome/0/devices/ctrl_ln2_aq1_158d00024efc9e/channel_1\":\"卧室灯\",\n    \"mihome/0/devices/ctrl_ln1_aq1_158d0002114e41/channel_0\":\"房间灯\"\n};\nif(msg.topic in dict){\n    msg.name = dict[msg.topic];\n    return msg;\n}\nelse{\n    return null;\n}\n","outputs":1,"noerr":0,"x":620,"y":100,"wires":"945a3651.db9a38","1c86259e.7edb0a"]]},{"id":"1c86259e.7edb0a","type":"debug","z":"24511613.6f274a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":180,"wires":]},{"id":"3f55203f.9b662","type":"debug","z":"24511613.6f274a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1350,"y":80,"wires":]},{"id":"405c8951.055658","type":"switch","z":"24511613.6f274a","name":"过滤非即时更新的消息","property":"timestamp","propertyType":"msg","rules":{"t":"eq","v":"lastchange","vt":"msg"}],"checkall":"true","repair":false,"outputs":1,"x":400,"y":100,"wires":"944299fe.8a7518"]]},{"id":"c22031b3.44798","type":"xiaoai-tts","z":"24511613.6f274a","name":"小爱TTS","xiaoai":"95f52ee1.d4703","tts":"","device":"你的deviceid通过另一个节点获取列表","x":1160,"y":100,"wires":"3f55203f.9b662"],"ffa8db45.9caed8"]]},{"id":"ffa8db45.9caed8","type":"debug","z":"24511613.6f274a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1350,"y":120,"wires":]},{"id":"95f52ee1.d4703","type":"xiaoai-tts-configurator","z":"","name":"","username":"yourusername","password":"yourpassword"}]

这个代码贴进去不被识别,增加几个括号也没成功
221212