Tradfri binding loses connection after Power failure / gateway reboot

Every time after shutting down and restoring the power of my Tradfri gateway and wifi router (the gateway is plugged into the USB port of the router so that I don’t need an additional power supply), all tradfri things remain marked as offline in habmin and do not respond to openhab commands. The Tradfri app and remotes work fine, though. To get the things working again I have to change the gateway’s IP to something else and back again to the old value, see screenshots. The IP was never wrong, the thing is just not refreshed after going offline.

Is this a bug in the binding or is there something else I could do?



Need to use a dedicated power supply most likely.

This sounds like a router issue or power issue. I use TRÅDFRI and have no issues. In fact I don’t even have access to my gateway or router, it’s hidden in a closet.

Thanks for the reply, but I really don‘t think the power supply itself is the issue. Maybe it is because Wifi and Gateway come up at the same time but this would not change if the gateway had its own supply and the power fails in the whole house. And it works just fine like this, only openhab does not recognize the working gateway after it went offline. Changing the IP does nothing with the gateway, it only causes Openhab to properly connect.

Make sure your router has a static ip set for the gateway also this could be a problem. On power up its first come first serve. You can also use the gateway host name in openHAB.

On the power supply I would still try an independent one as it loses nothing but 5 mins of time.

Sorry, but the Gateway gets the proper IP address and works just fine by itself. It is Openhab that does not detect it being online again. Please take a look at my screenshots of Habmin - After changing it shortly from 10.0.1.167 to 10.0.1.16 (which is arbitrary) and back again to 10.0.1.167 the item state switches from offline to online. The Tradfri gateway never had any other IP than 10.0.1.167. Maybe the binding should do some kind of polling for offline gateways.

I have power cycled my router and gateway while openhab stays online. I use files for my configuration vs habmin. Would you be opposed to switching to files even if it is just to try on your setup. This would prove a problem in habmin and you could submit an issue to github.

Keep in mind you may think the gateway is working locally. I believe the remotes talk directly to the bulb bypassing the gateway. The app I can’t explain.

This would mean that Openhab forgets the correct gateway IP after the connection fails and habmin shows some old value instead, even though the old value is the correct value. In that case the main issue would still be in openhab or the binding for losing the connection and a minor one in Habmin for not showing openhab’s faulty value. I will do some further debugging with the log files, though. Maybe this will give some clues what is going wrong.

Nothing unexpected in the logs:

Power off:

21:08:18.163 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'tradfri:gateway:gwdcefcaba8d2b' changed from ONLINE to OFFLINE (COMMUNICATION_ERROR)
21:08:18.164 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'tradfri:0100:6e0e462d:65542' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
21:08:18.165 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'tradfri:0220:6e0e462d:65537' changed from ONLINE to OFFLINE (BRIDGE_OFFLINE)
[...]

Power restore, nothing tradfri related happened. Openhab reconnected to the cloud service, though, so it did notice being back online.

Changing the thing IP to something incorrect:

21:10:52.529 [INFO ] [smarthome.event.ThingUpdatedEvent    ] - Thing 'tradfri:gateway:gwdcefcaba8d2b' has been updated.
21:10:52.533 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'tradfri:gateway:gwdcefcaba8d2b' changed from OFFLINE (COMMUNICATION_ERROR) to UNKNOWN

Changing the IP to the correct value:

21:10:55.302 [INFO ] [smarthome.event.ThingUpdatedEvent    ] - Thing 'tradfri:gateway:gwdcefcaba8d2b' has been updated.
21:10:57.763 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'tradfri:gateway:gwdcefcaba8d2b' changed from UNKNOWN to ONLINE
21:10:57.765 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'tradfri:0220:6e0e462d:65538' changed from OFFLINE (BRIDGE_OFFLINE) to ONLINE
[...]

Note that I did not wait really long this time before doing the IP-change-workaround. From previous experiences I know that waiting even for hours doesn’t help.

I tested here at my house and yes I have the same issue and don’t use habmin. I had to stop start openhab to recover. I have not had to do this in the past, so it is unclear why it started now. It could be due to the 1.4 firmware. My gateway updated a few weeks ago, prior to that was the last time I tested any thing like this.

It is possible the binding needs an update due to the firmware change. If you look at Ikea’s release notes many were due to network issues. I am thinking they broke something trying to fix something.

Are you sure that it is the IP.
For me the IP is the correct one I had to put the Security code in again, it vanished for some unknown reason. The gateway immediately came online. Prior to that I restarted the bundle and even rebooted the server.

I myself have a UPS where all gateways are attached, though still having this problem when UPS kicks in.
I think the problem I have that the network switch is not on UPS, so network is down (have to correct that).

