Eventstream does not provide correct data

Hi Everyone,

I am currently in the process of writing a Hubitat + Siemens HomeConnect integration to display the status of the devices. It is currently a work in progress as I have run into a bit of a blocking issue.

You can find the source code in its current form on gitHub (https:// github .com/Wattos/hubitat/blob/main/homeconnect/src/main/groovy/drivers/Dishwasher.groovy). Please note, this version comes currently with no functionality. However, I have managed to implement the oAuth flow and implemented a dummy driver to play with the Home connect API (You can find it here: https:// apiclient.home-connect .com/)

The REST API works as expected, however I am having trouble implementing the server side events (https:// apiclient.home-connect .com/#/status_events/get_events) on the hubitat.

I am able to successfully connect and receive the events from the backend. However, within the parse function, I receive content that is not very useful. My function:

void parse(data) {
    log.debug "Received eventstream message: ${data}"
}

causes the following log message to appear:

debug: Received eventstream message: MENS-SX878D16PE-68A40E03FB3F

Suffice to say, that this is not really useful. I wanted to make sure that the Home Connect API is not sending bogus events, so I connected with curl to debug the events being sent. When connected with curl, I actually receive the proper SSE events:

data:{"items":[{"timestamp":1602431826,"handling":"none","uri":"/api/homeappliances/SIEMENS-SX878D16PE-68A40E03FB3F/programs/selected/options/BSH.Common.Option.ProgramProgress","key":"BSH.Common.Option.ProgramProgress","unit":"%","value":0,"l
evel":"hint"},{"timestamp":1602431826,"handling":"none","uri":"/api/homeappliances/SIEMENS-SX878D16PE-68A40E03FB3F/programs/selected/options/BSH.Common.Option.RemainingProgramTime","key":"BSH.Common.Option.RemainingProgramTime","unit":"second
s","value":9900,"level":"hint"}],"haId":"SIEMENS-SX878D16PE-68A40E03FB3F"}
event:NOTIFY
id:SIEMENS-SX878D16PE-68A40E03FB3F

I receive these events separated with 2 new line characters which seems to be exactly according to the spec (A simplified version can be found here: https:// developer.mozilla. org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)

It seems that hubitat is only taking the last line of the event (in my case id:SIEMENS-SX878D16PE-68A40E03FB3F) and assuming that it should start with data: (as a data only event) creating a substring based on that and returning this into the parse method. Is this true or am I doing something wrong here? Is there something I can do within the driver to properly read out the event?

Of course I can build a nodejs proxy to work around the issue (by wrapping the event in a json), but I would really like to avoid doing that. This would make it somewhat difficult for other people to re-use my integration.

Thank you in advance for all the answers!

PS, Apologies, I had to break the links apart as I could not post with the links in-tact

1 Like

It's a little hard to tell because you appear to have pre-processing going on, but you're showing me the code prior to that preprocessing so what I'm looking at isn't actual HE code, but

parent.getHomeConnectAPI().connectDeviceEvents(interfaces);
You have that.

But your api has:

instance.connectDeviceEvents = { haId, interfaces -> 
        log.info("Connecting to the event stream of Home Appliance '$haId' from Home Connect")
        interfaces.eventStream.connect(
            "${apiUrl}/api/homeappliances/${haId}/events",
            [ headers: ([ 'Accept': 'text/event-stream' ] << authHeaders())])
    }

So where is that haID getting passed from? Might be easier to help debug if you show the post-processed code so I'm seeing what actually runs on the hub. I'm not a gradle user personally so I didn't really want to invest the time to get gradle up and runninbg to dig in.

Hey!

Thank you for the answer and great catch! I have forgotten to push the latest commit to the branch, so you saw an outdated piece of code. Yes, in fact, I am passing in the device id (called haId in the Homeconnect API). I updated my git repo and also pushed the assembled files.

The connection is succesfull, as I do get the events, but I simply get the wrong data into the parse function. I also get the events when I expect to get them. I

I have a suspicion that hubitat is simply not following the spec and assuming that all events are data only events.

I suspect you're correct. I only used the HE eventstream stuff once before to connect to a Firebase DB, and your code looks correct to me. If there is someone who might know, it's probably @gopher.ny

Hope you will be able to get this working! :smiley: I've just bought myself a Seiemens dishwasher that is connected through Home Connect so I would love to see an integration like this!

The code is correct and it is a bug with Hubitat. I have filed this to customer support but have not heard back since then. I cannot implement live updates without Hubitat fixing their issue.

1 Like