Ring doorbell

@zolakk
There are 2 ways to dynamically find the port OH is running on

  1. just get the env var “OPENHAB_HTTP_PORT” - that was refused in the Review of the Shelly PR
  2. use HttpServiceUtil. getHttpServicePort (componentContext.getBundleContext()); in Handler Factory. sniplet from HandlerFactory:
   @Activate
    public ShellyHandlerFactory(@Reference NetworkAddressService networkAddressService,
            ComponentContext componentContext, Map<String, @Nullable Object> configProperties) {
        logger.debug("Activate Shelly HandlerFactory");
        super.activate(componentContext);

        this.coapServer = new ShellyCoapServer();
        Validate.notNull(coapServer, "coapServer creation failed!");

        Validate.notNull(configProperties);
        bindingConfig.updateFromProperties(configProperties);
        httpPort = HttpServiceUtil.getHttpServicePort(componentContext.getBundleContext());
        if (httpPort == -1) {
            httpPort = 8080;
        }
        Validate.isTrue(httpPort > 0, "Unable to get OH HTTP port");
        logger.debug("Using OH HTTP port {}", httpPort);

        String lip = networkAddressService.getPrimaryIpv4HostAddress();
        localIP = lip != null ? lip : "";
    }

Note: this already uses constructor injection for the HandlerFactory, which allows to get easy access to networkAddressService to obtain the selected default IP. This provides the local IP and OH port to build the URL. Does Ring supports retrieving the video through a https connection (would make sense)? In this case you need to obtain the local https port (default 8443).

1 Like

@zolakk With the correct port, the connection refused error has gone, but I still don’t seem to be getting any video. My browser now shows “No video with supported format or MIME type found”. A wget from a shell returns zero bytes.

Is there something else I’m missing?

@markus7017 thanks for the pointers again, I really, really appreciate it. This has been my first attempt at working on a binding (and java really in any meaningful sense) and it’s been a real challenge trying to reverse engineer what was done by the original author while trying to get new things to work by sorting through the documentation to try and fix the existing issues plus the new ones that crop up like these video issues.

@smar - The method I implemented in the version I last posted doesn’t seem to be working out so I scrapped it. What I have running in my dev environment is to have the binding automatically download the video file to a configurable local folder and have servlet then allows the download of that file from the folder on your local openhab. For instance, in my environment it downloads the videos into /etc/openhab2/html/ring/video as “FrontDoor-motion-2020-02-13T12-56-38.mp4” and if the download was successful after a number of retries in case the video isn’t quite ready yet, the url changes to “http://:/ring/video/FrontDoor-motion-2020-02-13T12-56-38.mp4” (formatted like DeviceName-EventType-DateTime - chose to replace the ":"s to “-” because it’s an invalid character). I also have it configured to save the last 10 files, but you would be able to set that to whatever you want, or 0 if you didn’t want to automatically download for some reason. I would like to run it for a few days in my environment before posting it to make sure it works as expected so we hopefully don’t have weird issues when everyone else tries it.

@jwiseman is having the url point to an actual file like I mentioned above what you were thinking? If you wanted just the file name (“FrontDoor-motion-2020-02-13T12-56-38.mp4” in my example), you could just split the string by the “/” character and take the last part.

1 Like

I can do that as a workable option.

Best, Jay

Cool, I just didn’t want to get channel creep as it were since I’m hopefully going to be able to add more channels in for different things soon now that I’m starting to understand how all this works :slight_smile:

send me a PM with your questions, may I could help

The latest version I tested over the weekend worked great with absolutely no issues. Didn’t go offline once and the timestamps on the downloaded videos match the timestamps in the ring app in under a minute using a 10 second poll interval! Here’s the new version: org.openhab.binding.ring-2.5.2-SNAPSHOT.jar. Note that the version has been updated to 2.5.2 so make sure to delete the previous file but otherwise it works just fine with my 2.5 release install.

