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