Hi everyone,
I’m struggling to setup REST binary connectivity sensor based on my router’s API and would really appreciate your help or even just a second opinion. What really confuses me is that the same code works for REST sensor but doesn’t work for REST BINARY sensor. So,
Given:
an XML response that provides connectivity status among other parameters:
<packet>
<response id="1">
<checked>Mon Apr 12 19:11:24 2021</checked>
<enabled>yes</enabled>
<reliable>yes</reliable>
<gateway-accessible>yes</gateway-accessible>
<dns-accessible>yes</dns-accessible>
<host-accessible>yes</host-accessible>
<internet>yes</internet>
<gateway>
<interface>GigabitEthernet0/Vlan2</interface>
<address>11.111.111.111</address>
<failures>0</failures>
<accessible>yes</accessible>
<excluded>no</excluded>
</gateway>
</response>
</packet>
REST sensor code that correctly pulls “internet” status from response:
- platform: rest
name: Online
resource: http://192.168.0.1/ci
method: POST
payload: '<request id="1"><command name="show internet status"></command></request>'
authentication: digest
username: !secret router_user
password: !secret router_pass
headers:
Content-Type: application/xml
scan_interval: 15
value_template: '{{ true if "yes" in value_json.packet.response.internet else false }}'
Same code placed under binary_sensor domain doesn’t work, have no idea why. Triple checked manuals, tried to use 1 & 0 instead of true & false’, no results. Please help.
P.S: I am aware that for REST templates xml code gets translated to JSON first, so my current assumption is that there might be an issue related to this specific case. Hoping to be proven wrong.