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

 找回密码
 立即注册
查看: 4864|回复: 5

[教程系列] 远程控制电脑开关机NodeRED+HomeAssistant+阿里飞燕+ubuntu

[复制链接]

4

主题

18

帖子

118

积分

注册会员

Rank: 2

积分
118
金钱
100
HASS币
0
发表于 2022-5-18 20:26:15 | 显示全部楼层 |阅读模式
本帖最后由 csphhing 于 2022-5-18 20:26 编辑

远程控制电脑开关机PC上无需任何插件  NodeRED+HomeAssistant+阿里飞燕+ubuntu

平台硬件:移动电视机顶盒-魔百和M301H  刷入Ubuntu 20.04 LTS   参考论坛 https://www.histb.com/


平台软件:ubuntu下安装 NodeRED     Docker
                 Docker下安装Homeassistant
                 阿里云飞燕平台

流程思路:通过阿里云飞燕平台新建一个开关,结合NodeRED虚拟出飞燕平台的开关,在NodeRED里添加流程对开关进行处理,实现WOL开机,Shell命令关机

各部分准备:
1、Homeassistant  需要安装HACS,在HACS下安装 Nodered集成
          Doker下安装HACS,本机ubuntu环境通过Shell命令安装
docker exec -it homeassistant bash
wget -O - https://get.hacs.xyz | bash -
          以上命令,其中homeassistant 为docker容器的名字,根据安装HA时设置的名称更改           由于网络环境可能会导致安装失败,修改hosts文件即可           在/etc/hosts  文件里添加以下内容
185.199.109.133 raw.githubusercontent.com
185.199.110.133 raw.githubusercontent.com
185.199.108.133 raw.githubusercontent.com
185.199.111.133 raw.githubusercontent.com
20.205.243.166 github.com
20.205.243.165 nodeload.github.com
20.205.243.168 api.github.com
185.199.109.153 training.github.com
185.199.110.153 training.github.com
185.199.111.153 training.github.com
185.199.108.153 training.github.com
20.205.243.165 codeload.github.com
185.199.109.153 asstes-cdn.github.com
185.199.111.153 asstes-cdn.github.com
185.199.110.153 asstes-cdn.github.com
185.199.108.153 asstes-cdn.github.com
           其他的设置教程很多,不多啰嗦。
    2、NodeRED 安装
          本机NodeRED直接安装在宿主机内,并未安装在Docker内。因为安装在Docker内会导致NodeRED无法调用连接在宿主机上的某些硬件,比如USB转232数据线。
            ubuntu下通过命令安装
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
         NodeRED需要安装的节点
           node-red                                                                     NodeRED自带节点
           node-red-contrib-home-assistant-websocket         HomeAssistant 对接节点
           node-red-node-ping                                                   Ping 节点
           node-red-node-wol                                                     Wake-On-Lan 节点
           node-red-contrib-aliyun-living                                  阿里云飞燕 节点
     3、PC电脑准备
           Win10系统需要有带密码的本地管理员账户。需要固定IP。
           本win10使用的是Microsoft账户登录的PC,所以又新建了一个本地管理员账户。无需登录使用,新建起来即可。

    4、开通并登录阿里云飞燕平台
         https://living.aliyun.com/
         支付宝扫一扫登录

飞燕平台操作
新建一个自有品牌项目,名称任意
下载.png

    创建新产品
下载 (1).png

      填写相关信息,连网方式要选择 蜂窝
       下载 (2).png

     产品建立好后,进入 功能定义,标准功能  不用管,在自定义功能处添加功能
    下载 (3).png
   功能类型为属性,在功能名称处双击 选择 运行状态,其他可按图修改,修改好后确认,下一步


    进入人机交互界面,在选择交互端选项中  打开 使用公版APP控制产品
    下载 (4).png

    根据左边导航选项设置,有感叹号的为必须设置好
      下载 (5).png

    设置好名称,型号,保存
    下载 (6).png

    不要点击下一步,点击左边导航栏的选项,点击有感叹号的
      下载 (7).png

    点击未设置,进入面板编辑界面   选择从模板新建
    下载 (8).png
    选择红色 功能丢失 模块,按 退位键←  删除,可以根据自己的喜好移动,修改按键等
      下载 (9).png

    修改完毕后按右上角保存,名称任意。
         下载 (10).png

    关闭此页面,或切换到刚才的页面,点击 未设置,选择刚才编辑好的面板  确认
            下载 (11).png


    选择左边导航栏的多语言管理,选择英文  输入产品品牌 名称 型号。下拉到底 保存
       下载 (12).png


      必填项设置好后,点击下一步,选择模组,随便选一个,我选择的 未知
         下载 (13).png

    在测试设备处 新增测试设备,输入名称或由系统自定义
       下载 (14).png

    确定后得到一个界面,到此,飞燕平台暂停操作。
    下载 (15).png