There are some notes:

  • I added two new configuration parameters to the Account Thing - videoStoragePath and videoRetentionCount, so I think you’re going to have to delete and re-create your Account Thing and re-create it to pick those up.
  • videoStoragePath defaults to “/etc/openhab2/html/ring/video”, and will create that folder if it’s not already there. If you want to store your videos somewhere else, you can change it as long as the openhab user has the ability to write to that folder. If your’re a windows user, you’ll probably have to change that manually for now to a valid windows path.
  • For the things file folks, i’ve yet to figure out a way to auto detect that and give you the refresh token in the normal logs. For now if you set the logging to TRACE and watch for the response from ring when authenticating while the account thing is initializing you should see the response with the refresh token - i’d recommend putting it back to normal or debug after that though because otherwise you’ll get a log entry for every poll so it can fill up your logs pretty quickly. Put that big long string in your refreshToken parameter and you should not have issues with it stopping working because the session expired. Once you have that token in place, the binding ignores the username and password parameters so you can remove those if you want. If you want to use two factor authentication, you’re going to have to start off with the username and password, wait for the SMS and populate the twofactorCode parameter and once you get the refresh token, populate that and clear the username, password and twofactorCode parameters (if you want). You may have to restart the binding after putting in the two factor code, I didn’t have any issues with my testing though but keep in mind that it needs to all be done relatively fast so the SMS code doesn’t expire on you.
2 Likes

I was able to just drop it in after uninstalling the previous 2.5.1 version and everything went back online along with the new parameters showing up in the Thing Account.

I’m running OH 2.4 on a Synology and I used this path /volume1/homes/openhab/conf/html/ring/video

EDIT: I have tested it and it works great (for ding & motion); downloaded a 20mb video file to my system for each event.

Best, Jay

Can someone help me with the OH syntax to pull just the filename (FrontDoor-ding-2020-02-21T10-17-38.mp4) off this URL and assign it to a VAR?

http://192.168.0.230:8080/ring/video/FrontDoor-ding-2020-02-21T10-17-38.mp4

Best, Jay

In my rule, I use:

rule "Ring Trigger"
when
    Item Ring_Acct_Time changed
then
    createTimer(now.plusSeconds(30), [|
    executeCommandLine("wget " + Ring_Acct_URL.state.toString + " -O /etc/openhab2/html/ring.mp4", 5000)
    executeCommandLine("/etc/openhab2/scripts/./ring.sh")
end

This copies the ring video to the html folder 30 seconds after the time changes, and sends me a copy of the video through Telegram. Then on my sitemap, I have:

Video url="http://10.0.1.25:8080/static/ring.mp4" icon="ring"

So I can see the most recent video on my sitemap.

~John

There are lots of approaches. Using the String split it would be something like.

val parts = UrlString.split("/")
val filename = parts.get(parts.size-1)

That’s something different. You could use a simple replace assuming the first part always stays the same.

val newUrl = UrlString.replace("http://192.168.0.230:8080/ring/video/", "http://www.mypersonalURL/OHRing/")
1 Like

when i use this in habpanel in an iframe it downloads a 0Kb mp4 and does not show the video in the frame? I have files which i can open and view just fine in the video download folder. is there any way to get this to play in a widget on habpanel?

@Greigc,
I was having that 0 kb issue until I updated to the ver. 2.5.2 of the binding. What is the URL you are using for your video? I put the Video URL (see post above) in to a HABpanel frame widget and went to the “advanced” tab and clicked the box “fill to edges” and the most recent Ring video plays in scaled size (to the widget) without issue.

~John

1 Like

ok thats fixed that problem but how do i refresh the widget automatically upon new event?

Does anyone have a way to refresh the video feed to pickup the new ring.mp4 when its copied to the html folder and play it on detection on the new file?

Thanks works great but it takes about 30 seconds to get the Event. Any idea?

The only thing I can think of is that’s an issue on the ring end. Either they are being slow to post the event to your account or possibly your polling rate is too fast and you’re getting throttled by them if you’ve set it to less than the default 5 seconds.

I am still a newb with openhab. Just recently installed it on my Synology and slowly finding my way around things, items and rules…

I am failing to connect my ring account. I do have two factor on, so I enter credentials in the account thing, receive the two factor code and edit the account thing. I receive following error : OFFLINE - COMMUNICATION_ERROR Invalid username or password.

I guess the problem is with the two factor, but how do I get a refresh token?

Are you using a .things file or did you create the thing in paperui? If you did it in paperui, once the two factor code is put in, it should auto populate the refresh token as long as the correct code got put in before it expired

I added in paper UI and entered the code within the first minute or so. The code should be valid for 10 minutes.