Help with a RESTful Binary Sensor - JSON value_template

I hope someone can help with this. What should be a very simple RESTful binary sensor is driving me a little crazy. I’m trying to monitor the state of an input on a door intercom. The JSON response is as follows:

  "success" : true,
  "result" : {
    "ports" : [
        "port" : "input1",
        "state" : 0

And my binary sensor yaml is this:

  - platform: rest
    name: Input 1
    username: admin
    password: SECRET PASSWORD
    verify_ssl: false
    value_template: "{{ value_json['result']['ports'][0]['state'] }}"
    method: GET

The result is that the sensor constantly gives a value of ‘Off’ regardless of whether the JSON state value is 1 or 0. I must be missing something really simply, but I just can’t see it. Any help greatly appreciated.

1 Like