From the blog

Front Porch AI Motion Alerts with Reolink, Hubitat, Alexa, and Apple Home

By The Local Home · · 4 min read

#hubitat#reolink#alexa#apple-home#cameras#ai

When the front porch camera sees someone coming, my phone gets a notification that the front porch detected motion, and Alexa announces it. I have found this to work better than any driveway sensor, because the built-in AI has fewer false positives than the driveway alarm.

My goal is for things to be available where I use them, which here means my phone and my voice assistants. The camera already does the AI detection. I just needed it to show up somewhere useful.

How it works

I exposed it via Hubitat as a sensor. When that sensor detects motion, Alexa announces it. Also when it detects it, Apple Home sends a notification. Only for vehicles right now.

  1. A Reolink camera on the front porch does its own AI detection for people, vehicles, pets, and faces.
  2. A custom Hubitat driver logs in to the camera over Reolink’s HTTP API on my network and polls its AI state every few seconds.
  3. The driver runs on a virtual device that acts as a motion sensor. I have only Vehicle turned on for now, so other motion doesn’t trip it. I’ve considered turning on Person for nighttime.
  4. Hubitat shares that sensor to Alexa through the Amazon Echo Skill and to Apple Home through HomeKit Bridge.
  5. An Alexa routine announces when the sensor goes active, and an Apple Home automation sends a notification. I’m not covering those steps in detail here. In general, both apps let you pick a motion sensor as the trigger.

How I got here

It took a few tries. I started with ONVIF events through my NVR, which never produced any events. I asked whether I could point at the camera’s own IP instead of the NVR, and the camera responded, but ONVIF on the camera didn’t give events either. At that point I agreed to switch to Reolink’s native HTTP API. Version 1.3 of the driver worked perfectly. Then I asked for filtering by detection type, which became version 1.4.

An AI assistant wrote the code. I ran each version on the hub and reported the logs and errors back, and I pulled in ideas from Claude, ChatGPT, and Nemotron along the way.

The driver

You can download the driver here: reolink-ai-motion-sensor.groovy. It was written with an AI assistant, so use it at your own risk. It isn’t affiliated with or supported by Reolink.

To use it, enable the API on the camera, add the file under Drivers Code in Hubitat, create a virtual device with this driver, then fill in the camera’s IP, username, password, and channel, save, and click Initialize. What worked for me was pointing it straight at the camera, not the NVR, with HTTPS on port 443 and channel 0.

This is the polling part. It asks for generic motion with a GET and for the AI state with a POST:

def pollState() {
    if (!tokenValid()) { login(); return }
    int ch = (settings.channel ?: 0) as int

    asynchttpGet("handleMdState", [
        uri             : apiUrl(),
        query           : [cmd: "GetMdState", channel: ch, token: state.token],
        timeout         : 5,
        ignoreSSLIssues : true
    ])

    String aiBody = JsonOutput.toJson([[
        cmd    : "GetAiState",
        action : 0,
        param  : [channel: ch]
    ]])
    asynchttpPost("handleAiState", [
        uri                : apiUrl(),
        query              : [cmd: "GetAiState", token: state.token],
        headers            : ["Content-Type": "application/json"],
        body               : aiBody,
        requestContentType : "application/json",
        timeout            : 5,
        ignoreSSLIssues    : true
    ])
}

The response has people, vehicle, dog_cat, and face entries, and an alarm_state of 1 means that type is detected. The driver holds motion active for a set time after the last detection and logs back in to the camera periodically to keep its session fresh.

ignoreSSLIssues is on because the camera uses a self-signed certificate. That’s fine for a camera on your own network, but it does mean the driver isn’t checking the certificate, so don’t point it at anything outside your LAN. Use a camera account and password you don’t use anywhere else.