Binary Restful sensor value template help

I have been trying to create a Restful binary sensor for to pull the status of a Dahua camera’s LED. Unfortunately I can’t get it to work - no errors in the logs. Can anyone suggest anything that I’ve done wrong…

binary_sensor:   
    - platform: rest
      resource: http://192.168.88.51/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2[0][1][0].Mode
      method: GET
      authentication: digest
      username: *****
      password: *****
      name: Gate cam LED status
      device_class: light
      icon: mdi:led-on
      value_template: "{{ 'On' if value.split('=')[1] == 'Manual' else 'Off' }}"

The JSON response from the camera is as follows when the LED is on:

table.Lighting_V2[0][1][0].Mode=Manual

Based on the explanation in the third paragraph of the Restful Binary Sensor’s documentation, the template’s response should be on or off, not On or Off.

Thanks, but unfortunately this makes no difference.

How have you confirmed that all other parameters of the
REST call are correct?

BTW, what is the displayed current state of binary_sensor.gate_cam_led_status?

Current state is off. When the LED comes on and therefore to ‘Manual’ the binary sensor remains off. I’m pretty sure all the parameters are correct.

Try this simpler version:

value_template: "{{ 'Manual' in value }}"

If that fails to work, I suggest you create a Restful Sensor that simply reports the received value just to confirm that it is actually receiving the value you expect.

1 Like

Thanks, this has worked. Not sure why the original didn’t work. It doesn’t matter now but any ideas?

1 Like

The simplified template makes no assumptions about the received value’s structure. It just checks if the received string contains the string ‘Manual’ (and implicitly reports either boolean true or false).

The original template assumes the received value has a particular structure which it then proceeds to split into a list and compare the list’s second element to a string (‘Manual’) and then explicitly reports either on or off. There’s a lot more processing involved that can be derailed if the received value isn’t quite in the form one expected it to be.