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:
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.
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.
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.