A word about HA -> HE integration

I like your way better. The logic for retrying was essentially the same as mine, but yours backing off if retries don't succeed is an improvement. I will likely incorporate that sort of approach into my other drivers that do websocket reconnects.

3 Likes

v0.1.17 went into a reconnect frenzy on my setup.

Went back to v0.1.16

Interesting... Is your HA running on WiFi or a Hardwired Ethernet connection?

It is strange that every two seconds you receive a webSocket status update of 'closing'...

Ethernet. I change the driver, hit initialize and this start. This does not happen with version 16.

I think I understand what is happening... I am seeing the same thing if I click INITIALIZE. This is because doing so, causes the connection to be closed (even though it is open and working)... thus creating a loop.... I am going to dive in deeper to see if I can come up with a solution...(but I am all ears if any of your have any ideas... :wink: )

I was just about to say this. The same problem showed up on @ymerj's system with the earlier version of my code for the same reason.

My suggestion- let's close the stream explicitly with closeConnection() in initialize() rather than implicitly. Since you know it happened and was expected, you can adjust the websocketStatus() handler to not retry the connection in that specific case.

Sounds good. Please give it a try and I'll happily test... I keep getting my ideas twisted up as I think about the fact that anything we do in Initialize, is causing the websocketStatus() routine to be run... :thinking: If you've got an idea, I am all ears.

1 Like

OK. You guys have some good ideas. For now I'll try @ogiewon 's changes without initialize (Just getting to changing it now).

@ymerj are you running this in a virtual machine like I am? I'm using Virtual Box, and like you, my host machine's connection is Ethernet.

1 Like

Please see my PR for the general concept. Let me know if you see any issues with the approach.

This is something that I've been doing frequently too. I was messing with using DeCONZ instead of ZHA (decided to abandon that effort), and HA requires the service is restarted for quite a number of changes.

I did run it on Virtualbox on a Windows machine for testing but I move it in Docker on Raspbian. I use the RPi for something else at the same time (magic mirror).

1 Like

Looks like a good approach to me! I am testing as many scenarios as possible right now, including rebooting my HE Hub... (all working as one would desire!)

Looks very good to me, and the logic makes sense. I'll merge your PR.

@ymerj and @SmartHomePrimer, please give @tomw's v0.1.18 a try.

2 Likes

Will do. Rebooting the HE hub right now, as the prior version made my hub UI slow down significantly and that's not something I've experienced for a very long time.

It did the initializing twice but it's working fine.

Screenshot_20210214_231930

3 Likes

Looking good so far here too. First three are when I was rebooting the hub.
Nice work tonight gentlemen. Now go apologize to your spouses for working on this on Valentine's Day! :stuck_out_tongue_winking_eye:

4 Likes

Looking good. No errors or closed connections after changing to v0.1.18 more than 13 hours later. :+1:

Screen Shot 2021-02-15 at 1.49.28 PM Screen Shot 2021-02-15 at 1.50.13 PM

2 Likes

Over 34 hours later and the websocket had not closed once. I did however try intentionally restarting the HA service just now , and that does close the websocket, but it doesn't automatically reopen.

If it's possible to trigger initialize on event: start which is an available event on HA, then that might work for us.

I noticed that the refresh command is an empty shell. @ogiewon @tomw Will this do the trick?:

def componentRefresh(ch){
    if (logEnable) log.info("received refresh request from ${ch.label}")
    state.id = state.id + 1
    entity = ch.name
    domain = entity.tokenize(".")[0]
    messUpd = JsonOutput.toJson([id: state.id, type: "call_service", domain: "homeassistant", service: "update_entity", service_data: [entity_id: "${entity}"]])
    if (logEnable) log.debug("messUpd = ${messUpd}")
    interfaces.webSocket.sendMessage("${messUpd}")
}

It works on my setup but I don't want to mess with the code

1 Like

That is strange. It should reconnect automatically. Did you let it enough time before checking because the way it is implemented it can take as much as 10 minutes to reconnect.

2 Likes

No I didn't. Only waited a few minutes before manually initiating. Will test that now.

1 Like