home-assistant.io/source/_components/binary_sensor.rest.markdown
2016-09-04 11:41:10 +02:00

2.2 KiB

layout, title, description, date, sidebar, comments, sharing, footer, ha_category, ha_release
layout title description date sidebar comments sharing footer ha_category ha_release
page RESTful Binary Sensor Instructions how to integrate REST binary sensors into Home Assistant. 2015-12-17 19:10 true false true true Binary Sensor 0.10

The rest binary sensor platform is consuming a given endpoint which is exposed by a RESTful API of a device, an application, or a web service. The binary sensor has support for GET and POST requests.

The JSON messages can contain different values like 1, "1", TRUE, true, on, or open. If the value is nested then use a template.

{
    "name": "Binary sensor",
    "state": {
        "open": "true",
        "timestamp": "2016-06-20 15:42:52.926733"
    }
}

To enable this sensor, add the following lines to your configuration.yaml file for a GET request:

# Example configuration.yaml entry
binary_sensor:
  platform: rest
  resource: http://IP_ADDRESS/ENDPOINT
  method: GET
  name: REST GET binary sensor
  sensor_class: opening
  value_template: '{% raw %}{{ value_json.state }}{% endraw %}'
  verify_ssl: False

or for a POST request:

# Example configuration.yaml entry
binary_sensor:
  platform: rest
  resource: http://IP_ADDRESS/ENDPOINT
  method: POST
  name: REST POST binary sensor
  sensor_class: opening
  value_template: '{% raw %}{{ value_json.state }}{% endraw %}'
  payload: '{ "device" : "door" }'

Configuration variables:

  • resource (Required): The resource or endpoint that contains the value.
  • method (Optional): The method of the request. Default is GET.
  • name (Optional): Name of the REST binary sensor.
  • sensor_class (Optional): The type/class of the sensor to set the icon in the frontend.
  • value_template (Optional): Defines a template to extract the value.
  • payload (Optional): The payload to send with a POST request. Usualy formed as a dictionary.
  • verify_ssl (Optional): Verify the certification of the endpoint. Default to True.

Make sure that the URL matches exactly your endpoint or resource.