[APP][Pro] Support for ONVIF compatible cameras (Release 2.0.41)

I checked the REST commands ( API-April, 2023 - Google Drive**) for Reolink camera’s and this seems to work for AI detection. First you have to login with a HTTP POST http://192.168.0.176/api.cgi?cmd=Login to obtain a token. The body should be like:

[
  {
    "cmd": "Login",
    "param": {
      "User": {
        "Version": "0",
        "userName": "admin",
        "password": "yourpassword"
      }
    }
  }
]

The response contains the token.

The AI states can be obtained with (of course one should use its own IP and token):
http://192.168.0.176/api.cgi?cmd=GetAiState&token=c4272d74d317e3e

The response looks like this:

[
   {
      "cmd" : "GetAiState",
      "code" : 0,
      "value" : {
         "channel" : 0,
         "dog_cat" : {
            "alarm_state" : 0,
            "support" : 0
         },
         "face" : {
            "alarm_state" : 0,
            "support" : 0
         },
         "people" : {
            "alarm_state" : 0,
            "support" : 1
         },
         "vehicle" : {
            "alarm_state" : 0,
            "support" : 1
         }
      }
   }
]

The alarm_state will be 1 in case the corresponding subject is detected by the camera.

So in this way the AI alerts from Reolink camera’s can still be used. How to integrate this in Homey I don’t know, I don’t speak Javascript. But maybe there is somebody willing to make a script for this.

Quick-and-dirty:

const ENDPOINT = 'http://192.168.0.176/api.cgi';

async function cmd(command, data, token = '', method = 'post') {
  const response = await fetch(`${ ENDPOINT }?cmd=${ command }&token=${ token }`, {
    method:  method,
    body:    method === 'post' ? JSON.stringify([ data ]) : undefined,
    headers: { 'content-type' : 'application/json' },
  });
  return (await response.json())[0]?.value;
}

const login = await cmd('Login', {
  cmd: 'Login',
  param: {
     User: {
      Version: '0',
      userName: 'username',
      password: 'password'
    }
  }
});

const token   = login?.Token?.name;
const aiState = await cmd('GetAiState', {}, token, 'get');

console.log('%j', aiState);
1 Like

That is quick! Thanks a lot. I tried the script and it is working perfectly. But now I am trying to parse the outcome to a Homey variable (person_detected). I am using Homeyscript and the script is working fine but how to convert just the “people alarm_state” to this variable I am still struggling with.

Try this:

await tag('person_detected', !!aiState?.people?.alarm_state);

Will try that. But now I discovered that if you trigger the script too many times you cannot login anymore due to the limited number of sessions. It looks like that everytime the script is run a new token is generated. Maybe I need a separate script for obtaining the token (and save it in a variable) that I run once every 5 minutes. The other script can then be executed once every 5 seconds or so to keep track of crooks wandering around my house.

How about triggering it when motion is detected by ONVIF as I think that will happen every time regardless of human, etc. Then use the script to filter the types of motion

1 Like

That’s a smart one! Only when there is a lot of movement the sessions might still become too many. But this idea can still be used I hope. I splitted Robert’s script up in 2. One runs every 5 minutes to obtain the token and the other every 5 seconds to check for humans. But that generates a lot of traffic Reolink apparently doesn’t like because the camera refuses to answer after some time. So I now will adjust the flow in such a way it will only be executed when the camera detects general movement. Fingers crossed.

I received the latest (beta) firmware for the RLC-520A (V2) from Reolink support and the AI ONVIF notifications seem to work now. You cannot download it from their website, you have to request support. Maybe because it is still in beta. Thanks you Adrian and Robert for your support.

2 Likes

Iam having an issue getting my REOLINK RLC-842A cams working with the new Homey Pro 2023.
The old Homey worked without problems but now it’s not finding any cams and i have to input them manually.
When i fill in all details i get and message: ERROR: could Not Get MAC Address
I have latest Cam firmware V3.1.0.0 , ONVIF V2.0.30 and latest Homey 10.0.0-rc.105 installed. ONVIF is enabled in the settings and https connection. both account admin or user account in reolink will get me the same error.
What is going wrong, do i need to set something in my REOLINK cams.

Can you try the latest test version, 2.0.40.

Hello and thank you for your suggestion i have tested it but still same ERROR: could Not Get MAC Address

Does it find the camera automatically with the new version?

Hello Adrian,
It says it found new devices but need to add them mannualy. after i type in the network specifics i get again the ERROR: could Not Get MAC Address


The “Add Manually” option appears if it can’t discover any cameras. Also the MAC address error also suggests Homey can’t communicate with the camera at a basic network level.

Is Homey on the same network/virtual lan as thecamera?

I’m trying to setup an Amcrest IP8M-T2599EW camera but can’t get it to work. Automatic detection does not work, but that is expected with the fw/router (pfSense) settings I have. So I try to add the camera manually. The camera is not located on the same network as Homey. All IPv4 traffic from Homey to the camera is accepted in fw/router.

I also get the “Error: Could Not Get MAC Address” after clicking “Login”. The only traffic I see going to the camera is ICMP pings.

The diagnostics log only have entries for the discovery process:

Log ID: 2023-05-31T10:12:43.068Z
App version 2.0.30

10:12:43.068: ====  Discovery Starting  ====
10:12:52.095: ====  Discovery Finished  ====
10:12:52.096: Discovered: []

I’m using ONVIF Camera v2.0.30 on a Homey Pro (Early 2023).
Homey is not connected over WiFi, only ethernet.
Any ideas how I can continue the troubleshooting?

Can you update to the test version (2.0.40)

That’s a requirement for Homey to access its MAC address, though (although I’m not sure why the ONVIF app needs its MAC address).

I get the same problem with 2.0.40.
It looks like the MAC address is used as a camera device ID in the app. I suppose that will not work for my setup since I have my cameras in a separate VLAN.

The MAC address is used to identify the camera as the UUID is not always sent in the ONVIF information.
I will make some changes to handle the failure and try a different approach to identify the camera.

1 Like

Sounds great, thanks! I’ll test it as soon as you have a test version ready.