RESTful binary sensor
RESTful 二值传感器集成使用设备、应用程序或 Web 服务通过 RESTful API 提供的端点。该二值传感器支持 GET 和 POST 请求。
提示: 如果您想使用同一个端点创建多个 sensors,请参考 RESTful 配置说明。
如果端点返回以下值对之一:0/1、"0"/"1"、FALSE/TRUE、false/true、off/on 或 closed/open,则可以直接使用。如果返回值不同,请使用模板。如果端点返回内容类型为 text/xml、application/xml 或 application/xhtml+xml 的 XML,它将根据此规范自动转换为 JSON。
配置
要启用此传感器,请将以下行添加到您的 "configuration.yaml" 文件中以进行 GET 请求:
或进行 POST 请求:
或基于模板的请求:
Using templates
For incoming data, a value template translates incoming JSON or raw data into a valid payload.
Incoming payloads are rendered with possible JSON values, so when rendering, the value_json variable can be used to access attributes in a JSON-based payload. Otherwise, the value variable can be used for non-JSON payloads.
The this variable can also be used in the template. The this attribute refers to the current entity state of the entity.
Further information about the this variable can be found in the template documentation.
Example value template with JSON:
With the following payload:
Template {{ value_json.temperature | round(1) }} renders to 21.9.
示例
在本节中,您将找到一些使用此传感器的实际示例。
aREST 传感器
不使用 aREST 二值传感器,您可以直接使用 REST 二值传感器检索支持 aREST 的设备的值。
访问受 HTTP 认证保护的端点
REST 传感器支持 HTTP 认证和支持模板的自定义标头。
标头将包含所有相关详细信息。这也使您能够访问受令牌保护的端点。

