Ring doorbell

Hi @jsable, I have exactly the same issue.
Account and Doorbell are showing online in Paper UI / Things, both have status “OFF” Paper UI / Control.The Ring Event Created timestamp is exactly one hour of (1 hour earlier listed in Paper UI).
Best,
E

I would expect this could be related a different time zone bzw. the RIng service platform and you local one.

@zolakk
Maybe I just need an explanation, does the the switch channel “ring:account:XXXX:control#status” in the “Ring Account Binding Thing” and the switch “ring:doorbell:ZZZZ:control#status” channel in the “Ring Video Doorbell” thing actually do anything? Both have the status of “OFF” when I added these things in PaperUI.
I do have another question, that is about the event time, I followed the ring.items from your GitHub page, and the RingEventCreated is displayed as:

2020-01-19 @ 14:54:16

In the Rest API, when I get the item state, it’s showing:

2020-01-19T14:54:16.000-0500

Which should be 2020-01-19 @ 09:54:16, do I need to do some formatting in the item label, I’ve tried but formatting does not seem to correct for the -5 hours?

Thanks,
~John

I have installed and got the account working (with 2FA), thanks for a great job!

Haven’t tested the things yet, but they are both online.

/Peter

@markus7017 That’s certainly an option I hadn’t thought of, that I think might be doable. I’ll have to look into that. This project seems to have that ability, it’s a matter of decoding the .ts to java and seeing if the libraries used are available in a binding.

@EdwardV @jsable I took a look through the code, and the original code I forked and hacked to get working and I don’t see any code that actually uses the “Status” channel, so I think I’ll just remove it in the next build unless I find some reason for it that I haven’t found yet.

The time thing is something that has been driving me nuts to be honest. Here’s the code for that, which I’m sure is wrong but I haven’t been able to find good documentation on time handling. I think I will need to dig into what other bindings are doing and see if I can find one I can understand.

    ZonedDateTime zoned = ZonedDateTime
                .parse(jsonObject.getOrDefault(ApiConstants.EVENT_CREATED_AT, "?").toString());
        return zoned.toLocalDateTime().toString();

Maybe its possible by the use of ffmpeg, (I believe it can handle ts stream as well).
And maybe you could have some ideas from @matt1 who make the ipcamera binding.

I´m pretty sure there may be some ideas to work on even though Ring doorbell isnt a dedicated IP camera.

Yes ffmpeg can read and write h264.ts and mpeg2.ts as it is more about the contents of the file and not the container.

1 Like

what format is provided by the backend?
if it‘s an regular video format a browser should support it
so it‘s just reading the stream and writing into a file (spin of a dedicated thread to make it asynchronous)
I‘ll provide you the timezone code I use in the Shelly binding when getting home or tomorrow

Here we are:

  1. Get local time, timezone of the PC (systemDefault)
   public static DateTimeType getTimestamp() {
        return new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochSecond(now()), ZoneId.systemDefault()));
    }
  1. With given timezone
    public static DateTimeType getTimestamp(String zone, long timestamp) {
        ZoneId zoneId = ZoneId.of(zone);
        ZonedDateTime zdt = LocalDateTime.now().atZone(zoneId);
        int delta = zdt.getOffset().getTotalSeconds();
        return new DateTimeType(ZonedDateTime.ofInstant(Instant.ofEpochSecond(timestamp - delta), zoneId));
    }

This can be used if you are able to retrieve the timezone from the api service.

Reading a stream from a given URL

           String imageUrl = SERVLET_IMAGE_URL_BASE + uri;
            logger.debug("RachioImage: {} image '{}' from '{}'", request.getMethod(), uri, imageUrl);
            setHeaders(resp);
            URL url = new URL(imageUrl);
            URLConnection conn = url.openConnection();
            conn.setDoInput(true);
            conn.setDoOutput(true);
            reader = conn.getInputStream();
            writer = resp.getOutputStream();

            // read data in 4k chunks
            byte[] data = new byte[4096];
            int n;
            while (((n = reader.read(data)) != -1)) {
                writer.write(data, 0, n);
            }

