使用树莓派开启HomeKit智能家居系统 篇十三:将小米电视通过 Node-RED 接入 HomeKit

2021-01-31 21:38:20 23点赞 111收藏 34评论

创作立场声明:无偿分享,整理自我自己家的HomeKit改造

上一篇文章中我们已经安装了 Node-RED,本文讲如何接入小米电视。

HomeKitHomeKit

实现功能:关闭电视、方向键、菜单键、返回键、切换常用APP、用 Siri 调整音量

无法实现:回到主页、打开电视

安装节点

通过 IP:1880进入 Node-RED,点击右上角三个横杠,选择“节点管理”。

节点管理节点管理

点击“安装”,搜索 redmatic-homekit 节点,安装。

安装节点安装节点

绑定MAC与IP

进入路由器后台,绑定电视机的MAC地址和IP,否则IP发生变化会失效,可以参考之前的文章。

使用树莓派开启HomeKit智能家居系统 篇七:将Yeelight吸顶灯、台灯接入Home Assistant和HomeKit盘点你心中的年度好物,分享属于你的难忘故事!12月15日-1月22日参加#2020值得总结#征稿活动,发文至社区即有50金币奖励,最高可获得1000元京东E卡!岁月不会辜负每一个用心生活的人,让我们一起回顾跌宕起伏的2020年。还等什么,快点击查看活动详情!Yeelight新款的吸顶灯和米家台灯1sBrianTffff| 13 评论15 收藏80查看详情

导入json

下面直接给出要用到的json代码

