我的智能家居之路——如何利用homeassistant实现厕所自动开关灯
创作立场声明:本文所有使用设备均为本人自费购入
追加修改(2021-04-28 21:47:55):
题目修改为:homeassistant系列(三):我的智能家居之路——如何利用homeassistant实现厕所自动开关灯
看到这个题目有人肯定会说这不很简单吗?买一个声控或者感应灯泡人过开灯或者喊一声开灯不就行了,但是如果你蹲在厕所里不动,是不是需要过一会喊一声嘿哈呢。
现在智能家居越来越深入人心,当然米家的接受度更高,因为设置简单。但是个人使用过程中觉得小米家不是很好,主要存在一下几个问题:1.感应间隔时间太长,小米人体感应器是1分钟感应一次,这就让人很无语了,1分钟后有可能检测不到你的存在直接给你把灯关了,而且你挥手半天它都不感应再次开灯。2.你的家里不可能全是小米的,所以如果有其他的设备存在,加入不到米家,无法联动。
实现功能:
有人自动开灯,没有人活动自动关灯,如果开灯后厕所门关闭,则灯永不会关闭。只有在门打开,并且厕所中无人活动感应,灯才会关闭。避免了人在蹲厕所,直接关灯的尴尬。
家里万一有老人习惯用开关,开关与这个感应不冲突。
所需设备
所需要用到的设备如下:
1.易微联网关
2.易微联人体感应器(感应间隔可调,最短可以调成2S左右)
3.小米的门窗感应器,因为小米的比易微联的感应宽度更大,需要搭配小米的网关使用。当然为了省钱也可以选择易微联的wifi门窗感应器。
斜着放感应范围更大点,不需要完全对牢。
4.易微联的灯座
5.433开关
折腾过程
1.安装homeassisant,本文章不做赘述,玩智能家居的都懂,因为我本身家里有软路由24h运行,所以我选择在虚拟机中添加了homeassisant。当然也可以NAS docker中安装,网上教程较多。
2.在/config/configuration.yaml中加入如下:
sonoff: #易微联
username: +8613xxxxxxxxxx(注意:后有一个空格,username前有2个空格)
password: 你的易微联账号密码(注意:后有一个空格, password前有2个空格)
reload: always (注意:后有一个空格, reload前有2个空格)
3.完成第二步后重启homeassistant,然后可以在开发者工具中的实体中查看到每个设备的ID及状态情况。
4.我选择安装的为hassio套装,所以在supervisor中安装了Node-red
5.将下面的流程复制,在Node-red导入节点,将会得到下面的流程,延迟20s自己可以调短,总的思路就是当易微联的人体感应器感应到关闭后,感应小米门窗感应器的闭合状态,如果是打开的则延迟20s后再次查看易微联人体感应器的状态,如果依然为关闭状态则执行下一步,最后关闭灯。如果是打开状态则返回前面再次检测小米门窗感应器的状态,形成一个只要是人在就无限循环20s不关闭灯。后面我加入了一个易微联插座作为这个自动化的开关按钮,如果这个插座是关闭的,则这个自动化关闭,此步(即方框内)可选择不加入。
[{"id":"243d5c6a.1ee6c4","type":"api-call-service","z":"c7f06fcb.6204a","name":"打开厕所灯","server":"542f76fd.960708","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.sonoff_100111159e","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":810,"y":80,"wires":[["5149747b.27721c"]]},{"id":"5149747b.27721c","type":"debug","z":"c7f06fcb.6204a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":970,"y":80,"wires":[]},{"id":"2fd2dcb6.1dc934","type":"server-state-changed","z":"c7f06fcb.6204a","name":"厕所易微联人體感應器","server":"3a7ec2db.61d00e","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.sonoff_a40000899c","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":220,"y":80,"wires":[["b0113d9d.6542e"]]},{"id":"b0113d9d.6542e","type":"switch","z":"c7f06fcb.6204a","name":"on/off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":80,"wires":[["243d5c6a.1ee6c4"],[]]},{"id":"8bb09429.5ac4f8","type":"api-call-service","z":"c7f06fcb.6204a","name":"关闭厕所灯","server":"542f76fd.960708","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.sonoff_100111159e","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1090,"y":240,"wires":[["ced0e7eb.13d668"]]},{"id":"ced0e7eb.13d668","type":"debug","z":"c7f06fcb.6204a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1270,"y":240,"wires":[]},{"id":"182e34bb.849dbb","type":"server-state-changed","z":"c7f06fcb.6204a","name":"厕所易微联人體感應器","server":"3a7ec2db.61d00e","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.sonoff_a40000899c","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":220,"y":140,"wires":[["e615c0f3.c85c9"]]},{"id":"87ec82a2.9c889","type":"delay","z":"c7f06fcb.6204a","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1000,"y":160,"wires":[["5432e42e.eadfac"]]},{"id":"e615c0f3.c85c9","type":"switch","z":"c7f06fcb.6204a","name":"on/off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":140,"wires":[[],["62116c08.6e2bb4"]]},{"id":"62116c08.6e2bb4","type":"api-current-state","z":"c7f06fcb.6204a","name":"厕所横门感应状态","server":"542f76fd.960708","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.e4aaec36eee6_contact","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":650,"y":160,"wires":[["3ee89f76.99fa9"]]},{"id":"3ee89f76.99fa9","type":"switch","z":"c7f06fcb.6204a","name":"on/off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":160,"wires":[["87ec82a2.9c889"],[]]},{"id":"5432e42e.eadfac","type":"api-current-state","z":"c7f06fcb.6204a","name":"再次厕所感应器状态","server":"542f76fd.960708","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.sonoff_a40000899c","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":580,"y":240,"wires":[["7055d792.3728f8"],["62116c08.6e2bb4"]]},{"id":"b891ce90.b5a53","type":"comment","z":"c7f06fcb.6204a","name":"厕所感应开关灯","info":"","x":200,"y":40,"wires":[]},{"id":"7055d792.3728f8","type":"api-current-state","z":"c7f06fcb.6204a","name":"开关厕所关灯自动化","server":"542f76fd.960708","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.sonoff_1000b37519","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":840,"y":240,"wires":[["8bb09429.5ac4f8"],[]]},{"id":"542f76fd.960708","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"3a7ec2db.61d00e","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]
总结
我家是老房子,老旧线路的局限也阻拦不了我变懒的决心,智能家居的使用让生活更加方便。第一次发文,如有不足评论指出。












校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案
校验提示文案