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

 找回密码
 立即注册
查看: 5836|回复: 2

[流程系列] 【求助】NR判断状态控制网关警戒和空净设置

[复制链接]

22

主题

184

帖子

1524

积分

金牌会员

Rank: 6Rank: 6

积分
1524
金钱
1340
HASS币
10
发表于 2020-11-9 08:50:57 | 显示全部楼层 |阅读模式
本帖最后由 Anooki 于 2020-11-9 10:43 编辑

刚接触Node-RED,想写一个流程来控制网关的报警器和空气净化器,逻辑如下
1.离家场景:当手机的状态为切换为away或者office(即不在家的时候),就检查网关报警的状态
                   如果状态为disarmed(关闭),就打开报警器(服务为alarm_arm_away)
2.回家场景:当入口的人体感应器检测到人,就判断人的位置是不是在家(home),
                    如果在家,再检测网关警戒状态,如果为armed_away,就关闭警戒(服务为alarm_arm_home)
  回家场景:接着上一条,如果检测到人,也判断在家,就同时检测客厅控制质量,如果AQI>=50,
                   就打开空气净化器
3.打开空净场景:每半个小时检测一次手机状态,如果状态为home,就检测AQI是否>=50,如果大于就再检测
                          空净状态,如果为off,就打开空净
4.关闭空净场景:接上一条,如果AQI<50,为了避免误差,五分钟后再检测一次,如果AQI依然<50,
                          就关闭空净

