again I recommend to download to download the video to a local folder (e.g. up to 10 files) and passt the local file/servlet url to the channel. In this case the trigger could be send when the download id complete. We know that the creation in their cloud is sync to the event and video might not be available at that time, so
start a download job, which tries to download the video for lets say 2min. When its not available pause for 15s and try again.
Once the download is started a http error cancels that cycle
the video gets saved to local disk, an async job could limit the number of files in that folder or folder size
once download is complete the binding posts the rewritten url to the channel, which could be used to define the image panel. A unique filename triggers a change to the item
In this case we are independent from async event vs video download, any expired tokens, you could keep as much videos as you like )even exceeding the cloud space) and could create a history of last x videos just by creating an html index page of that folder
I have this fully workng - the only problem is the token is invalid after 1 hour and the only way for it to get a new token is to restart openhab. could there be somthing added so it can get a new token automatically after 1 hour?
Ok, I am in need of a little help, both my Account and Doorbell Things are showing âonlineâ, but I am still getting a Zero kb file when I attempt to download the video. Can someone let me know where I am missing something? I have made some changes to the original rule posted earlier, using a change to the time of the last event. Also, it is not necessary for me to have the last 10 videos, they will be time stamped and saved when sent by telegram. Here is my code:
rule "Ring Trigger"
when
Item Ring_Acct_Time changed
then
createTimer(now.plusSeconds(30), [|
executeCommandLine("wget " + Ring_Acct_URL.state.toString + " -O /tmp/ring.mp4", 5000)
logInfo("Ring.com","Ring video should have downloaded")])
executeCommandLine("/etc/openhab2/scripts/./ring.sh")
logInfo("Ring.com","video should have been saved and sent by telegram")
end
This is my ring.sh file:
#!/bin/bash
curl -s -X POST "https://api.telegram.org/bot[BotNumber]:[Token]/sendVideo" -F chat_id=[ChatID] -F video="@/etc/openhab2/tmp/ring.mp4"
The telegram API will not send an empty file, but it will work with a downloaded video file from Ring.com, so that part works.
@Greigc Thatâs strange, the token should auto refresh for you. Mine has been online and refreshing since I posted the last version. How do you know itâs the token? Is it something in the log the binding is telling you or something else?
@jsable Itâs probably in how the servlet is doing things, which is weird because as far as I understand how it works, it just takes the data returned from the authenticated url and pumps it out to the client. I donât know why it seems to work fine for me but nobody else from what it seems so I guess I need to go back to the drawing board and look into having it download automatically as @markus7017 recommends, which is probably the best approach at the end of the day.
looking at the console in chrome i can see that the token is invaild after 1 hour. looking online ring reset the token every hour. its not getting a new token for some reason, i disabled 2fa but that has made no difference. If i restart openhab it will work ok for another hour.
Thanks @zolakk. For my url, I am getting: http://172.17.0.1:8080/ring/video/6792145905647442102
Although I can ping the ip, I get a connection refused from the url. I am guessing that this is because my openhab is running inside a docker container. I have tried by exposing the docker network as if it is directly connected to the host (using the --net=host option), but still no luck.
Is there anything else I can try? Also, would it be possible to manually set the ip and in particular, the port number, so as to avoid any potential conflicts?
My account and doorbell things were discovered through the paper UI, but I would have preferred to have them in a .things file. I am not a fan of paper UI.
@smar The servlet is just another url on your openhab setup just like /paperui or /habmin, etc is. Iâm not sure how to best display that so I just have it set to âhttp://< yourip >:8080/ring/video/< dingid >â, unfortunately that means that if youâre running on a port thatâs not 8080, the link wonât work. You should be able to reach it the same way you reach paper ui, just substitute /paperui at the end of the url with the /ring/video/ part and it should be accessible, assuming the video itself is available on the ring server.
@jsable as it stands now, the binding updates the account thing configuration with the refresh token from ring, which is then used in lieu of the username and password and is also to support two factor authentication. I believe that if itâs defined with a file, the account thing would not be able to update that value for you so youâd have to get that refresh token yourself (I used this link when I was testing before to get the token) and put it in the account thing config but if you did that, it should work I would think. The .thing examples are in the github that I have been posting the binding to, the account thing example is just missing the refreshToken parameter (for now). Iâm looking to see if I can detect if a thing is from a file vs paperui somehow so I can provide the refresh token in the logs to configure it with manually.
Iâm also working on the video download problem, my thought is to add two additional config parameters on the account thing - video storage path, which you could set to a folder on your box that openhab has rights to that will contain video files that will be automatically downloaded and video retention count that you could set to the number of past videos to keep on disk. That way the binding would do the downloading automatically and present a url to that now locally hosted file in the event url channel and keep the number of files on disk at whatever you want. Hopefully that works better than the previous solution I had, which seems to have a poor success rate it seems.
1 Like
jwiseman
(Mr. Wiseman (OH 4.3 Snapshot on Pi4))
234
Hey Zolakk,
Just a reminder; this field above, that is the file name, would be very helpful for those wanting to link to it remotely from OH when you get the downloading working.
Thanks @zolakk, and that makes sense. I have a response from with my normal openhab ip/port.
Just a suggestion (and not something to waste too much of your time on!) to avoid confusion for any future users who are not on port 8080, would it be worth either splitting the url to just the part after the ip/port or maybe having the user define what their ip/port is (or maybe take from the settings in PaperUIâs Configuration/System/Network Settings section?
BTW, I have refresh rates set at 3 seconds, but it seems to take an average of well over 90+ seconds after motion has been detected by the Ring bell, or the bell has been pressed, before I see any update in openhab. Iâm guessing this is due to Ring and not something we have any control over?
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).
@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.
@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
jwiseman
(Mr. Wiseman (OH 4.3 Snapshot on Pi4))
239
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
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
jwiseman
(Mr. Wiseman (OH 4.3 Snapshot on Pi4))
243
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
jwiseman
(Mr. Wiseman (OH 4.3 Snapshot on Pi4))
244
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?