Reolink camera motion parse json

Hello everybody :smiley:,

today i implemented my reolink WLAN cameras in HA I run in a Docker container.
Please recognize these entries i made in the configurations.yaml to do it:

camera:
  - platform: generic
    name: Innen
    still_image_url: !secret Innen_URL
    stream_source: !secret Innen_Source 
  - platform: generic
    name: Haustuer
    still_image_url: !secret Haustuer_URL
    stream_source: !secret Haustuer_Source

binary_sensor:
  - platform: rest
    resource: !secret reolink1
    name: Motion Haustuer
    scan_interval: 1
    #value_template: “{{ value_json[0].value.state }}"
    value_template: “{{ value_json0.value.state }}" 

Via the following in the !secret file i get response from the camera when posted

reolink1: "http://192.168.178.___/api.cgi?cmd=GetMdState&user=admin&password=YOUR_PW"

posting http://192.168.178.___/api.cgi?cmd=GetMdState&user=admin&password=YOUR_PW in my browser returs:

[ { “cmd” : “GetMdState”, “code” : 0, “value” : { “state” : 0 } } ]

or:

[ { “cmd” : “GetMdState”, “code” : 0, “value” : { “state” : 1 } } ]

When motion is present in front of the camera --> this works so far

The stream is accessiable via a picture glance card with this config:

aspect_ratio: 55%
camera_image: camera.haustuer
camera_view: live
entities:
  - entity: camera.haustuer
  - entity: binary_sensor.motion_haustur
title: Haustür
type: picture-glance

However, my progress ended when I tried to establish a motion detection with the binary sensor setup.

The binary sensor in the card does not respond on motion nor is in the sensor history a motion recorded whereas i recive notifications of events via the reolink app.

Does anyone has a clue what needs to added to the binary sensor configuration to make this work?

Thank you in advance for your time!

Best regards
Thorsten

try this as the value_template:

{{ (value_json.split('{ ')[2]).split(' }')[0][-1:] }}

…does not change the response.

I played a bit with Template developer tool and found that

{% set my_test_json = { "cmd" : "GetMdState", "code" : 0, "value" : { "state" : **0** } } %}
{{ my_test_json.value.state}}

simply returns a 1 or a 0, when i change the state in the message manually

It smells like the rest intergration is somehow not getting the message.

Oh, oops.

I should have added a bit more to the template.

A binary sensor has to return true or false. since your template is returning a 1 or 0 that won’t work.

try this then:

{{ ((value_json.split('{ ')[2]).split(' }')[0][-1:] )  == '1'}}

or maybe without the quotes around the 1. I’m not sure they are needed with the new data types.

you can play with it in the template editor to make sure it returns “True”.

Also future reference I don’t see your replies unless you tag me by using @finity in your post or you click the reply button at the bottom of my post to reply directly to me.

Hi,

i finally could make my application work without the use of a REST based sensor. I could manage to install the last REOLINK Intergration i found on Github and deploy the provided services and sensors.

Anyway i tried to add the last you noted to the template but i did not worked out. When i compared the sensor history of the Reolink based sensor and the REST based sensor it did not match up. The REST one do not work.

Even though thanks for your reply and time spend answering my issue!

BR
Thorsten