智能家居安全系统指南

action.devices.types.SECURITYSYSTEM - 安防系统的报警器可以开启和关闭。它们的报警器可以设置为多个安全等级(例如,“在家”和“外出”),也可以报告有关某些传感器的信息,例如用于检测动作或打开的窗户的传感器。

这种类型表示设备会获得安全系统图标以及一些相关的同义词和别名。

设备功能

如需了解实现详情(例如您的服务应支持的属性和状态),以及如何构建 EXECUTE 和 QUERY 响应,请参阅相应的特征文档。

必需的特征

这些特征和命令是必需的(如果适用于您的设备)。如果您的设备不支持这些特征,请在 QUERY 或 EXECUTE 响应中输入错误代码 functionNotSupported。如需了解详情,请参阅错误和异常

如果适用于你的设备,建议启用这些特征。 不过,您可以随意组合和匹配所有可用特征,以便与现有产品功能完美匹配。

质量要求

  • 延迟时间:必须小于或等于 2000 毫秒
  • 可靠性:必须大于或等于 97%

示例设备:简单的安防系统

本部分包含示例 intent 载荷,这些 intent 载荷代表基于上述设备类型和特征的常见“安全系统”。如果您在实现中添加或移除特征,请相应地修改响应以反映这些更改。

SYNC 响应示例

请求
{
  "requestId": "6894439706274654512",
  "inputs": [
    {
      "intent": "action.devices.SYNC"
    }
  ]
}
响应
{
  "requestId": "6894439706274654512",
  "payload": {
    "agentUserId": "user123",
    "devices": [
      {
        "id": "123",
        "type": "action.devices.types.SECURITYSYSTEM",
        "traits": [
          "action.devices.traits.StatusReport",
          "action.devices.traits.ArmDisarm"
        ],
        "name": {
          "name": "Simple security system"
        },
        "willReportState": true,
        "attributes": {
          "availableArmLevels": {
            "levels": [
              {
                "level_name": "home_key",
                "level_values": [
                  {
                    "level_synonym": [
                      "Home and Guarding",
                      "level 1",
                      "home",
                      "SL1"
                    ],
                    "lang": "en"
                  }
                ]
              },
              {
                "level_name": "away_key",
                "level_values": [
                  {
                    "level_synonym": [
                      "Away and Guarding",
                      "level 2",
                      "away",
                      "SL2"
                    ],
                    "lang": "en"
                  }
                ]
              }
            ],
            "ordered": true
          }
        },
        "deviceInfo": {
          "manufacturer": "smart-home-inc",
          "model": "hs1234",
          "hwVersion": "3.2",
          "swVersion": "11.4"
        }
      }
    ]
  }
}

示例 QUERY 响应

请求
{
  "requestId": "6894439706274654514",
  "inputs": [
    {
      "intent": "action.devices.QUERY",
      "payload": {
        "devices": [
          {
            "id": "123"
          }
        ]
      }
    }
  ]
}
响应
{
  "requestId": "6894439706274654514",
  "payload": {
    "devices": {
      "123": {
        "status": "SUCCESS",
        "online": true,
        "isArmed": true,
        "currentArmLevel": "home_key",
        "currentStatusReport": [
          {
            "blocking": false,
            "deviceTarget": "123",
            "priority": 0,
            "statusCode": "lowBattery"
          }
        ]
      }
    }
  }
}

EXECUTE 命令示例

ArmDisarm

如需详细了解命令参数,请参阅 action.devices.traits.ArmDisarm 参考文档。

请求
{
  "requestId": "6894439706274654516",
  "inputs": [
    {
      "intent": "action.devices.EXECUTE",
      "payload": {
        "commands": [
          {
            "devices": [
              {
                "id": "123"
              }
            ],
            "execution": [
              {
                "command": "action.devices.commands.ArmDisarm",
                "params": {
                  "arm": true,
                  "armLevel": "away_key"
                }
              }
            ]
          }
        ]
      }
    }
  ]
}
响应
{
  "requestId": "6894439706274654516",
  "payload": {
    "commands": [
      {
        "ids": [
          "123"
        ],
        "status": "SUCCESS",
        "states": {
          "online": true,
          "isArmed": true,
          "currentArmLevel": "away_key"
        }
      }
    ]
  }
}

设备 ERRORS

查看错误和异常的完整列表。

报告报警异常

尝试开启或关闭系统报警器时,您可以通过通过 StatusReport 特征报告的异常代码提供其他上下文。 异常可报告为阻塞或非阻塞。

  • 非阻塞异常若被报告为“SUCCESS”状态,则表示异常未阻止报警或关闭。
  • 屏蔽异常若报告状态为“EXCEPTIONS”,则表示由于这些异常,报警或关闭报警器已停止。

通常与安全系统相关的异常代码包括:

  • doorOpen:门是开着的。
  • windowOpen:一个窗口已打开。
  • isOpen:传感器检测到有东西在打开(但不知道这是门还是窗户)。

示例:非阻塞异常

此示例展示了一种非阻塞异常,在这种异常中,即使报告了某个窗口,安防系统也处于开启状态。

User 把安防系统的安保等级设为高
Google 助理 好的,前窗是开着的。正在开启安防系统报警器,确保安防等级高
请求
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.ArmDisarm",
          "params": {
            "arm": true,
            "armLevel": "L2"
          }
        }]
      }]
    }
  }]
}
响应
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [
      {
        "ids": [
          "123"
        ],
        "status": "SUCCESS",
        "states": {
          "online": true,
          "isArmed": true,
          "currentArmLevel": "L2",
          "currentStatusReport": [
            {
              "blocking": false,
              "priority": 0,
              "statusCode": "windowOpen",
              "deviceTarget": "sensor_id1"
            }
          ]
        }
      }
    ]
  }
}