[{"id":"8658c195.25121","type":"tab","label":"小米电视","disabled":false,"info":""},{"id":"2ac213f9.afe504","type":"debug","z":"8658c195.25121","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":420,"wires":[]},{"id":"2909301a.3b9a28","type":"switch","z":"8658c195.25121","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"PowerModeSelection","vt":"str"},{"t":"eq","v":"InputSource","vt":"str"},{"t":"eq","v":"Active","vt":"str"},{"t":"eq","v":"VolumeSelector","vt":"str"},{"t":"eq","v":"RemoteKey","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":810,"y":300,"wires":[["70a0b6eb.5779d8"],["36c4bd9b.913482"],["53abe661.a837a"],["647b93de.cf6fbc"],["12ba5907.55878f"]]},{"id":"53abe661.a837a","type":"switch","z":"8658c195.25121","name":"开关机","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":1010,"y":260,"wires":[["540f32be.c82b14"],["e18fb354.e83f78"]]},{"id":"36c4bd9b.913482","type":"switch","z":"8658c195.25121","name":"输入源","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"主页","vt":"str"},{"t":"eq","v":"云视听极光","vt":"str"},{"t":"eq","v":"CIBN酷喵","vt":"str"},{"t":"eq","v":"无线投屏","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":1010,"y":200,"wires":[["7d4e8f78.6da858"],["d17567b9.1464e"],["819bdaa6.ab3a8"],["dfa1a8ff.44bfa8"]],"outputLabels":["","","","爱奇艺"]},{"id":"12ba5907.55878f","type":"switch","z":"8658c195.25121","name":"功能键","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"PLAY_PAUSE","vt":"str"},{"t":"eq","v":"SELECT","vt":"str"},{"t":"eq","v":"BACK","vt":"str"},{"t":"eq","v":"INFORMATION","vt":"str"},{"t":"eq","v":"ARROW_RIGHT","vt":"str"},{"t":"eq","v":"ARROW_LEFT","vt":"str"},{"t":"eq","v":"ARROW_UP","vt":"str"},{"t":"eq","v":"ARROW_DOWN","vt":"str"}],"checkall":"true","repair":false,"outputs":8,"x":1010,"y":520,"wires":[["bac76e62.2891e"],["bac76e62.2891e"],["6a1c37de.6b89"],["eaa8e575.80e928"],["35fb6a4.b22cc96"],["d6a1c7a6.b56b08"],["6ab2c6b2.2ab9c"],["d6912780.9666f8"]],"outputLabels":["暂停","确认","返回","信息","向右","向左","向上","向下"]},{"id":"6ab2c6b2.2ab9c","type":"http request","z":"8658c195.25121","name":"上","method":"GET","ret":"txt","paytoqs":false,"url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=up","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":600,"wires":[[]]},{"id":"d6912780.9666f8","type":"http request","z":"8658c195.25121","name":"下","method":"GET","ret":"txt","paytoqs":false,"url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=down","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":640,"wires":[[]]},{"id":"d6a1c7a6.b56b08","type":"http request","z":"8658c195.25121","name":"左","method":"GET","ret":"txt","paytoqs":false,"url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=left","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":560,"wires":[[]]},{"id":"35fb6a4.b22cc96","type":"http request","z":"8658c195.25121","name":"右","method":"GET","ret":"txt","paytoqs":false,"url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=right","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":520,"wires":[[]]},{"id":"eaa8e575.80e928","type":"http request","z":"8658c195.25121","name":"菜单","method":"GET","ret":"txt","paytoqs":false,"url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=menu","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":480,"wires":[[]]},{"id":"6a1c37de.6b89","type":"http request","z":"8658c195.25121","name":"返回","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=back","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":440,"wires":[[]]},{"id":"bac76e62.2891e","type":"http request","z":"8658c195.25121","name":"确定","method":"GET","ret":"txt","paytoqs":false,"url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=enter","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":400,"wires":[[]]},{"id":"540f32be.c82b14","type":"http request","z":"8658c195.25121","name":"电源","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=power","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":240,"wires":[["ed279dbc.01eee"]]},{"id":"a8f8c766.3296c","type":"change","z":"8658c195.25121","name":"设定电视 IP","rules":[{"t":"set","p":"ip","pt":"msg","to":"192.168.31.107","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":500,"wires":[["2909301a.3b9a28","dfe94121.751d78"]]},{"id":"6eacdbbe.aa7d04","type":"redmatic-homekit-tv","z":"8658c195.25121","name":"小米电视","username":"AB:22:3D:40:49:AD","pincode":"886-50-223","port":"50335","inputsources":[{"name":"主页","type":1},{"name":"云视听极光","type":10},{"name":"CIBN酷喵","type":10},{"name":"无线投屏","type":8}],"x":440,"y":460,"wires":[["a8f8c766.3296c","2ac213f9.afe504"]]},{"id":"8808a79c.6a9de8","type":"http request","z":"8658c195.25121","name":"切换应用","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://{{{ip}}}:6095/controller?action=startapp&type=packagename&packagename={{{app}}}","tls":"","persist":false,"proxy":"","authType":"basic","x":1440,"y":40,"wires":[[]]},{"id":"7d4e8f78.6da858","type":"change","z":"8658c195.25121","name":"主页","rules":[{"t":"set","p":"app","pt":"msg","to":"com.mitv.tvhome","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":80,"wires":[["8808a79c.6a9de8"]]},{"id":"b0c2dd2e.83bd7","type":"inject","z":"8658c195.25121","name":"状态","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":true,"onceDelay":0.1,"topic":"Active","payload":"false","payloadType":"bool","x":170,"y":340,"wires":[["bcb8edb.d03d39"]]},{"id":"e75fa169.d2d108","type":"http request","z":"8658c195.25121","name":"检查状态","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://{{{ip}}}:6095/request?action=isalive","tls":"","persist":false,"proxy":"","authType":"basic","x":260,"y":420,"wires":[["6b1fbe50.155f78"]]},{"id":"bcb8edb.d03d39","type":"change","z":"8658c195.25121","name":"设定电视 IP","rules":[{"t":"set","p":"ip","pt":"msg","to":"192.168.31.107","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":380,"wires":[["e75fa169.d2d108"]]},{"id":"6b1fbe50.155f78","type":"function","z":"8658c195.25121","name":"","func":"var code=msg.statusCode;nif( code != 200 )n{nmsg.payload=false;n}nelsen{nmsg.payload=truen n}nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":290,"y":460,"wires":[["6eacdbbe.aa7d04"]]},{"id":"d17567b9.1464e","type":"change","z":"8658c195.25121","name":"云视听极光","rules":[{"t":"set","p":"app","pt":"msg","to":"com.ktcp.video","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":120,"wires":[["8808a79c.6a9de8"]]},{"id":"819bdaa6.ab3a8","type":"change","z":"8658c195.25121","name":"CIBN酷喵","rules":[{"t":"set","p":"app","pt":"msg","to":"com.cibn.tv","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":160,"wires":[["8808a79c.6a9de8"]]},{"id":"e18fb354.e83f78","type":"http request","z":"8658c195.25121","name":"返回","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=back","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":280,"wires":[[]]},{"id":"dfa1a8ff.44bfa8","type":"change","z":"8658c195.25121","name":"无线投屏","rules":[{"t":"set","p":"app","pt":"msg","to":"com.xiaomi.mitv.smartshare","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":200,"wires":[["8808a79c.6a9de8"]]},{"id":"70a0b6eb.5779d8","type":"change","z":"8658c195.25121","name":"系统设置","rules":[{"t":"set","p":"app","pt":"msg","to":"com.xiaomi.mitv.settings","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":40,"wires":[["8808a79c.6a9de8"]]},{"id":"dfe94121.751d78","type":"http request","z":"8658c195.25121","name":"查看app名称","method":"GET","ret":"txt","paytoqs":false,"url":"http://{{{ip}}}:6095/controller?action=getinstalledapp&count=999&changeIcon=1","tls":"","persist":false,"proxy":"","authType":"basic","x":830,"y":680,"wires":[["d135a9bc.335e68"]]},{"id":"5a7c7f06.f424c8","type":"inject","z":"8658c195.25121","name":"查询 APP 名称","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":420,"y":540,"wires":[["a8f8c766.3296c"]]},{"id":"d135a9bc.335e68","type":"json","z":"8658c195.25121","name":"","property":"payload","action":"","pretty":false,"x":850,"y":720,"wires":[["a03f6f5.b1f9a1"]]},{"id":"a03f6f5.b1f9a1","type":"debug","z":"8658c195.25121","name":"获取 APP 名称","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":920,"y":760,"wires":[]},{"id":"647b93de.cf6fbc","type":"switch","z":"8658c195.25121","name":"音量","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"VOLUMEUP","vt":"str"},{"t":"eq","v":"VOLUMEDOWN","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1010,"y":340,"wires":[["dde64b14.8151a8"],["240e0ccd.e0cff4"]]},{"id":"dde64b14.8151a8","type":"http request","z":"8658c195.25121","name":"音量 +","method":"GET","ret":"txt","paytoqs":false,"url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=volumeup","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":320,"wires":[[]]},{"id":"240e0ccd.e0cff4","type":"http request","z":"8658c195.25121","name":"音量 -","method":"GET","ret":"txt","paytoqs":false,"url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=volumedown","tls":"","persist":false,"proxy":"","authType":"basic","x":1210,"y":360,"wires":[[]]},{"id":"7955fcb1.d3c0e4","type":"http request","z":"8658c195.25121","name":"电源","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://{{{ip}}}:6095/controller?action=keyevent&keycode=power","tls":"","persist":false,"proxy":"","authType":"basic","x":1510,"y":240,"wires":[[]]},{"id":"ed279dbc.01eee","type":"delay","z":"8658c195.25121","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1360,"y":240,"wires":[["7955fcb1.d3c0e4"]]}]

点击右上角三个横杠,点击导入,把上面的内容粘贴进去,选择新流程,点击导入,出现以下流程图,导入成功。

导入成功导入成功

简单分析一下这个流程图,中间的“小米电视”节点为“核心”节点,也就是一个HomeKit配件,其左边的是传入状态,其右边的是根据用户通过 HomeKit APP 操作后传出的相关指令,不懂也没有关系,可以先去了解一下Node-RED,如果只是为了小米电视的话,跟着我改就行。

修改电视机IP

找到其中两个名为“设定电视 IP”的节点,双击,将IP地址改为你电视机的IP地址,两个节点都这么处理。

修改IP修改IP

点击右上角“部署”来保存。

点击红色的“部署”点击红色的“部署”

打开电视机,等它开机后,点击右上角BUG图标进入DEBUG。

DEBUGDEBUG

点击“查询APP名称”节点前的小方块执行,如果右侧栏DEBUG区域能返回上图msg,则说明连接成功,进入下一步。

查询APP查询APP

修改输入源(APP)

HomeKit电视机出了左图的控制器以外,还支持如右图的输入源切换,这个是可以手动设置的,只要滚动选择器,电视机上就能直接打开对应APP,无需通过遥控器找。

HomeKitHomeKit

获取应用名称

还记得刚才的 DEBUG 信息吗?如下图展开信息,其中的“PackageName”就是应用名称,在这步,记下你需要的所有 APP 的名称。

APP名称APP名称

设置 APP 切换

如果你和我一样也是主页(爱奇艺)+腾讯+优酷+投屏,那就不用改了。

双击“小米电视”节点,增删改显示在HomeKit UI上的切换器名称和类型(类型不重要,好像看不出来有啥用),并记住顺序,点击“完成”保存。

增删改增删改

双击“输入源”节点,按照顺序修改名称,一定要一模一样,因为 HomeKit 节点会发一个UI上的名称过来,在这里进行匹配分流到之后的节点,这里的1、2、3、4对应节点后面的四个接口,也可以根据需要添加更多,点击“完成”保存。

注意⚠️:“主页”按钮不建议修改,容易出问题,名字可以改,内容最好不要动。

将小米电视通过 Node-RED 接入 HomeKit


一一对设为头图

双击后面的节点,按照之前的顺序,修改名称和APP名称,就是下面的“com.xxx.xxx”,如果节点不够,可以 “Ctrl C”、 “Ctrl V”拷贝粘贴更多节点,用鼠标连接相应的线即可,最后几个 APP 都需要与后面的“切换应用”节点相连。

修改APP名称修改APP名称

完成后点击“部署”

导入HomeKit

双击“小米电视”核心节点,下面会出现一个二维码,用HomeKit扫描即可,会出现关机按钮和切换器。

遥控器的话下拉iPhone的控制中心,最下面会出现 Apple TV 遥控器,如果没有,进入设置、控制中心,添加即可。

遥控器/切换器遥控器/切换器

代码预设1分钟更新一次状态,也就是说如果使用普通遥控器开启电视,HomeKit会在1分钟更新为开机。


展开 收起

MI 小米 米家 小卫质品泡沫洗手液 米家自动洗手机专用 温和亲肤 植物基配方 氨基酸洗手液

MI 小米 米家 小卫质品泡沫洗手液 米家自动洗手机专用 温和亲肤 植物基配方 氨基酸洗手液

39元起

[小白200万Y2]小米生态链摄像头监控家用手机远程无线wifi高清360

[小白200万Y2]小米生态链摄像头监控家用手机远程无线wifi高清360

暂无报价

小米(MI) 小米生态 HITH T1 自动加热足浴盆泡脚桶泡脚盆5D电动按摩智能恒温洗脚桶足浴桶 鲸鱼灰

小米(MI) 小米生态 HITH T1 自动加热足浴盆泡脚桶泡脚盆5D电动按摩智能恒温洗脚桶足浴桶 鲸鱼灰

399元起

小米 高温无线洗地机吸拖洗一体机智能新品自清洁吸尘器 小米高温洗地机基站+配件

小米 高温无线洗地机吸拖洗一体机智能新品自清洁吸尘器 小米高温洗地机基站+配件

2809元起

小米(MI) 米物计时器厨房定时器学习生倒计时提醒器磁吸LED静音时间管理器 米物静享旋转计时器 白色

小米(MI) 米物计时器厨房定时器学习生倒计时提醒器磁吸LED静音时间管理器 米物静享旋转计时器 白色

49元起

小米(MI) 米家台灯Lite 护眼国标A级无蓝光卧室书房阅读灯3挡调光触控学生儿童学习床头灯带底座 米家台灯Lite

小米(MI) 米家台灯Lite 护眼国标A级无蓝光卧室书房阅读灯3挡调光触控学生儿童学习床头灯带底座 米家台灯Lite

79元起

小米小爱同学触屏音箱Pro 8 平板智能音箱 智能交互 DTS调音 WiFi/蓝牙音响

小米小爱同学触屏音箱Pro 8 平板智能音箱 智能交互 DTS调音 WiFi/蓝牙音响

599元起

小米(MI)米家智能窗帘支持app小爱同学语音智能开合电动窗帘 米家智能窗帘

小米(MI)米家智能窗帘支持app小爱同学语音智能开合电动窗帘 米家智能窗帘

830元起

小米小爱音箱 Pro 黑色 小爱同学智能音箱 性能升级 智能设备控制 遥控传统家电 蓝牙Mesh网关

小米小爱音箱 Pro 黑色 小爱同学智能音箱 性能升级 智能设备控制 遥控传统家电 蓝牙Mesh网关

319元起

小米净水器家用净水机600G厨下式 RO反渗透4级过滤 进口RO滤芯 无罐直饮水 智控水龙头 米家APP智能互联

小米净水器家用净水机600G厨下式 RO反渗透4级过滤 进口RO滤芯 无罐直饮水 智控水龙头 米家APP智能互联

1699元起

小米生态小白可视智能门铃1080p视频无线家用猫眼监控摄像头连接米家APP远程控制高清夜视 小白智能视频门铃D1套装

小米生态小白可视智能门铃1080p视频无线家用猫眼监控摄像头连接米家APP远程控制高清夜视 小白智能视频门铃D1套装

239元起

小米生态FIVE消毒刀架刀具防霉杀毒机紫外线智能分类防霉烘干刀筷架 FIVE智能刀筷架 白色

小米生态FIVE消毒刀架刀具防霉杀毒机紫外线智能分类防霉烘干刀筷架 FIVE智能刀筷架 白色

529.67元起

小米(MI) 小米生态积木磁力积木\/指尖积木玩具机器人男孩女孩少儿童 米兔指尖积木

小米(MI) 小米生态积木磁力积木\/指尖积木玩具机器人男孩女孩少儿童 米兔指尖积木

43.2元起

小米 3USB接口+6孔位 2A快充 插线板/插排/插座

小米 3USB接口+6孔位 2A快充 插线板/插排/插座

72元起

小米(MI) 米家空调伴侣2 远程控制 小爱声控 睡后调温 电量统计 空调伴侣PRO

小米(MI) 米家空调伴侣2 远程控制 小爱声控 睡后调温 电量统计 空调伴侣PRO

132元起

小米(MI) 华米Amazfit 米动手表青春版 智能运动学生手表GPS轨迹心率蓝牙离线支付. 米动青春版 曜石黑 标配

小米(MI) 华米Amazfit 米动手表青春版 智能运动学生手表GPS轨迹心率蓝牙离线支付. 米动青春版 曜石黑 标配

422元起
34评论

发表评论请 登录
  • 最新
  • 最热
评论举报

请选择举报理由

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

相关文章推荐

更多精彩文章
更多精彩文章
最新文章 热门文章