@Kai is it possible to somehow hard-wire the settings of tradfri in a config file?

Sure, see https://www.openhab.org/addons/bindings/tradfri/#full-example. But this won’t solve the problem @robert2 describes above.

Is this a bug in the binding or is there something else I could do?

It sounds to me as if the binding does not try to correctly reestablish the connection if the tradfri gateway is restarted. Feel free to enter a bug report at https://github.com/eclipse/smarthome/issues describing the problem.

done:

Thanks but sorry, that is not the issue here. I have created https://github.com/eclipse/smarthome/issues/6065 instead.

I tried today to unplug power from tradfri gateway for few seconds.
As a result the tradfri gateway thing went offline and stayed that for hours.
image
I then wen to the configuration parameters and just updated the security code


The Gateway thing immediately went online
image

My conclusion is that either way cycling ip address or re-entering security code brings the thing online.
Rebooting server or restarting binding in karaf does not bring the thing online.

@lukics @robert2 A different question to both of you. What happens with the status for the gateway Thing after an OH restart? I currently see some strange behavior in my live environment too where the gateway Thing never came ONLINE again after a restart even if it worked before. I have to reboot my gateway and restart the binding manually afterwards.

The status of the gateway thing is OFFLINE.
When restarting the binding in karaf I can see in the logs COMMUNICATION_ERROR

2018-08-16 10:10:28.510 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65550' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:29.396 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65537' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:31.717 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65543' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:31.799 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65555' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:32.595 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65568' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:32.760 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65561' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:33.496 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65541' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:33.781 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65554' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:34.811 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65557' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:34.980 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65547' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:37.009 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65553' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:38.281 [hingStatusInfoChangedEvent] - 'tradfri:0100:gwb072bf27910b:65569' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:38.613 [hingStatusInfoChangedEvent] - 'tradfri:gateway:gwb072bf27910b' changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR)
2018-08-16 10:10:38.617 [hingStatusInfoChangedEvent] - 'tradfri:0820:gwb072bf27910b:65573' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.620 [hingStatusInfoChangedEvent] - 'tradfri:0820:gwb072bf27910b:65574' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.628 [hingStatusInfoChangedEvent] - 'tradfri:0100:gwb072bf27910b:65572' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.632 [hingStatusInfoChangedEvent] - 'tradfri:0100:gwb072bf27910b:65569' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.639 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65537' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.647 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65538' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.654 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65540' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.659 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65546' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.664 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65548' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.668 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65560' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.671 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65542' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.676 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65544' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.681 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65547' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.684 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65551' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.687 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65541' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.690 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65543' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.694 [hingStatusInfoChangedEvent] - 'tradfri:0830:gwb072bf27910b:65536' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.696 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65561' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.702 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65552' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.705 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65553' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.708 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65554' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.711 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65557' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.714 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65556' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.716 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65555' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.719 [hingStatusInfoChangedEvent] - 'tradfri:0830:gwb072bf27910b:65549' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.722 [hingStatusInfoChangedEvent] - 'tradfri:0830:gwb072bf27910b:65545' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.725 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65562' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.727 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65550' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.731 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65568' changed from OFFLINE (COMMUNICATION_ERROR) to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.733 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65563' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.742 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65565' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.745 [hingStatusInfoChangedEvent] - 'tradfri:0830:gwb072bf27910b:65571' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.747 [hingStatusInfoChangedEvent] - 'tradfri:0830:gwb072bf27910b:65567' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.749 [hingStatusInfoChangedEvent] - 'tradfri:0830:gwb072bf27910b:65559' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)
2018-08-16 10:10:38.752 [hingStatusInfoChangedEvent] - 'tradfri:0220:gwb072bf27910b:65539' changed from OFFLINE (BRIDGE_OFFLINE): Gateway offline 'UNKNOWN' to OFFLINE (BRIDGE_OFFLINE)

Thanks for quick test.

The Bridge handler overwrites the “Security Code” with null after successfully establishing a connection to the gateway. Why? I will remove that line of code and do some tests (see comment).

I do not think this is the solution. As pointed out by Roben IP rotation establishes the connection too.
And the IP address is not deleted.

That is right. I got it now. Nonetheless I did some more research. It seems we ran into timeouts after restarting the binding. I will try to find a solution for it.

@roben @lukicsl

New ESH 291 and OH2 1340 snapshots have been release. May I ask you to do some more tests with the new version? I am curios if it works…

Thanks! Can I use just the new binding jar with the current OH stable? Or is there even a way to tell OH to install the snapshot version of the binding?

Both options are possible.

First: You have to install the features esh-tp-coap and esh-io-transport-coap via Karaf console and then put the .jar file into your addons/ folder.

Second: see https://www.openhab.org/docs/installation/linux.html#installation