我写了一版,但是不执行,有大佬帮忙看一下吗?
设备型号如下(都是小米的,可以用米家去设置,但是我还是想试试NR怎么做):
1.网关Aaqra网关,状态为disarmed、alarm_arm_away
2.小米人体感应器,状态为on、off
3.小米空气净化器pro,状态为on、off,AQI就是数值
4.通过iPhone追踪位置,状态为home、office、away
代码如下:
[{"id":"132f1615.25daaa","type":"tab","label":"网关警戒","disabled":false,"info":""},{"id":"964619b5.0aaec8","type":"api-current-state","z":"132f1615.25daaa","name":"网关警戒状态","server":"451fbac5.90e684","version":1,"outputs":2,"halt_if":"disarmed","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"alarm_control_panel.aqara_hub_7e29","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":360,"y":60,"wires":[["c192cde1.171ef"],[]]},{"id":"c192cde1.171ef","type":"api-call-service","z":"132f1615.25daaa","name":"打开警戒","server":"451fbac5.90e684","version":1,"debugenabled":false,"service_domain":"alarm_control_panel","service":"alarm_arm_away","entityId":"alarm_control_panel.aqara_hub_7e29","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":620,"y":60,"wires":[[]]},{"id":"f39c8932.6b4978","type":"api-call-service","z":"132f1615.25daaa","name":"关闭警戒","server":"451fbac5.90e684","version":1,"debugenabled":false,"service_domain":"alarm_control_panel","service":"alarm_arm_home","entityId":"alarm_control_panel.aqara_hub_7e29","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":720,"y":200,"wires":[["f26e8a15.cb3ca8"]]},{"id":"db4d3902.cf1678","type":"server-state-changed","z":"132f1615.25daaa","name":"上班","server":"451fbac5.90e684","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"device_tracker.anooki_iphone","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"office","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":150,"y":135,"wires":[["964619b5.0aaec8"],[]]},{"id":"9c7be457.37f928","type":"server-state-changed","z":"132f1615.25daaa","name":"外出","server":"451fbac5.90e684","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"device_tracker.anooki_iphone","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"away","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":150,"y":65,"wires":[["964619b5.0aaec8"],[]]},{"id":"944fc1a3.402ec","type":"trigger-state","z":"132f1615.25daaa","name":"检测到人","server":"451fbac5.90e684","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.motion_sensor_7ad9","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":160,"y":200,"wires":[["42ecd344.b5385c"],[]]},{"id":"42ecd344.b5385c","type":"api-current-state","z":"132f1615.25daaa","name":"获取状态","server":"451fbac5.90e684","version":1,"outputs":2,"halt_if":"home","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"device_tracker.anooki_iphone","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":340,"y":200,"wires":[["cfebb3fe.b1acb","434ab82b.397758"],[]]},{"id":"cfebb3fe.b1acb","type":"api-current-state","z":"132f1615.25daaa","name":"网关警戒状态","server":"451fbac5.90e684","version":1,"outputs":2,"halt_if":"armed_away","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"alarm_control_panel.aqara_hub_7e29","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":540,"y":200,"wires":[["f39c8932.6b4978","820de085.17c8c"],[]]},{"id":"434ab82b.397758","type":"api-current-state","z":"132f1615.25daaa","name":"AQI水平","server":"451fbac5.90e684","version":1,"outputs":2,"halt_if":"50","halt_if_type":"num","halt_if_compare":"gte","override_topic":false,"entity_id":"sensor.xiaomi_ap_aqi","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":620,"y":340,"wires":[["580b09d8.d9d618","78016b4e.b4a2b4"],["67e0b5a8.9c2fdc"]]},{"id":"86484691.1243b8","type":"api-call-service","z":"132f1615.25daaa","name":"打开空净","server":"451fbac5.90e684","version":1,"debugenabled":false,"service_domain":"fan","service":"turn_on","entityId":"fan.xiaomi_air_purifier_pro","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":980,"y":340,"wires":[["7a859a16.530b74"]]},{"id":"580b09d8.d9d618","type":"api-current-state","z":"132f1615.25daaa","name":"空净状态","server":"451fbac5.90e684","version":1,"outputs":2,"halt_if":"off","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"fan.xiaomi_air_purifier_pro","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":800,"y":340,"wires":[["86484691.1243b8","bafca89e.380f88"],[]]},{"id":"fb092e40.a54ae","type":"trigger","z":"132f1615.25daaa","name":"半个小时检测一次","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-30","extend":false,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":270,"y":340,"wires":[["15c62023.ad16a"]]},{"id":"15c62023.ad16a","type":"api-current-state","z":"132f1615.25daaa","name":"获取状态","server":"451fbac5.90e684","version":1,"outputs":2,"halt_if":"home","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"device_tracker.anooki_iphone","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":440,"y":340,"wires":[["434ab82b.397758"],[]]},{"id":"67e0b5a8.9c2fdc","type":"api-current-state","z":"132f1615.25daaa","name":"空净状态","server":"451fbac5.90e684","version":1,"outputs":2,"halt_if":"on","halt_if_type":"num","halt_if_compare":"is","override_topic":false,"entity_id":"fan.xiaomi_air_purifier_pro","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":800,"y":400,"wires":[["a689d3e2.9ac91"],[]]},{"id":"a689d3e2.9ac91","type":"delay","z":"132f1615.25daaa","name":"延迟5分钟","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":970,"y":400,"wires":[["5f1a4741.1d4e88"]]},{"id":"5f1a4741.1d4e88","type":"api-current-state","z":"132f1615.25daaa","name":"AQI水平","server":"451fbac5.90e684","version":1,"outputs":2,"halt_if":"50","halt_if_type":"num","halt_if_compare":"lte","override_topic":false,"entity_id":"sensor.xiaomi_ap_aqi","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1120,"y":400,"wires":[["629f1d0c.50e654"],[]]},{"id":"629f1d0c.50e654","type":"api-call-service","z":"132f1615.25daaa","name":"关闭空净","server":"451fbac5.90e684","version":1,"debugenabled":false,"service_domain":"fan","service":"turn_off","entityId":"fan.xiaomi_air_purifier_pro","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1280,"y":400,"wires":[[]]},{"id":"e2e37e3b.48d59","type":"inject","z":"132f1615.25daaa","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":90,"y":340,"wires":[["fb092e40.a54ae"]]},{"id":"78016b4e.b4a2b4","type":"debug","z":"132f1615.25daaa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":280,"wires":[]},{"id":"bafca89e.380f88","type":"debug","z":"132f1615.25daaa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1040,"y":280,"wires":[]},{"id":"820de085.17c8c","type":"debug","z":"132f1615.25daaa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":780,"y":160,"wires":[]},{"id":"f26e8a15.cb3ca8","type":"debug","z":"132f1615.25daaa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":960,"y":220,"wires":[]},{"id":"7a859a16.530b74","type":"debug","z":"132f1615.25daaa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1180,"y":340,"wires":[]},{"id":"451fbac5.90e684","type":"server","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
还有,我做了导航查询,有上班和回家两个时间,我想实现如果超过超过十二点就显示回家时间,没超过就显示上班时间,这个怎么做?
(主要是不知道怎么去判断两个时间点的大小)
回复

使用道具 举报

15

主题

438

帖子

4346

积分

论坛元老

Rank: 8Rank: 8

积分
4346
金钱
3908
HASS币
0
发表于 2020-11-9 10:04:13 | 显示全部楼层
你这个代码导入进去就一个节点..  其他什么都没有,怎么可能执行
回复

使用道具 举报

22

主题

184

帖子

1524

积分

金牌会员

Rank: 6Rank: 6

积分
1524
金钱
1340
HASS币
10
 楼主| 发表于 2020-11-9 10:42:35 | 显示全部楼层
本帖最后由 Anooki 于 2020-11-9 10:44 编辑
miniknife 发表于 2020-11-9 10:04
你这个代码导入进去就一个节点..  其他什么都没有,怎么可能执行

我这边都有显示的 11.png

应该是之前代码复制错了,已经更新了
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-21 21:47 , Processed in 1.166776 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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