示例:屏蔽异常

User 把安防系统的安保等级设为高
Google 助理 控制安防系统时出错。前窗是开着的。
请求
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.ArmDisarm",
          "params": {
            "arm": true,
            "armLevel": "L2"
          }
        }]
      }]
    }
  }]
}
响应 2
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [
      {
        "ids": [
          "123"
        ],
        "status": "SUCCESS",
        "states": {
          "online": true,
          "isArmed": false,
          "currentArmLevel": "L2",
          "currentStatusReport": [
            {
              "blocking": true,
              "priority": 0,
              "statusCode": "windowOpen",
              "deviceTarget": "sensor_id1"
            }
          ]
        }
      }
    ]
  }
}

开启双重身份验证

如果您的报警流程要求用户通过双重身份验证对话框输入 PIN 码,您必须确认用户是否希望在出现有效的异常时(例如,窗或门打开时)要继续开启系统

在这种情况下,可能需要同时输入 PIN 码或口令,然后再进行确认。

示例:确认验证

在此示例中,用户尝试开启安防系统,但前门被检测到打开。用户确认即使前门是开着的,安防系统也应开启。

User 开启安防系统报警器。
Google 助理 前门是开着的。 确定要开启安防系统报警器吗?
User 是。
Google 助理 好的,正在开启安防系统报警器。

在第一轮中,您应该以 ackNeeded 质询回应。

请求 1
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.ArmDisarm",
          "params": {
            "arm": true
          }
        }]
      }]
    }
  }]
}
响应 2
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [
      {
        "ids": [
          "123"
        ],
        "status": "ERROR",
        "errorCode": "challengeNeeded",
        "challengeNeeded": {
          "type": "ackNeeded"
        },
        "states": {
          "isArmed": true,
          "currentArmLevel": "L2",
          "currentStatusReport": [
            {
              "blocking": false,
              "priority": 0,
              "statusCode": "doorOpen",
              "deviceTarget": "456"
            }
          ]
        }
      }
    ]
  }
}

Google 向您提出的后续请求将包含 ack 结果。

请求 2
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.ArmDisarm",
          "params": {
            "arm": true
          },
          "challenge": {
            "ack": true
          }
        }]
      }]
    }
  }]
}
响应
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [
      {
        "ids": [
          "123"
        ],
        "status": "SUCCESS",
        "states": {
          "isArmed": true
        }
      }
    ]
  }
}

示例:PIN 码和确认验证

此示例展示了用户尝试开启需要输入 PIN 码的安防系统报警器。 系统会检测到前窗和后窗都开着,并要求用户确认应继续开启报警器。

User 伸手去别。
Google 助理 您的 PIN 码是什么?
User 1234.
Google 助理 前窗和后窗似乎都处于打开状态。确定要继续开启安防系统报警器吗?
User 是。
Google 助理 好的,正在开启安防系统报警器

在第一个回合中,您应该使用标准的 pinNeeded 质询作为回应。

请求 1
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [{
          "id": "123"
        }],
        "execution": [{
          "command": "action.devices.commands.ArmDisarm",
          "params": {
            "arm": true
          }
        }]
      }]
    }
  }]
}
响应
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["456"],
      "status": "ERROR",
      "errorCode": "challengeNeeded",
      "challengeNeeded": {
        "type": "pinNeeded"
      }
    }]
  }
}

然后,Google 会进一步提出包含所提供 PIN 码的请求。为了支持第二轮,您应该使用 ackNeeded 质询响应,并提供更多信息,包括目标实验组级别和包含阻塞异常的当前状态报告。

请求 2
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [...],
        "execution": [{
          "command": "action.devices.commands.ArmDisarm",
          "params": {
            "arm": true,
            "armLevel": "away"
          },
          "challenge": {
            "pin": "1234"
          }
        }]
      }]
    }
  }]
}
响应
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [{
      "ids": ["456"],
      "status": "ERROR",
      "states": {
        "targetArmLevel": "away",
        "currentStatusReport": [{
            "blocking": true,
            "priority": 1,
            "deviceTarget": "front_window_id",
            "statusCode": "deviceOpen"
          },
          {
            "blocking": true,
            "priority": 1,
            "deviceTarget": "back_window_id",
            "statusCode": "deviceOpen"
          }
        ]
      },
      "errorCode": "challengeNeeded",
      "challengeNeeded": {
        "type": "ackNeeded"
      }
    }]
  }
}

Google 的后续请求将仅包含 ack 结果,而不包含第一轮提供的 PIN 码。

请求 3
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "inputs": [{
    "intent": "action.devices.EXECUTE",
    "payload": {
      "commands": [{
        "devices": [...],
        "execution": [{
          "command": "action.devices.commands.ArmDisarm",
          "params": {
            "arm": true,
            "armLevel": "away"
          },
          "challenge": {
            "ack": true
          }
        }]
      }]
    }
  }]
}
响应
{
  "requestId": "ff36a3cc-ec34-11e6-b1a0-64510650abcf",
  "payload": {
    "commands": [
      {
        "ids": [
          "123"
        ],
        "status": "SUCCESS",
        "states": {
          "isArmed": true
        }
      }
    ]
  }
}