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

 找回密码
 立即注册
查看: 9173|回复: 10

[教程系列] 流变量的简单应用[魔方控制3组灯]

[复制链接]

219

主题

1287

帖子

7941

积分

超级版主

Rank: 8Rank: 8

积分
7941
金钱
6624
HASS币
86

教程狂人论坛风云人物突出贡献

发表于 2018-12-26 10:01:32 | 显示全部楼层 |阅读模式

flow变量

  1. flow变量可在同一个flow读取/写入,方便不同的流程互相传递数据.

魔方同时控制3组灯

  1. 读取flow变量,当变量为on时,关三组灯,否则开三组灯
  2. 开灯的时候,将flow变量设置为on,关的时候设置为off

为何需要flow变量

  1. 当未通过魔方控制灯的时候,不会干扰到本流程的执行
  2. 比如,手动按开关,开关灯

TIM截图20181226100017.jpg

[{"id":"26f6c878.c71868","type":"server-events","z":"59f4d8aa.25fef8","name":"获取所有事件","server":"94f0c0a9.629b6","event_type":"xiaomi_aqara.cube_action","x":370,"y":1240,"wires":[["a19f23ca.91e73","4d0db3fe.5b336c"]]},{"id":"a19f23ca.91e73","type":"switch","z":"59f4d8aa.25fef8","name":"获取魔方动作事件","property":"payload.event.action_type","propertyType":"msg","rules":[{"t":"eq","v":"tap_twice","vt":"str"},{"t":"eq","v":"rotate","vt":"str"},{"t":"eq","v":"move","vt":"str"},{"t":"eq","v":"flip90","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":590,"y":1240,"wires":[["cab2106d.306d5","4d0db3fe.5b336c"],[],[],[]]},{"id":"cab2106d.306d5","type":"function","z":"59f4d8aa.25fef8","name":"获取study_light变量状态","func":"if(flow.get('study_light')==='on'){\n    return [msg,null];\n}\nelse{\n    return [null,msg];}\n","outputs":2,"noerr":0,"x":850,"y":1220,"wires":[["5c035c16.a23a34","63e71ed6.b46e6","5567fdb.c9aec04","4d0db3fe.5b336c"],["54da9730.835f88","1bd5906f.a7b2","77eb6cf2.8b2514","4d0db3fe.5b336c"]]},{"id":"5c035c16.a23a34","type":"api-call-service","z":"59f4d8aa.25fef8","name":"","server":"94f0c0a9.629b6","service_domain":"switch","service":"turn_off","data":"{\"entity_id\":\"switch.wall_switch_ln_left_158d000239c546\"}","render_data":false,"mergecontext":"","x":1150,"y":1020,"wires":[["fb408198.59b41"]]},{"id":"63e71ed6.b46e6","type":"api-call-service","z":"59f4d8aa.25fef8","name":"","server":"94f0c0a9.629b6","service_domain":"switch","service":"turn_off","data":"{\"entity_id\":\"switch.wall_switch_ln_right_158d000239c546\"}","render_data":false,"mergecontext":"","x":1150,"y":1060,"wires":[["fb408198.59b41"]]},{"id":"5567fdb.c9aec04","type":"api-call-service","z":"59f4d8aa.25fef8","name":"","server":"94f0c0a9.629b6","service_domain":"switch","service":"turn_off","data":"{\"entity_id\":\"light.xiaomi_philips_eyecare_smart_lamp_2\"}","render_data":false,"mergecontext":"","x":1150,"y":1100,"wires":[["fb408198.59b41"]]},{"id":"54da9730.835f88","type":"api-call-service","z":"59f4d8aa.25fef8","name":"","server":"94f0c0a9.629b6","service_domain":"switch","service":"turn_on","data":"{\"entity_id\":\"switch.wall_switch_ln_left_158d000239c546\"}","render_data":false,"mergecontext":"","x":1170,"y":1180,"wires":[["e45bc4d0.292bd8"]]},{"id":"1bd5906f.a7b2","type":"api-call-service","z":"59f4d8aa.25fef8","name":"","server":"94f0c0a9.629b6","service_domain":"switch","service":"turn_on","data":"{\"entity_id\":\"switch.wall_switch_ln_right_158d000239c546\"}","render_data":false,"mergecontext":"","x":1170,"y":1220,"wires":[["e45bc4d0.292bd8"]]},{"id":"77eb6cf2.8b2514","type":"api-call-service","z":"59f4d8aa.25fef8","name":"","server":"94f0c0a9.629b6","service_domain":"switch","service":"turn_on","data":"{\"entity_id\":\"light.xiaomi_philips_eyecare_smart_lamp_2\"}","render_data":false,"mergecontext":"","x":1170,"y":1260,"wires":[["e45bc4d0.292bd8"]]},{"id":"fb408198.59b41","type":"function","z":"59f4d8aa.25fef8","name":"设置study_light变量状态为off","func":"flow.set('study_light','off');\nreturn null;","outputs":1,"noerr":0,"x":1480,"y":1060,"wires":[[]]},{"id":"e45bc4d0.292bd8","type":"function","z":"59f4d8aa.25fef8","name":"获取study_light变量状态为on","func":"flow.set('study_light','on');\nreturn null;","outputs":1,"noerr":0,"x":1480,"y":1280,"wires":[[]]},{"id":"4d0db3fe.5b336c","type":"debug","z":"59f4d8aa.25fef8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":730,"y":1040,"wires":[]},{"id":"94f0c0a9.629b6","type":"server","z":"","name":"Home Assistant","legacy":true,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}]



回复

使用道具 举报

40

主题

3056

帖子

1万

积分

超级版主

Nero

Rank: 8Rank: 8

积分
11149
金钱
8042
HASS币
182
发表于 2018-12-26 10:03:34 | 显示全部楼层
nodered 热潮~
Nero
回复

使用道具 举报

9

主题

242

帖子

1790

积分

金牌会员

Rank: 6Rank: 6

积分
1790
金钱
1548
HASS币
0
发表于 2018-12-26 10:06:43 | 显示全部楼层
我也没想到,我还有位置坐!!!!
回复

使用道具 举报

3

主题

286

帖子

2660

积分

版主

懵懂的小白

Rank: 7Rank: 7Rank: 7

积分
2660
金钱
2374
HASS币
0
发表于 2018-12-26 10:07:24 | 显示全部楼层
小白来学习
回复

使用道具 举报

15

主题

656

帖子

2832

积分

金牌会员

Rank: 6Rank: 6

积分
2832
金钱
2175
HASS币
91

教程狂人

QQ
发表于 2018-12-26 11:15:55 | 显示全部楼层
一直没上nodered
回复

使用道具 举报

27

主题

2143

帖子

8926

积分

论坛元老

Rank: 8Rank: 8

积分
8926
金钱
6778
HASS币
30

论坛元老

发表于 2018-12-26 11:32:33 | 显示全部楼层
L大,跟帖问一下,node怎么实现trigger.homeassistant.start,把ha启动作为触发条件呢
回复

使用道具 举报

8

主题

870

帖子

5218

积分

论坛元老

Rank: 8Rank: 8

积分
5218
金钱
4348
HASS币
0
发表于 2018-12-26 22:16:58 | 显示全部楼层
谢谢分享,
回复

使用道具 举报

8

主题

2073

帖子

6053

积分

论坛元老

流水无味

Rank: 8Rank: 8

积分
6053
金钱
3980
HASS币
145

灌水之王

发表于 2018-12-27 14:44:23 | 显示全部楼层
个嘿嘿  研究一下  node red 的列子都要上
回复

使用道具 举报

219

主题

1287

帖子

7941

积分

超级版主

Rank: 8Rank: 8

积分
7941
金钱
6624
HASS币
86

教程狂人论坛风云人物突出贡献

 楼主| 发表于 2018-12-28 02:06:58 | 显示全部楼层
情非殇 发表于 2018-12-26 11:32
L大,跟帖问一下,node怎么实现trigger.homeassistant.start,把ha启动作为触发条件呢 ...

没找到单纯只用node-red的办法

用ha自动化触发,然后通过curl命令 访问node-red的http in节点.
回复

使用道具 举报

27

主题

2143

帖子

8926

积分

论坛元老

Rank: 8Rank: 8

积分
8926
金钱
6778
HASS币
30

论坛元老

发表于 2018-12-28 15:45:53 | 显示全部楼层
lidicn 发表于 2018-12-28 02:06
没找到单纯只用node-red的办法

用ha自动化触发,然后通过curl命令 访问node-red的http in节点. ...

能请教下curl和http in的具体写法么,小白不太懂,我的土办法就只会虚拟一个input,通过input状态打通ha和node
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-21 18:31 , Processed in 0.433441 second(s), 37 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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