亲邻开门

小区门禁改造,可以通过 App 和小程序开单元门,不过还是不够方便,参考了这篇文章,抓取小程序的 SESSION,通过 NodeRED 接入 HASS

抓包

iPhone 使用 Stream 抓包,抓小程序(多亲开门+)的包,如何抓包可以 Google,找到这个接口,复制sessionId=wxmini:后的字符串(SESSION)备用

qinlin1

NodeRED

将抓包得到的 SESSION 填入 NodeRED 的亲邻SESSION

qinlin2

定时任务是为了防止 SESSION 失效,多亲的 SESSION 是 1800 秒

SESSION 可能不定期失效,可在定时任务后添加 SESSION 失效推送,我用的 Bark 教程有空出

[
  {
    "id": "c5b34bf5ebeed3ed",
    "type": "tab",
    "label": "流程 2",
    "disabled": false,
    "info": "",
    "env": []
  },
  {
    "id": "12be2044802e765e",
    "type": "inject",
    "z": "c5b34bf5ebeed3ed",
    "name": "每五分钟",
    "props": [{ "p": "payload" }, { "p": "topic", "vt": "str" }],
    "repeat": "300",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "",
    "payloadType": "date",
    "x": 250,
    "y": 120,
    "wires": [["8079dd0eb0d99e06"]]
  },
  {
    "id": "d057f6d6355919ce",
    "type": "http request",
    "z": "c5b34bf5ebeed3ed",
    "name": "",
    "method": "POST",
    "ret": "txt",
    "paytoqs": "ignore",
    "url": "",
    "tls": "",
    "persist": false,
    "proxy": "",
    "insecureHTTPParser": false,
    "authType": "",
    "senderr": false,
    "headers": [],
    "x": 880,
    "y": 120,
    "wires": [["a37e829627e514c4"]]
  },
  {
    "id": "1e81127fcdd33c48",
    "type": "change",
    "z": "c5b34bf5ebeed3ed",
    "name": "刷新亲邻SESSION",
    "rules": [
      {
        "t": "set",
        "p": "url",
        "pt": "msg",
        "to": "$join(\t   [\t       'https://mobileapi.qinlinkeji.com/api/wxmini/v3/appuser/refresh?sessionId=wxmini:',\t        session\t   ]\t)",
        "tot": "jsonata"
      }
    ],
    "action": "",
    "property": "",
    "from": "",
    "to": "",
    "reg": false,
    "x": 690,
    "y": 120,
    "wires": [["d057f6d6355919ce"]]
  },
  {
    "id": "8079dd0eb0d99e06",
    "type": "change",
    "z": "c5b34bf5ebeed3ed",
    "name": "亲邻SESSION",
    "rules": [
      {
        "t": "set",
        "p": "session",
        "pt": "msg",
        "to": "亲邻SESSION",
        "tot": "str"
      }
    ],
    "action": "",
    "property": "",
    "from": "",
    "to": "",
    "reg": false,
    "x": 460,
    "y": 120,
    "wires": [["1e81127fcdd33c48"]]
  },
  {
    "id": "92730cfb256f1ebc",
    "type": "switch",
    "z": "c5b34bf5ebeed3ed",
    "name": "判断是否失效",
    "property": "success",
    "propertyType": "msg",
    "rules": [{ "t": "eq", "v": "false", "vt": "str" }],
    "checkall": "true",
    "repair": false,
    "outputs": 1,
    "x": 700,
    "y": 220,
    "wires": [[]]
  },
  {
    "id": "a37e829627e514c4",
    "type": "change",
    "z": "c5b34bf5ebeed3ed",
    "name": "获取SESSION状态",
    "rules": [
      {
        "t": "set",
        "p": "success",
        "pt": "msg",
        "to": "$string($eval(payload).success)",
        "tot": "jsonata"
      },
      { "t": "set", "p": "id", "pt": "msg", "to": "亲邻开门", "tot": "str" },
      { "t": "set", "p": "state", "pt": "msg", "to": "失效", "tot": "str" }
    ],
    "action": "",
    "property": "",
    "from": "",
    "to": "",
    "reg": false,
    "x": 470,
    "y": 220,
    "wires": [["92730cfb256f1ebc"]]
  },
  {
    "id": "a04a0a77e5feacc1",
    "type": "mqtt in",
    "z": "c5b34bf5ebeed3ed",
    "name": "楼下门禁",
    "topic": "homeassistant/building/door",
    "qos": "2",
    "datatype": "auto",
    "broker": "98873a95.6b9878",
    "nl": false,
    "rap": false,
    "rh": "0",
    "inputs": 0,
    "x": 240,
    "y": 300,
    "wires": [["45c25d30df844784"]]
  },
  {
    "id": "45c25d30df844784",
    "type": "change",
    "z": "c5b34bf5ebeed3ed",
    "name": "亲邻SESSION",
    "rules": [
      {
        "t": "set",
        "p": "session",
        "pt": "msg",
        "to": "亲邻SESSION",
        "tot": "str"
      }
    ],
    "action": "",
    "property": "",
    "from": "",
    "to": "",
    "reg": false,
    "x": 460,
    "y": 300,
    "wires": [["588ac63f902de5b8"]]
  },
  {
    "id": "9adc291aca20da84",
    "type": "http request",
    "z": "c5b34bf5ebeed3ed",
    "name": "",
    "method": "POST",
    "ret": "txt",
    "paytoqs": "ignore",
    "url": "",
    "tls": "",
    "persist": false,
    "proxy": "",
    "insecureHTTPParser": false,
    "authType": "",
    "senderr": false,
    "headers": [],
    "x": 880,
    "y": 300,
    "wires": [[]]
  },
  {
    "id": "588ac63f902de5b8",
    "type": "change",
    "z": "c5b34bf5ebeed3ed",
    "name": "亲邻开门",
    "rules": [
      {
        "t": "set",
        "p": "url",
        "pt": "msg",
        "to": "$join(\t   [\t       'https://mobileapi.qinlinkeji.com/api/open/doorcontrol/v2/open?sessionId=wxmini:',\t       session\t   ]\t)",
        "tot": "jsonata"
      },
      {
        "t": "set",
        "p": "headers",
        "pt": "msg",
        "to": "{\"content-type\":\"multipart/form-data\"}",
        "tot": "json"
      },
      {
        "t": "set",
        "p": "payload",
        "pt": "msg",
        "to": "{\"doorControlId\":\"225237\",\"macAddress\":\"23DABA014201\",\"communityId\":\"18523\"}",
        "tot": "json"
      }
    ],
    "action": "",
    "property": "",
    "from": "",
    "to": "",
    "reg": false,
    "x": 680,
    "y": 300,
    "wires": [["9adc291aca20da84"]]
  },
  {
    "id": "98873a95.6b9878",
    "type": "mqtt-broker",
    "name": "ji",
    "broker": "192.168.2.12",
    "port": "1883",
    "clientid": "",
    "autoConnect": true,
    "usetls": false,
    "compatmode": false,
    "protocolVersion": "5",
    "keepalive": "60",
    "cleansession": true,
    "birthTopic": "",
    "birthQos": "0",
    "birthRetain": "false",
    "birthPayload": "",
    "birthMsg": {},
    "closeTopic": "",
    "closeQos": "0",
    "closeRetain": "false",
    "closePayload": "",
    "closeMsg": {},
    "willTopic": "",
    "willQos": "0",
    "willRetain": "false",
    "willPayload": "",
    "willMsg": {},
    "userProps": "",
    "sessionExpiry": ""
  }
]

HASS

添加 MQTT 开关,这样就可以通过 MQTT 来控制 NodeRED 调用开门关门

mqtt:
  switch:
    - unique_id: home_lock
      name: home_lock
      command_topic: homeassistant/home/lock/set
      payload_on: on
      payload_off: off