Node-Red获取设备联网状态


以下方法经本人验证通过,环境如下:

LG LA6600 电视机

Node-RED V0.20.5

node-red-node-ping 0.0.16

node-red-configurable-ping 1.0.1


前言:我有一台LG LA6600的电视机,利用”LG Netcast TV”接入了Home Assistant,但电视状态获取并不及时。我需要实时知道电视机的开启/关闭状态,以便我在执行看电影的自动化场景时,判断是否需要自动关闭电视机

第一步: 在路由器中将 LG LA6600 (或其它需要获取联网状态的设备)设置为固定IP

第二步:Node-Red中安装模块

我测试了两个模块: ” node-red-node-ping“和”node-red-configurable-ping“,它们的应用各不相同

  • node-red-node-ping :是一个不间断ping指定ip的节点,可用于不间断判断设备联网状态 ,例如当自己的手机已联网时,便可判断为在家状态,并执行相应自动化
  • node-red-configurable-ping:可在需要的时候使用该节点ping指定ip,获取设备当时那一刻的联网状况

打开Node-Red页面,点击右上角的选项图标,打开”节点管理”对话框

选择”安装”,根据你的需要,搜索并安装相应模块

安装成功后会在右侧节点列表处显示相应的节点

第三步:使用节点(以 node-red-configurable-ping 为例做简要说明)

按下图所示,拖入inject,conf ping,switch,change,debug节点,并将他们连接起来

  • conf ping :输入你要Ping的设备IP,超时等待时间以及Ping的次数
  • switch :设置两个分支,一个是”为假”,表示无法Ping通,设备不在线;一个是”除此之外”,表示设备在线

以下是导出的流程

[{"id":"213261c3.8746ee","type":"tab","label":"测试区","disabled":false,"info":""},{"id":"ed39ac61.fdbb6","type":"conf ping","z":"213261c3.8746ee","name":"Ping指定设备","host":"192.168.0.72","timeout":"3","requests":"1","x":285,"y":349,"wires":[["1944c161.cc612f"]]},{"id":"56ed78b4.3aa208","type":"inject","z":"213261c3.8746ee","name":"开始","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":348,"wires":[["ed39ac61.fdbb6"]]},{"id":"1944c161.cc612f","type":"switch","z":"213261c3.8746ee","name":"判断是否连接","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":507,"y":351,"wires":[["eaf15649.9520b8"],["6075aa41.9ff694"]]},{"id":"6075aa41.9ff694","type":"change","z":"213261c3.8746ee","name":"输出设备连接","rules":[{"t":"set","p":"payload","pt":"msg","to":"设备连接","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":709,"y":388,"wires":[["d7a9277b.11b558"]]},{"id":"eaf15649.9520b8","type":"change","z":"213261c3.8746ee","name":"输出设备未连接","rules":[{"t":"set","p":"payload","pt":"msg","to":"设备未连接","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":707,"y":301,"wires":[["d7a9277b.11b558"]]},{"id":"d7a9277b.11b558","type":"debug","z":"213261c3.8746ee","name":"输出","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":901,"y":348,"wires":[]}]

最后,部署,点击开始的节点即可在调试窗口中看到结果


如果您喜欢这篇文章,或者它给您带来了帮助,您可以请我们喝一杯咖啡,我们将非常感谢您的支持!

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

11 − 7 =