NodeRED操作
    找到 aliyun-living   拖入流程
         下载 (16).png    


    编辑阿里飞燕节点  设备名称自取,其他三项   复制刚才网页上的三项数据    完成。直接  部署,出现一个二维码
      下载 (17).png



          下载 (18).png

    下载云智能APP,登陆后扫NodeRED生成的二维码添加设备。
    继续NodeRED流程,其他的流程如下图,后面会贴出 json代码
       下载 (19).png

[{"id":"fa9df4be7b0c093c","type":"tab","label":"电脑开关机","disabled":false,"info":"","env":[]},{"id":"25988d07616c7974","type":"wake on lan","z":"fa9df4be7b0c093c","mac":"","host":"192.168.1.255","udpport":9,"numpackets":3,"interval":100,"name":"WOL开机","x":980,"y":320,"wires":[]},{"id":"c7ae589685a1b42e","type":"aliyun-living","z":"fa9df4be7b0c093c","name":"阿里飞燕电脑开关","width":160,"DeviceName":"","ProductKey":"","DeviceSecret":"","x":610,"y":360,"wires":[["616ece5f3b3891ad"]]},{"id":"42d4434a.11da6c","type":"debug","z":"fa9df4be7b0c093c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1190,"y":340,"wires":[]},{"id":"c81072df.ec5e2","type":"inject","z":"fa9df4be7b0c093c","name":"测试开","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"powerstate":1}","payloadType":"json","x":350,"y":460,"wires":[["c7ae589685a1b42e"]]},{"id":"a67a9b70.d27558","type":"inject","z":"fa9df4be7b0c093c","name":"测试关","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"powerstate":0}","payloadType":"json","x":350,"y":500,"wires":[["c7ae589685a1b42e"]]},{"id":"616ece5f3b3891ad","type":"switch","z":"fa9df4be7b0c093c","name":"开关指令识别","property":"payload.powerstate","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":800,"y":360,"wires":[["25988d07616c7974","42d4434a.11da6c"],["55477420cb319d53"]]},{"id":"5426c1246b7877ac","type":"ping","z":"fa9df4be7b0c093c","protocol":"Automatic","mode":"timed","name":"Ping取电脑状态","host":"192.168.1.9","timer":"10","inputs":0,"x":100,"y":360,"wires":[["3e7fc0b99a98d438"]]},{"id":"3e7fc0b99a98d438","type":"switch","z":"fa9df4be7b0c093c","name":"Ping值转换","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"},{"t":"istype","v":"boolean","vt":"boolean"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":360,"wires":[["d5b1914f422fd890"],["f0a16b3f28e340f4"]]},{"id":"d5b1914f422fd890","type":"change","z":"fa9df4be7b0c093c","name":"已开启","rules":[{"t":"set","p":"payload","pt":"msg","to":"{"RunningState":1}","tot":"json"},{"t":"set","p":"enable","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":340,"wires":[["c7ae589685a1b42e","7eaab5c011838107"]]},{"id":"f0a16b3f28e340f4","type":"change","z":"fa9df4be7b0c093c","name":"已关闭","rules":[{"t":"set","p":"payload","pt":"msg","to":"{"RunningState":0}","tot":"json"},{"t":"set","p":"enable","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":380,"wires":[["c7ae589685a1b42e","7eaab5c011838107"]]},{"id":"7d2697e38ca9ca8d","type":"inject","z":"fa9df4be7b0c093c","name":"测试状态开","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"RunningState":1}","payloadType":"json","x":360,"y":540,"wires":[["c7ae589685a1b42e"]]},{"id":"4d1d6d8992c7a7bc","type":"inject","z":"fa9df4be7b0c093c","name":"测试状态关","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"RunningState":0}","payloadType":"json","x":360,"y":580,"wires":[["c7ae589685a1b42e"]]},{"id":"55477420cb319d53","type":"exec","z":"fa9df4be7b0c093c","command":"net rpc shutdown -I 192.168.1.99 address -U 用户名%密码","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"关机指令","x":980,"y":380,"wires":[["42d4434a.11da6c"],["42d4434a.11da6c"],["42d4434a.11da6c"]]},{"id":"7eaab5c011838107","type":"ha-entity","z":"fa9df4be7b0c093c","name":"HA电脑开关","server":"a487525207434812","version":2,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"电脑"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:desktop-classic"},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"payload","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"activate","outputPayloadType":"str","x":590,"y":260,"wires":[["25988d07616c7974"],["55477420cb319d53"]]},{"id":"ccfc6bcdabe6b91d","type":"comment","z":"fa9df4be7b0c093c","name":"用NodeRED创建一个开关,加入到HA里","info":"","x":670,"y":180,"wires":[]},{"id":"1a7af30cd7cad950","type":"comment","z":"fa9df4be7b0c093c","name":"网络-Ping","info":"","x":100,"y":320,"wires":[]},{"id":"38a803ad326d4d1b","type":"comment","z":"fa9df4be7b0c093c","name":"switch","info":"","x":270,"y":320,"wires":[]},{"id":"8c76cc39517d64d9","type":"comment","z":"fa9df4be7b0c093c","name":"change","info":"","x":410,"y":300,"wires":[]},{"id":"316d8dde395723f8","type":"comment","z":"fa9df4be7b0c093c","name":"entity","info":"","x":570,"y":220,"wires":[]},{"id":"3c95a89064198ef9","type":"comment","z":"fa9df4be7b0c093c","name":"aliyun - living","info":"","x":590,"y":320,"wires":[]},{"id":"07817bb9158fa13b","type":"comment","z":"fa9df4be7b0c093c","name":"switch","info":"","x":770,"y":400,"wires":[]},{"id":"f63dc50a6039afd9","type":"comment","z":"fa9df4be7b0c093c","name":"wake on lan","info":"","x":990,"y":280,"wires":[]},{"id":"7c8e31bf0ce00533","type":"comment","z":"fa9df4be7b0c093c","name":"exec","info":"","x":970,"y":420,"wires":[]},{"id":"997e7426b850c73b","type":"comment","z":"fa9df4be7b0c093c","name":"inject","info":"","x":330,"y":620,"wires":[]},{"id":"60b5e3b8a5813076","type":"comment","z":"fa9df4be7b0c093c","name":"debug","info":"","x":1170,"y":300,"wires":[]},{"id":"a487525207434812","type":"server","name":"Home Assistant","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]

参考贴:https://bbs.iobroker.cn/t/topic/6337

回复

使用道具 举报

0

主题

9

帖子

190

积分

注册会员

Rank: 2

积分
190
金钱
181
HASS币
0
发表于 2023-1-29 15:26:44 | 显示全部楼层
如果不使用阿里飞燕平台,直接使用HA中的米家无线开关是否也是可行的?
回复

使用道具 举报

0

主题

2

帖子

58

积分

注册会员

Rank: 2

积分
58
金钱
56
HASS币
0
发表于 2023-1-30 18:20:47 | 显示全部楼层
楼主的代码导入报错,说Unexpected token p in JSON at position 900,不如上传个JS 文件,下载学习下
回复

使用道具 举报

1

主题

126

帖子

743

积分

高级会员

Rank: 4

积分
743
金钱
617
HASS币
0
发表于 2023-5-30 13:33:43 | 显示全部楼层
就一个简单的wol解决,搞得这么复杂
回复

使用道具 举报

1

主题

198

帖子

1554

积分

金牌会员

Rank: 6Rank: 6

积分
1554
金钱
1356
HASS币
0
发表于 2023-5-30 14:13:47 | 显示全部楼层
cyczq3 发表于 2023-5-30 13:33
就一个简单的wol解决,搞得这么复杂

哈哈      
回复

使用道具 举报

2

主题

106

帖子

589

积分

高级会员

Rank: 4

积分
589
金钱
483
HASS币
0
发表于 2024-6-12 16:52:04 | 显示全部楼层
问一下楼主,就是云智能扫那个二维码的时候,手机需要和部署Node-red服务器在同一个内网才能添加成功么?我没练一个内网的WIFI配网添加设备添加不起
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-12-22 11:33 , Processed in 0.093525 second(s), 31 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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