EventStream

Hey folks. I'm trying to write a driver to pull sensor data from my alarm panel. The panel has a locally accessible event stream for sensor events. The caveat is that I'm a complete novice. I've done some modification to existing drivers/apps in the past, but never written one from scratch. What I'm trying to do at this point is to just get the raw event stream into the Hubitat logs so I can start writing out the parsing and what-not. The issue is that I'm getting nothing back from the stream and I have no clue why. I've tried looking at some of the other drivers out there that are using the eventstream function, but haven't been able to get anywhere. Anyone able to nudge me in the right direction?

Here's the driver's code as it stands right now:

Summary
import groovy.json.*

def version() {"0.0.1"}

metadata {
	definition (name: "ADC Stream", namespace: "rlelliott", author: "Ryan E.") {
		command "streamStart"
		command "streamStop"
	}

}

void initialize(){
}

void streamStart() {
	log.info("Starting eventStream()...")
    try {
    interfaces.eventStream.connect("10.21.83.35:12345", [ignoreSSLIssues:true,rawData:true])
    } catch(e) {
        log.warn "Broke"
        log.warn e
    }
}

def eventStreamStatus(String message) {
    log.info(message)
}

void parse(String message){
    try{
    def data = new JsonSlurper().parseText(message)
    log.info(data)
    }
    catch(e){
        log.warn("Error parsing", e)
    }
}

void streamStop() {
    interfaces.eventStream.close()
    log.info("Stopping eventstream")
}

Here's what I get in the logs:

Summary
[dev:604](https://10.22.83.200/logs#dev604)2022-06-29 12:28:46.795 pm [info](https://10.22.83.200/device/edit/604)Stopping eventstream

[dev:604](https://10.22.83.200/logs#dev604)2022-06-29 12:21:17.053 pm [info](https://10.22.83.200/device/edit/604)START: EventStream Started

[dev:604](https://10.22.83.200/logs#dev604)2022-06-29 12:21:17.027 pm [info](https://10.22.83.200/device/edit/604)Starting eventStream()...

And here is what the event stream looks like when I curl it from Windows:

Summary
PS C:\Program Files\PowerShell\7> curl -k https://10.21.83.35:12345 --http0.9
ACK
{"event":"ZONE_EVENT","zone_event_type":"ZONE_ACTIVE","version":1,"zone":{"status":"Open","zone_id":34},"requestID":"16c5060a-b1e8-4eed-8d10-4b25960d426d"}
{"event":"ZONE_EVENT","zone_event_type":"ZONE_UPDATE","zone":{"id":"CB91AA","type":"Door_Window","name":"Office Window","group":"entryexitdelay","status":"Open","state":"0","zone_id":34,"zone_physical_type":1,"zone_alarm_type":3,"zone_type":1,"partition_id":0},"version":1,"requestID":"53604c72-cb20-4be6-8708-8dc6668ec6e5"}
{"event":"ZONE_EVENT","zone_event_type":"ZONE_ACTIVE","version":1,"zone":{"status":"Closed","zone_id":4},"requestID":"4f1d933a-b81e-4089-ad41-8713481be6dd"}
{"event":"ZONE_EVENT","zone_event_type":"ZONE_ACTIVE","version":1,"zone":{"status":"Closed","zone_id":43},"requestID":"860870b3-a668-4cee-967a-b380d3ab552e"}
{"event":"ZONE_EVENT","zone_event_type":"ZONE_UPDATE","zone":{"id":"E7B8A2","type":"Door_Window","name":"Garage Door Outside","group":"entryexitdelay","status":"Closed","state":"0","zone_id":4,"zone_physical_type":1,"zone_alarm_type":3,"zone_type":1,"partition_id":0},"version":1,"requestID":"0e56a1f1-14e1-49ff-b870-7036215d9077"}
1 Like

I don't think EventStream is what you want to use. If curl is using https then that is what your driver should use or otherwise ensure the device is a websocket that fits the Eventstream.

It is an event stream. The events in the curl sample occurred over time as I toggled the sensors.

Alright...a little progress...I had a type. I forgot to prepend the IP with HTTPS so the interface was just rejecting the connection. After updating the driver code to use "https://10.21.83.35:12345" I'm at least connecting, but then getting an error.

dev:6042022-06-30 11:27:43.546 am infoSTOP: EventStream Stopped
dev:6042022-06-30 11:27:43.540 am infoERROR: Exception during EventStream Request: java.net.ProtocolException: Unexpected status line: ACK
dev:6042022-06-30 11:27:42.700 am infoSTART: EventStream Started
dev:6042022-06-30 11:27:42.646 am infoStarting eventStream()...

Come to find out...someone has already done what I'm trying to do:

1 Like

Hey @FriedCheese2006, did you ever get very far with the EventStream interface? I know the existing integration that you linked to is using RawSocket, but I'm wondering if you might have gotten any more progress on EventStream and we could compare notes.

I'm working on an unrelated integration that uses EventStream with digest authentication. I can get a successful connection and useful events coming back, but I had to use the rawData: true option.

I don't sense that the EventStream interface gets much use, so it could be that it is rough around the edges and this is as good as it will get. Or it could be that I just haven't gotten all of the headers and options right to make it work. Or a little of both.

Did you ever get anything working? I wanted to compare notes with someone else who had already found their way through it.

Here's what the traffic looks like on my stream. Each line from each server-sent event invokes my parse() method. The lines that start with "Code=" are the ones I want, so they're easy enough to find. But I'd like to get the whole event in one parse message so that I can handle the complete event.

This one is particularly problematic, because there's a json string in the data field that I need, but it shows up in 4 separate invocations of parse:

Any ideas? Also tagging @gopher.ny for any pro-tips.

1 Like

I did not. Once I found the integration I linked to, I didn't have a use-case anymore. Maybe post up your code?

1 Like