With the rachio binding I had a problem that their code service doesn’t set the correct content type. What I did was creating a servlet, which runs on the OH system and redirects the requested so I could fix the image type and return the browser the correct media type

  • The Api return the media url, which will be rewritten to point to the local system (127.0.0.1)

  • The rewritten url becomes the channel value

  • so the browser will open this one, which in fact generates a request to the binding’s servlet

  • inside the binding I load the remote media and sends it to the browser, which then display the correct media fule

  • In your case you could do something similar. Store the file in a sub folder under /html so it’s accessible via http.

  • rewrite the url to point to that uri and update the channel with that value

  • the browser or other app opens this url, the binding catches the request and returns the file data to the client

  • some kind of round robin or timeline makes sure that your are not queuing endless video file

This is the servlet code: https://github.com/markus7017/org.openhab.binding.rachio/blob/master/src/main/java/org/openhab/binding/rachio/internal/api/RachioImageServlet.java

Awesome, thanks for the pointers. Some great ideas I hadn’t thought of for sure. The actual Ring video is mp4 and used to be able to be retrieved via simple wget, it’s just new authentication that was getting in the way. Hopefully I can make some time in the next few days to bang on this for a bit and get something done, it’s been an unusually busy time lately for some reason.

This should work the same way (in fact every format, which is supported by the browser/client app)
I would place the download folder somewhere under conf/html so you could rewrite the url with something like “http://127.0.0.1/static/&lt;ring folder>/<filename>” - keep the same file name, which should be unique.

fyi: there is also HttpUtil. downloadImage(), but I’m not sure if this also handled video files

I installed the ring binding 2.5.1 and have the same problem with a delay of about 30 to 60 seconds. Polling interval is set to 3 seconds. So i would expect to get an event after a ring notification with a max delay of 3 seconds and not 30 seconds. The delay is not caused by rule compilation. Using IFTTT i never had a delay but the service is not usable anymore with myopenhab cloud service.
I hope that anybody has a solution for this problem.

Did you set the polling delay on the device (doorbell, etc) thing, the account thing, or both?

I set the polling intervall on the device and account thing to 3 seconds. Location is Germany if this is relevant.

@markus7017 HttpUtil. downloadImage() unfortunately didn’t work, but your servlet idea seems to be bearing some fruit. I hope to have something up very soon with the video working via a servlet!

@fuslwusl I took a look at things and so far I don’t see anything in the binding that could be causing this, every time the poll interval is reached, it does a request to Ring’s server and if there is a new event then it updates the channels. Unfortunately this means that we are at the mercy of the ring side to post the event in a timely manner on that interface. I suspect IFTTT didn’t have that issue because they might be using a subscription type connection to an interface instead of polling the rest interface. It may be part of the perks of being in their “partner” program if that’s the case. Unfortunately as soon as I replied to the email thread I had with them that I was finally able to connect and poll data and asked if there was any way we could discuss getting into their partner program, they went from timely responses to radio silence.

I will keep digging into it though to see if there’s something we can do once I get a release with the video link put out.

Thanx for checking this again. I really hope Ring will open their system for basic features like motion and ring notifications. Amazon Echo devices are able to get the ring notifications since a few weeks. Perhaps there is a way to get these notifications from there or from IFTTT? The best way was IFTTT for me. But openhab doesn’t support it anymore. So it would be great to get realtime events using this binding.

I’ve put a new version of the binding here: org.openhab.binding.ring-2.5.1-SNAPSHOT.jar . This one should fix the time zone and time formatting, and includes providing a link to the last event video again. The binding puts up a servlet that runs at http://:8080/ring/video/ to provide an .mp4 of the video and will put that url in the channel. I’ve also cleaned up the logging to not include sensitive information in debug (only trace). Hopefully this one works for everyone.

1 Like

@zolakk,

I am clearly confused as to how the servlet for the ring video is suppose to work… do you have a walkthrough as to how it is set up? I have the URL showing as:

http://10.0.1.25:8080/ring/video/[Bunch of numbers here]

I put this URL in a browser and I get the play icon with a slash through it. I am at a loss, I just can’t seem to follow the documents that @markus7017 linked. I have a very limited knowledge base for coding.

~John

Whilst direct access is the holy grail, I’m getting an almost instantaneous doorbell press event into openHAB by using an Alexa routine.

I’ve exposed a “Door Bell” Switch item to Alexa, and on the Doorbell event from Ring, I’m setting this openHAB Switch to ON. I’ve then set up a Rule that when the “Door Bell” switch is set to ON, it plays ‘doorbell.mp3’ via openHAB into my multi-room audio setup. The Switch item is then set to OFF a second later.

This actually starts playing the sound through openHAB quicker than my Ring Chime and Echo devices do!

2 Likes