NodeRed控制小米网关广播

为了给我妈在洗衣服的时候,用洗衣房边上的小米网关听听广播,开发的…

NodeRed里先安装

node-red-contrib-mi-miio

**首先:
**1.米家APP上获取小米网关的token;
2.米家APP上须先收藏要听的广播台;
3.NR里配置:填网关的ip和token;

**使用方法:
**1.第一个func里修改vlaue数值调整音量;
2.第4、5个func是我收藏的中央音乐和央广财经,通过修改id和对应的频道url来换台(其实id改不改没啥用,就是格式罢了)。 url是喜马拉雅电台网络直播的广播地址,我实在记不得哪里可以搜到广播台地址列表了,只能自己找。
3.最后三个是给网关上传、删除和播放自定义音频;

  • 上传音频的func里value 分别对应编号和音频地址,编号从10001起步,音频地址必须外网地址,格式是m3u8;
  • 播放音频的func里value对应音频编号和音量;
  • 理论上可以把tts音频文件转格式后挂外网,上传到网关,实现网关tts,但据说设备内存有限,不建议这样使用。

最后上马:

{"id":"587baaa7.21f6b4","type":"Mi-Other","z":"7729095c.330af8","name":"xiaomi gateway","device":"adb2c3a8.b2f87","x":520,"y":160,"wires":"d591c9a2.b52c98"]]},{"id":"5caf3e48.e41af","type":"inject","z":"7729095c.330af8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":140,"wires":"ba042066.bb222"]]},{"id":"d591c9a2.b52c98","type":"debug","z":"7729095c.330af8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":160,"wires":]},{"id":"ba042066.bb222","type":"function","z":"7729095c.330af8","name":"音乐FM","func":"msg.payload={\n    \"cmd\":\"miio\",\n    \"method\":\"play_specify_fm\",\n    \"value\":{\n        \"type\":0,\n        \"id\":12,\n        \"url\":\"http://live.xmcdn.com/live/12/64.m3u8\"\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":140,"wires":"587baaa7.21f6b4"]]},{"id":"60235e20.0cdd1","type":"inject","z":"7729095c.330af8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":220,"wires":"5d0b770e.fbbd78"]]},{"id":"5d0b770e.fbbd78","type":"function","z":"7729095c.330af8","name":"广播状态","func":"msg.payload={\n    \"cmd\":\"miio\",\n    \"method\":\"get_prop_fm\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":220,"wires":"587baaa7.21f6b4"]]},{"id":"e8fed9ab.c4dd98","type":"inject","z":"7729095c.330af8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":100,"wires":"99453c59.c84b3"]]},{"id":"99453c59.c84b3","type":"function","z":"7729095c.330af8","name":"打开FM","func":"msg.payload={\n    \"cmd\":\"miio\",\n    \"method\":\"play_fm\",\n    \"value\":\"on\"]\n}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":100,"wires":"587baaa7.21f6b4"]]},{"id":"1c2cdedc.11dac1","type":"function","z":"7729095c.330af8","name":"财经FM","func":"msg.payload={\n    \"cmd\":\"miio\",\n    \"method\":\"play_specify_fm\",\n    \"value\":{\n        \"type\":0,\n        \"id\":1066,\n        \"url\":\"http://live.xmcdn.com/live/1066/64.m3u8\"\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":180,"wires":"587baaa7.21f6b4"]]},{"id":"b5807c62.1e382","type":"inject","z":"7729095c.330af8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":180,"wires":"1c2cdedc.11dac1"]]},{"id":"b29ff636.b360e8","type":"inject","z":"7729095c.330af8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":60,"wires":"17269621.5b190a"]]},{"id":"17269621.5b190a","type":"function","z":"7729095c.330af8","name":"关闭FM","func":"msg.payload={\n    \"cmd\":\"miio\",\n    \"method\":\"play_fm\",\n    \"value\":\"off\"]\n}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":60,"wires":"587baaa7.21f6b4"]]},{"id":"7c4ffee1.c8187","type":"inject","z":"7729095c.330af8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":20,"wires":"75dbf337.76b2ac"]]},{"id":"75dbf337.76b2ac","type":"function","z":"7729095c.330af8","name":"FM音量","func":"msg.payload={\n    \"cmd\":\"miio\",\n    \"method\":\"volume_ctrl_fm\",\n    \"value\":'10']\n}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":20,"wires":"587baaa7.21f6b4"]]},{"id":"dab85cc5.0d96d","type":"function","z":"7729095c.330af8","name":"播放音频","func":"msg.payload={\n    \"cmd\":\"miio\",\n    \"method\":\"play_music_new\",\n    \"value\":'10002',20]\n}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":260,"wires":"587baaa7.21f6b4"]]},{"id":"9ba22b64.22f828","type":"inject","z":"7729095c.330af8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":260,"wires":"dab85cc5.0d96d"]]},{"id":"bb683bf5.2971b8","type":"function","z":"7729095c.330af8","name":"删除音频","func":"msg.payload={\n    \"cmd\":\"miio\",\n    \"method\":\"delete_user_music\",\n    \"value\":\"10002\"]\n}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":300,"wires":"587baaa7.21f6b4"]]},{"id":"8be79156.cf3b8","type":"inject","z":"7729095c.330af8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":300,"wires":"bb683bf5.2971b8"]]},{"id":"62a6cd89.cb4ce4","type":"function","z":"7729095c.330af8","name":"上传音频","func":"msg.payload={\n    \"cmd\":\"miio\",\n    \"method\":\"download_user_music\",\n    \"value\":'10002',mediaurl]\n}\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":340,"wires":"587baaa7.21f6b4"]]},{"id":"d51d0859.4e44c8","type":"inject","z":"7729095c.330af8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":340,"wires":"62a6cd89.cb4ce4"]]},{"id":"adb2c3a8.b2f87","type":"Mi-Other-Device","z":"","deviceName":"Xiaomi_Gateway","deviceIP":"192.168.100.160","deviceToken":"","deviceSyncInterval":"1000","deviceAttributesArr":]}]

占位学习,感谢大佬

虽然不让灌水,但是还是想说,大佬、刚需、谢谢。