Server Sent Events/EventStream

So I have been playing around with trying to create a device handler for my Netgear Arlo cameras. The API use Server Sent Events to notify subscribing devices of changes. Basically you open an event stream and subscribe to what you want and messages are sent on that event stream. I can get it to 'sort of' work. It is really inconsistent and I am not sure why. I am using a method that I found in @tonesto7 nstEventstream device handler called eventStreamConnect(). I cannot find any documentation of this method or really anything about eventStreams in hubitat anywhere. It does sort of work like I said, but I don't seem to get the messages the majority of the time.

Does anyone have any info or thoughts on this or know anything more about this eventStreamConnect method? I would greatly appreciate any info that might steer me in the right direction or if this is something that simply isn't supported I guess make me give up! :slight_smile: Thanks a lot!

What API? Their API isn't public.

I am well aware of that, but there are many well documented api's for connecting to the Arlo cameras and controlling them on github. Using one of them I do get all of the notifications I would expect to get in hubitat but don't. The only difference is the eventStream part which I am just not sure how to do in hubitat.

That's why i asked what API. A link to the one you are using might be helpful.

Sorry I didn't realize what you meant. I have been primarily using

When I just use his api to connect and subscribe I get all the events including motion etc. He uses a python library called sseClient to handle everything. If you look at @tonesto7 code below, he is doing some sort of eventStream with the Nest, although I have no idea where he got those methods from.

You've written an app and drivers to connect to the api?

No app, just a decide handler. I've just been getting started trying to see if it was doable. The handler just makes an http call to get the auth token then calls that eventStreamConnect method and the subscribe method. It all appears to work. I get success responses, but I don't get the messages. I actually did get them once randomly, but then the event stream timed out and I can't seem to get them again. That's why I'm posting here, just not sure where to go next.

Just to show that it does "sort of work" sometimes, playing around today and I got to connect and get the events being sent. The events from the eventStream are the ones that start with "parsed":

But then it disconnects and I change nothing and reconnect and no more events. I really don't understand it. Anyone have any ideas? Thanks

Can't add anything unfortunately but very keen to see you succeed in this effort!

Thanks! I really hope I can figure out the inconsistency of my current attempt too. I wish I know what the deal was. I have to believe there are quite a few Arlo users that would like something like this. If worse comes to worse I'll create a certain that user a server like a raspberry pi as a middle man, but native would be way better. I am hoping one of the smart guys can give my some guidance. We shall see.

For sure. The key thing for me is to be able to activate/deactivate each camera individually because currently their IFTTT integration does not support custom modes. So that would be super useful!

Cheers.

Yup I totally agree. Current integration is pretty terrible. What you want is totally possible. I'll get something built. Hopefully @patrick or @bravenel can provide some insight. Thanks!

1 Like

Would be really great if there could be some documentation on this... I can't find anything and would like to try to set this up to receive firebase events

@dman2306 Yea there really is no documentation on the EventStream interface. I think it was orginally added just for the Nest Manager integration. I found that and copied it to get my arlo stuff started. I had to get them to make a slight change to make it work for me, but they were very receptive and helped me out. Look at the nest manager app below and it will give you the basics. There really isn't much too it. I don't know anything about firebase or how the authentication works, but it may work. If not there are some changes coming that may make it work as well depending on what you need.

I was able to get it working following the example here. Just curious, what changes did you need to have made?

I need to be able to send authorization headers including cookies. Nothing earth shattering. Glad you got it working!

1 Like

@njschwartz did you ever get this working?

I am attempting to use the eventStream, but am unable to actually set the headers, using the currently documented version, it just seems to ignore them currently.

def openStream(){
log.debug "Opening Event Stream"
closeStream();
interfaces.eventStream.connect("https://##/hmsweb/client/subscribe?token=${state.token}",[
    pingInterval: 5,
    headers:[
        Authorization: state.token,
        "Content-Type" : "application/json; charset=utf-8",
        "User-Agent" : "Mozilla/5.0 (iPhone; CPU iPhone OS 11_1_2 like Mac OS X) AppleWebKit/604.3.5 (KHTML, like Gecko) Mobile/15B202 NETGEAR/v1 (iOS Vuezone)",
        Accept : "application/json",
        ]
    ]
  )              

}

I know what you’re trying to do here because I recognize the URL.

Try this. It passes authentication correctly but events never appear and it disconnects after exactly 1 minute. This implies it’s not answering pings from the server although I never did any debugging.

		// Connect to the remote event socket
		try
		{
            log.debug "[pingInterval: 5, headers: [Referer: \"https://my.arlo.com/\", Accept: \"text/event-stream\"]" + parent.arloLogin()
			log.info "Attempting socket connection to ${device.label ?: device.name} (${state.connectionAttempts})"
            interfaces.eventStream.connect("https://zzzz.com/hmsweb/client/subscribe", [pingInterval: 60, headers: [Referer: "https://my.arlo.com/", Accept: "text/event-stream", "Referrer-Policy": "no-referrer-when-downgrade"] + parent.arloLogin()])
		}
		catch(errorException)
		{
		}
1 Like

Hi dman2306 you got it to work. Great stuff !
Can you share what App and Drivers you installed
There is not a lot of documentation with this,
I review GitHub - tonesto7/nst-manager-he: NST Manager for Hubitat
Installed NST Manager app and all drivers to be sure I had it all
Sort of works when I go to add the user app - Login To Nest redirects me to Nest services integration Authorization page but on clicking "Allow" at bottom of page get a message at top of page "Oops! We’ve encountered an error. Please try again." not sure what to do from here.
When I go back to the app the location for my home is not available to select.

Did use my own Nest parent account which lots into nest.com OK

Sorry what I got to work as using eventstream in an unrelated app for Petnet feeders. I don’t own any Neat devices.