HASS-出门检测
出门检测对于玩 HASS 来说还是非常有必要的,而如何准确触发就很重要了
目前好像还没不需要随身设备来判断人是否在家的技术,所以最方便的还是根据设备来判断,毕竟谁都有的就是手机
由于父母不和我住,所以我家只需要判断我和我老婆手机在不在家就可以了
这里介绍下我的出门检测方案,已经稳定使用一年
HomeKit 出门自动化
主要是通过 GPS 应该也有网络来触发设备是否在家的
优点
- 简单,只要简单配置自动化
- 高效,根据距离,出门大概 100 米触发
缺点
- 手机需要都是 iPhone,并且至少有一个 HomeKit 中枢
- 不是非常稳定
前提
- HASS 中配置一个 MQTT 出门模式的虚拟按钮(其他类型虚拟按钮也行,MQTT 比较通用)
- 家庭成员都使用 iPhone
- 家庭成员都加入了 HomeKit
- 家中有 HomeKit 中枢比如 HomePod
- HASS 中家的位置要设置准确,在 HASS 配置 -> 区域与地点-> 地点(一定要用自带地图的设置不要去其他地图找坐标)
步骤
-
HASS 添加出门模式虚拟按钮
HASS 的 MQTT 配置添加一个按钮
mqtt: switch: - unique_id: home_lock name: home_lock command_topic: homeassistant/home/lock/set payload_on: on payload_off: off
-
HomeKit 自动化触发虚拟按钮
iPhone Detect 插件
通过检测手机 5353 UDP 端口来实现的插件
优点
- 手机不需要都是 iPhone(测试过小米 MIX2S,华为 P30),其他手机自测
- 稳定
缺点
- 手机必须要一直连 WiFi(有些人晚上习惯断网,比如我老婆)
- 相对比较死板,根据时间来触发
前提
- HASS 中配置一个 MQTT 出门模式的虚拟按钮(其他类型虚拟按钮也行,MQTT 比较通用)
- 路由里通过 MAC 固定了 IP
- 关闭私有无线局域网地址(iPhone 要关否则 MAC 每次都是随机的,其他品牌自测)
步骤
-
HASS 添加出门模式虚拟按钮
同 HomeKit
-
安装插件
下载扔 custom_components 目录即可,大部分 HASS 插件都是这样装的
-
HASS 配置
consider_home: 1200 就是 20x60 秒,20 分钟没人就触发离线
不建议太短,比如你自己在家,下楼拿个快递太短可能就触发出门模式了
20 分钟对我来说只是保险,防止 HomeKit 未能及时触发而已
device_tracker: - platform: iphonedetect consider_home: 1200 scan_interval: 5 new_device_defaults: track_new_devices: true hosts: kevin_iphone: 192.168.2.60 miya_iphone: 192.168.2.61 laoba_iphone: 192.168.2.68 laoma_mix: 192.168.2.64
known_devices.yaml 添加如下设备信息,和上面 hosts 名一致
miya_iphone: name: miya_iphone mac: icon: picture: track: true kevin_iphone: name: kevin_iphone mac: icon: picture: track: true laoba_iphone: name: laoba_iphone mac: icon: picture: track: true laoma_mix: name: laoma_mix mac: icon: picture: track: true
重启 HASS 应该就能发现设备
-
NodeRED 添加一个出门检测的子流程
这个用来检测是否所有设备都离线了
[ { "id": "1b76ee6f5d2734ef", "type": "subflow", "name": "出门检测", "info": "", "category": "", "in": [], "out": [ { "x": 1560, "y": 260, "wires": [{ "id": "428a6a7e173f0c81", "port": 0 }] }, { "x": 1560, "y": 340, "wires": [{ "id": "428a6a7e173f0c81", "port": 1 }] } ], "env": [], "meta": {}, "color": "#DDAA99" }, { "id": "7de299e90219f084", "type": "server-state-changed", "z": "1b76ee6f5d2734ef", "name": "Kevin-iPhone", "server": "58e79fdb.2d76d", "version": 4, "exposeToHomeAssistant": false, "haConfig": [ { "property": "name", "value": "" }, { "property": "icon", "value": "" } ], "entityidfilter": "device_tracker.kevin_iphone", "entityidfiltertype": "exact", "outputinitially": false, "state_type": "str", "haltifstate": "", "halt_if_type": "str", "halt_if_compare": "is", "outputs": 1, "output_only_on_state_change": true, "for": "0", "forType": "num", "forUnits": "minutes", "ignorePrevStateNull": false, "ignorePrevStateUnknown": false, "ignorePrevStateUnavailable": false, "ignoreCurrentStateUnknown": false, "ignoreCurrentStateUnavailable": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "eventData" }, { "property": "topic", "propertyType": "msg", "value": "", "valueType": "triggerId" } ], "x": 170, "y": 240, "wires": [["b416ddacdbfbdf61"]] }, { "id": "120f5de7335c2d9d", "type": "server-state-changed", "z": "1b76ee6f5d2734ef", "name": "Miya-iPhone", "server": "58e79fdb.2d76d", "version": 4, "exposeToHomeAssistant": false, "haConfig": [ { "property": "name", "value": "" }, { "property": "icon", "value": "" } ], "entityidfilter": "device_tracker.miya_iphone", "entityidfiltertype": "exact", "outputinitially": false, "state_type": "str", "haltifstate": "", "halt_if_type": "str", "halt_if_compare": "is", "outputs": 1, "output_only_on_state_change": true, "for": "0", "forType": "num", "forUnits": "minutes", "ignorePrevStateNull": false, "ignorePrevStateUnknown": false, "ignorePrevStateUnavailable": false, "ignoreCurrentStateUnknown": false, "ignoreCurrentStateUnavailable": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "eventData" }, { "property": "topic", "propertyType": "msg", "value": "", "valueType": "triggerId" } ], "x": 170, "y": 280, "wires": [["b416ddacdbfbdf61"]] }, { "id": "b416ddacdbfbdf61", "type": "api-current-state", "z": "1b76ee6f5d2734ef", "name": "Kevin-iPhone", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "device_tracker.kevin_iphone", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "kevin", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 390, "y": 300, "wires": [["d842523529e6d488"]] }, { "id": "d842523529e6d488", "type": "api-current-state", "z": "1b76ee6f5d2734ef", "name": "Miya-iPhone", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "device_tracker.miya_iphone", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "miya", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 570, "y": 300, "wires": [["7c43f8d8ba88e46c"]] }, { "id": "bb57e6b5660babd2", "type": "function", "z": "1b76ee6f5d2734ef", "name": "判断是否出门", "func": "if (msg.kevin === \"home\" || msg.miya === \"home\" || msg.laoba === \"home\" || msg.laoma === \"home\") {\n msg.payload = \"home\"\n} else {\n msg.payload = \"not_home\"\n}\nreturn msg", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1160, "y": 300, "wires": [["428a6a7e173f0c81"]] }, { "id": "428a6a7e173f0c81", "type": "switch", "z": "1b76ee6f5d2734ef", "name": "不同状态输出", "property": "payload", "propertyType": "msg", "rules": [ { "t": "eq", "v": "home", "vt": "str" }, { "t": "eq", "v": "not_home", "vt": "str" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 1380, "y": 300, "wires": [[], []] }, { "id": "7c43f8d8ba88e46c", "type": "api-current-state", "z": "1b76ee6f5d2734ef", "name": "Laoba-iPhone", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "device_tracker.laoba_iphone", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "laoba", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 760, "y": 300, "wires": [["215ae03078be4097"]] }, { "id": "04a9517ad2c206a8", "type": "server-state-changed", "z": "1b76ee6f5d2734ef", "name": "Laoba-iPhone", "server": "58e79fdb.2d76d", "version": 4, "exposeToHomeAssistant": false, "haConfig": [ { "property": "name", "value": "" }, { "property": "icon", "value": "" } ], "entityidfilter": "device_tracker.laoba_iphone", "entityidfiltertype": "exact", "outputinitially": false, "state_type": "str", "haltifstate": "", "halt_if_type": "str", "halt_if_compare": "is", "outputs": 1, "output_only_on_state_change": true, "for": "0", "forType": "num", "forUnits": "minutes", "ignorePrevStateNull": false, "ignorePrevStateUnknown": false, "ignorePrevStateUnavailable": false, "ignoreCurrentStateUnknown": false, "ignoreCurrentStateUnavailable": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "eventData" }, { "property": "topic", "propertyType": "msg", "value": "", "valueType": "triggerId" } ], "x": 170, "y": 320, "wires": [["b416ddacdbfbdf61"]] }, { "id": "288b9bff326083e8", "type": "server-state-changed", "z": "1b76ee6f5d2734ef", "name": "Laoba-Mix", "server": "58e79fdb.2d76d", "version": 4, "exposeToHomeAssistant": false, "haConfig": [ { "property": "name", "value": "" }, { "property": "icon", "value": "" } ], "entityidfilter": "device_tracker.laoma_mix", "entityidfiltertype": "exact", "outputinitially": false, "state_type": "str", "haltifstate": "", "halt_if_type": "str", "halt_if_compare": "is", "outputs": 1, "output_only_on_state_change": true, "for": "0", "forType": "num", "forUnits": "minutes", "ignorePrevStateNull": false, "ignorePrevStateUnknown": false, "ignorePrevStateUnavailable": false, "ignoreCurrentStateUnknown": false, "ignoreCurrentStateUnavailable": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "eventData" }, { "property": "topic", "propertyType": "msg", "value": "", "valueType": "triggerId" } ], "x": 180, "y": 360, "wires": [["b416ddacdbfbdf61"]] }, { "id": "215ae03078be4097", "type": "api-current-state", "z": "1b76ee6f5d2734ef", "name": "Laoma-Mix", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "device_tracker.laoma_mix", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "laoba", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 950, "y": 300, "wires": [["bb57e6b5660babd2"]] }, { "id": "58e79fdb.2d76d", "type": "server", "name": "hass", "version": 5, "addon": false, "rejectUnauthorizedCerts": true, "ha_boolean": "y|yes|true|on|home|open", "connectionDelay": true, "cacheJson": false, "heartbeat": true, "heartbeatInterval": "30", "areaSelector": "friendlyName", "deviceSelector": "friendlyName", "entitySelector": "friendlyName", "statusSeparator": "at: ", "statusYear": "hidden", "statusMonth": "short", "statusDay": "numeric", "statusHourCycle": "h23", "statusTimeFormat": "h:m", "enableGlobalContextStore": true } ]
-
NodeRED 添加触发 home_lock 开关的自动化
[ { "id": "5bb5f23dd29ea145", "type": "subflow", "name": "存在检测", "info": "", "category": "", "in": [{ "x": 140, "y": 140, "wires": [{ "id": "f861f698a8c96b9a" }] }], "out": [ { "x": 940, "y": 240, "wires": [{ "id": "b046f0cb59ded4c2", "port": 0 }] }, { "x": 940, "y": 320, "wires": [{ "id": "b046f0cb59ded4c2", "port": 1 }] } ], "env": [], "meta": {}, "color": "#DDAA99" }, { "id": "f861f698a8c96b9a", "type": "api-current-state", "z": "5bb5f23dd29ea145", "name": "主卧毫米波", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "binary_sensor.master_espmmw_mmw", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "master", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 310, "y": 140, "wires": [["72a7238bb26e9316"]] }, { "id": "a26ee3721dbe0afd", "type": "function", "z": "5bb5f23dd29ea145", "name": "判断是否存在", "func": "if (msg.master === \"on\" || msg.living === \"on\" || msg.second === \"on\" || msg.bathroom === \"on\" || msg.kitchen === \"on\") {\n msg.payload = \"on\"\n} else {\n msg.payload = \"off\"\n}\nreturn msg", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 560, "y": 280, "wires": [["b046f0cb59ded4c2"]] }, { "id": "b046f0cb59ded4c2", "type": "switch", "z": "5bb5f23dd29ea145", "name": "不同状态输出", "property": "payload", "propertyType": "msg", "rules": [ { "t": "eq", "v": "on", "vt": "str" }, { "t": "eq", "v": "off", "vt": "str" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 760, "y": 280, "wires": [[], []] }, { "id": "72a7238bb26e9316", "type": "api-current-state", "z": "5bb5f23dd29ea145", "name": "客厅毫米波", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "binary_sensor.living_espmmw_mmw", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "living", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 310, "y": 200, "wires": [["d5cfd3c3785c0804"]] }, { "id": "d5cfd3c3785c0804", "type": "api-current-state", "z": "5bb5f23dd29ea145", "name": "次卧毫米波", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "binary_sensor.second_espmmw_mmw", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "second", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 310, "y": 260, "wires": [["7a4388343f2a36cf"]] }, { "id": "8bd84e522c13fbbe", "type": "api-current-state", "z": "5bb5f23dd29ea145", "name": "阳台毫米波", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "binary_sensor.balcony_espmmw_mmw", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "balcony", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 110, "y": 320, "wires": [[]] }, { "id": "7a4388343f2a36cf", "type": "api-current-state", "z": "5bb5f23dd29ea145", "name": "浴室毫米波", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "binary_sensor.bathroom_espmmw_mmw", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "bathroom", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 310, "y": 380, "wires": [["ec8f15df8f3e584f"]] }, { "id": "ec8f15df8f3e584f", "type": "api-current-state", "z": "5bb5f23dd29ea145", "name": "厨房毫米波", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "binary_sensor.kitchen_espmmw_mmw", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "kitchen", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 310, "y": 440, "wires": [["a26ee3721dbe0afd"]] }, { "id": "1b76ee6f5d2734ef", "type": "subflow", "name": "出门检测", "info": "", "category": "", "in": [], "out": [ { "x": 1560, "y": 260, "wires": [{ "id": "428a6a7e173f0c81", "port": 0 }] }, { "x": 1560, "y": 340, "wires": [{ "id": "428a6a7e173f0c81", "port": 1 }] } ], "env": [], "meta": {}, "color": "#DDAA99" }, { "id": "7de299e90219f084", "type": "server-state-changed", "z": "1b76ee6f5d2734ef", "name": "Kevin-iPhone", "server": "58e79fdb.2d76d", "version": 4, "exposeToHomeAssistant": false, "haConfig": [ { "property": "name", "value": "" }, { "property": "icon", "value": "" } ], "entityidfilter": "device_tracker.kevin_iphone", "entityidfiltertype": "exact", "outputinitially": false, "state_type": "str", "haltifstate": "", "halt_if_type": "str", "halt_if_compare": "is", "outputs": 1, "output_only_on_state_change": true, "for": "0", "forType": "num", "forUnits": "minutes", "ignorePrevStateNull": false, "ignorePrevStateUnknown": false, "ignorePrevStateUnavailable": false, "ignoreCurrentStateUnknown": false, "ignoreCurrentStateUnavailable": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "eventData" }, { "property": "topic", "propertyType": "msg", "value": "", "valueType": "triggerId" } ], "x": 170, "y": 240, "wires": [["b416ddacdbfbdf61"]] }, { "id": "120f5de7335c2d9d", "type": "server-state-changed", "z": "1b76ee6f5d2734ef", "name": "Miya-iPhone", "server": "58e79fdb.2d76d", "version": 4, "exposeToHomeAssistant": false, "haConfig": [ { "property": "name", "value": "" }, { "property": "icon", "value": "" } ], "entityidfilter": "device_tracker.miya_iphone", "entityidfiltertype": "exact", "outputinitially": false, "state_type": "str", "haltifstate": "", "halt_if_type": "str", "halt_if_compare": "is", "outputs": 1, "output_only_on_state_change": true, "for": "0", "forType": "num", "forUnits": "minutes", "ignorePrevStateNull": false, "ignorePrevStateUnknown": false, "ignorePrevStateUnavailable": false, "ignoreCurrentStateUnknown": false, "ignoreCurrentStateUnavailable": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "eventData" }, { "property": "topic", "propertyType": "msg", "value": "", "valueType": "triggerId" } ], "x": 170, "y": 280, "wires": [["b416ddacdbfbdf61"]] }, { "id": "b416ddacdbfbdf61", "type": "api-current-state", "z": "1b76ee6f5d2734ef", "name": "Kevin-iPhone", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "device_tracker.kevin_iphone", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "kevin", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 390, "y": 300, "wires": [["d842523529e6d488"]] }, { "id": "d842523529e6d488", "type": "api-current-state", "z": "1b76ee6f5d2734ef", "name": "Miya-iPhone", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "device_tracker.miya_iphone", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "miya", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 570, "y": 300, "wires": [["7c43f8d8ba88e46c"]] }, { "id": "bb57e6b5660babd2", "type": "function", "z": "1b76ee6f5d2734ef", "name": "判断是否出门", "func": "if (msg.kevin === \"home\" || msg.miya === \"home\" || msg.laoba === \"home\" || msg.laoma === \"home\") {\n msg.payload = \"home\"\n} else {\n msg.payload = \"not_home\"\n}\nreturn msg", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 1160, "y": 300, "wires": [["428a6a7e173f0c81"]] }, { "id": "428a6a7e173f0c81", "type": "switch", "z": "1b76ee6f5d2734ef", "name": "不同状态输出", "property": "payload", "propertyType": "msg", "rules": [ { "t": "eq", "v": "home", "vt": "str" }, { "t": "eq", "v": "not_home", "vt": "str" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 1380, "y": 300, "wires": [[], []] }, { "id": "7c43f8d8ba88e46c", "type": "api-current-state", "z": "1b76ee6f5d2734ef", "name": "Laoba-iPhone", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "device_tracker.laoba_iphone", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "laoba", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 760, "y": 300, "wires": [["215ae03078be4097"]] }, { "id": "04a9517ad2c206a8", "type": "server-state-changed", "z": "1b76ee6f5d2734ef", "name": "Laoba-iPhone", "server": "58e79fdb.2d76d", "version": 4, "exposeToHomeAssistant": false, "haConfig": [ { "property": "name", "value": "" }, { "property": "icon", "value": "" } ], "entityidfilter": "device_tracker.laoba_iphone", "entityidfiltertype": "exact", "outputinitially": false, "state_type": "str", "haltifstate": "", "halt_if_type": "str", "halt_if_compare": "is", "outputs": 1, "output_only_on_state_change": true, "for": "0", "forType": "num", "forUnits": "minutes", "ignorePrevStateNull": false, "ignorePrevStateUnknown": false, "ignorePrevStateUnavailable": false, "ignoreCurrentStateUnknown": false, "ignoreCurrentStateUnavailable": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "eventData" }, { "property": "topic", "propertyType": "msg", "value": "", "valueType": "triggerId" } ], "x": 170, "y": 320, "wires": [["b416ddacdbfbdf61"]] }, { "id": "288b9bff326083e8", "type": "server-state-changed", "z": "1b76ee6f5d2734ef", "name": "Laoba-Mix", "server": "58e79fdb.2d76d", "version": 4, "exposeToHomeAssistant": false, "haConfig": [ { "property": "name", "value": "" }, { "property": "icon", "value": "" } ], "entityidfilter": "device_tracker.laoma_mix", "entityidfiltertype": "exact", "outputinitially": false, "state_type": "str", "haltifstate": "", "halt_if_type": "str", "halt_if_compare": "is", "outputs": 1, "output_only_on_state_change": true, "for": "0", "forType": "num", "forUnits": "minutes", "ignorePrevStateNull": false, "ignorePrevStateUnknown": false, "ignorePrevStateUnavailable": false, "ignoreCurrentStateUnknown": false, "ignoreCurrentStateUnavailable": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "eventData" }, { "property": "topic", "propertyType": "msg", "value": "", "valueType": "triggerId" } ], "x": 180, "y": 360, "wires": [["b416ddacdbfbdf61"]] }, { "id": "215ae03078be4097", "type": "api-current-state", "z": "1b76ee6f5d2734ef", "name": "Laoma-Mix", "server": "58e79fdb.2d76d", "version": 3, "outputs": 1, "halt_if": "", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "device_tracker.laoma_mix", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" }, { "property": "laoba", "propertyType": "msg", "value": "", "valueType": "entityState" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 950, "y": 300, "wires": [["bb57e6b5660babd2"]] }, { "id": "58e79fdb.2d76d", "type": "server", "name": "hass", "version": 5, "addon": false, "rejectUnauthorizedCerts": true, "ha_boolean": "y|yes|true|on|home|open", "connectionDelay": true, "cacheJson": false, "heartbeat": true, "heartbeatInterval": "30", "areaSelector": "friendlyName", "deviceSelector": "friendlyName", "entitySelector": "friendlyName", "statusSeparator": "at: ", "statusYear": "hidden", "statusMonth": "short", "statusDay": "numeric", "statusHourCycle": "h23", "statusTimeFormat": "h:m", "enableGlobalContextStore": true }, { "id": "95deecef72bb0fd1", "type": "subflow:1b76ee6f5d2734ef", "z": "4544820f.0a393c", "name": "", "x": 100, "y": 2220, "wires": [["1d8e314c935989ef"], ["f4599563d244388f"]] }, { "id": "b0ea267e21371e4e", "type": "api-call-service", "z": "4544820f.0a393c", "name": "启动出门模式", "server": "58e79fdb.2d76d", "version": 5, "debugenabled": false, "domain": "switch", "service": "turn_on", "areaId": [], "deviceId": [], "entityId": ["switch.home_lock"], "data": "", "dataType": "jsonata", "mergeContext": "", "mustacheAltTags": false, "outputProperties": [], "queue": "none", "x": 640, "y": 2240, "wires": [[]] }, { "id": "fad2b925d1dd2201", "type": "api-call-service", "z": "4544820f.0a393c", "name": "关闭出门模式", "server": "58e79fdb.2d76d", "version": 5, "debugenabled": false, "domain": "switch", "service": "turn_off", "areaId": [], "deviceId": [], "entityId": ["switch.home_lock"], "data": "", "dataType": "jsonata", "mergeContext": "", "mustacheAltTags": false, "outputProperties": [], "queue": "none", "x": 480, "y": 2200, "wires": [[]] }, { "id": "1d8e314c935989ef", "type": "api-current-state", "z": "4544820f.0a393c", "name": "出门模式启动", "server": "58e79fdb.2d76d", "version": 3, "outputs": 2, "halt_if": "on", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "switch.home_lock", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 280, "y": 2200, "wires": [["fad2b925d1dd2201"], []] }, { "id": "f4599563d244388f", "type": "api-current-state", "z": "4544820f.0a393c", "name": "出门模式关闭", "server": "58e79fdb.2d76d", "version": 3, "outputs": 2, "halt_if": "off", "halt_if_type": "str", "halt_if_compare": "is", "entity_id": "switch.home_lock", "state_type": "str", "blockInputOverrides": false, "outputProperties": [ { "property": "payload", "propertyType": "msg", "value": "", "valueType": "entityState" }, { "property": "data", "propertyType": "msg", "value": "", "valueType": "entity" } ], "for": "0", "forType": "num", "forUnits": "minutes", "override_topic": false, "state_location": "payload", "override_payload": "msg", "entity_location": "data", "override_data": "msg", "x": 280, "y": 2240, "wires": [["4c16915da38d4d9a"], []] }, { "id": "4c16915da38d4d9a", "type": "subflow:5bb5f23dd29ea145", "z": "4544820f.0a393c", "name": "", "x": 460, "y": 2240, "wires": [[], ["b0ea267e21371e4e"]] } ]
自动化
上面准备工作都做好后自动化就简单多了
只要根据 home_lock 开关的状态来触发不同的自动化就好了,例如:出门关闭所有灯等设备
总结
- 其实如果家里有毫米波雷达,还可以在触发 home_lock 开关之前加个判断,检测家里的所有毫米波是否真的没有人了,防止误触引发家庭矛盾,而且出门模式后毫米波可以用来触发报警
- 能保证稳定其实是多重判断的结果,只用 HomeKit 或者插件都可能导致误触或未触发