SleepIQ Binding issue polling Sleep Number API

I’m having the same issue. How did you create a rule to respond to an error so that I can do the same?
@syphr42 are you having challenges with the binding recently as well? I’m on 2.5.0M5 myself, but I think the binding hasn’t changed appreciably in quite some time.

Brian,

I am running 2.4.0. The issue starting I think after sleepIQ changed something in the API interface. I could not debug it enough to see why it started after 30 minutes after authentication… I turned on all the logging and was not enough to go on.

For the rule:

rule "Restart SleepIQ Binding when Offline"
when
        Thing "sleepiq:cloud:1" received update OFFLINE
then
        logInfo("Automation", "Rule=SleepIQ Binding offline... restarting Cloud Service!")
        executeCommandLine("bash /usr/share/openhab2/runtime/bin/client bundle:restart org.openhab.binding.sleepiq")
end

You can then see the execution in the openhab.log:

2019-12-01 19:46:17.191 [WARN ] [org.glassfish.jersey.internal.Errors] - The following warnings have been detected: WARNING: Cannot create new registration for component type class org.syphr.sleepiq.api.impl.SleepIQImpl$1: Existing previous registration found for the type.

2019-12-01 19:46:17.458 [INFO ] [ipse.smarthome.model.script.Automation] - Rule=SleepIQ Binding offline... restarting Cloud Service!
2019-12-01 19:46:17.466 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'bash /usr/share/openhab2/runtime/bin/client bundle:restart org.openhab.binding.sleepiq'

Hope that helps… At least it works till the binding is addressed!

Dan

I haven’t noticed any problems lately with the SleepIQ binding, but I just checked my logs and it appears to be flapping. It will get updates correctly and then an error occurs and the bridge goes offline. A few minutes later it corrects itself and starts getting updates again (at least for me running OH 2.4.0).

The API for SleepIQ (at least when I wrote the binding) was unpublished so I’m actually a little amazed it went this long without any issues.

This week is a bit hectic, but I will try to look at the binding this weekend and see what’s going on.

Quick update: I’ve run a set of tests with the SleepIQ API library (separately from the OH binding) and it appears to be working correctly. From that, my assumption is that there is a bug in the binding, though I don’t know why it didn’t appear until recently (perhaps something subtle changed in the API that is only apparent over time).

I do see a couple of possible suspects in the code for NPEs that I can make more robust, but I’ve spent the afternoon trying to get a working development environment without luck so far. Once I have a working environment, I’ll run some tests and hopefully be able to create a PR.

That fits the symptoms that restarting the binding allows it to work for 30 minutes before creating another error and repeats the cycle (the binding basic function is ok). Possibly the API does something different after 30 minutes like re-authenticate?

The binding has been working fine here with the rule to restart on the error. It has been running like this for a few weeks and the automation is working consistently.

I upgraded to release 2.5 yesterday and the above rule stopped working. In 2.5 to tighten security you can no longer execute bash commands to restart bundles without authentication. To establish a trusted key between applications follow this thread: Security of Karaf console. Once the key was created the rule started to work again.

@syphr42 did you ever find out why the binding is going offline after 30 minutes?

No, not yet. I still don’t have a working development environment. After creating the new workspace in Eclipse, OH refuses to start. I’m probably missing a bundle somewhere or there is some setting in Eclipse that I’m missing. I will have to figure out how to get a working setup before I can debug the issue further.

Any updates on this?

No updates but the rule to restart the binding every 30 minutes is at least a workaround for the time being. I have been using it for a few months and the automation has restored.

@syphr42 Did you ever get your workspace figured out to troubleshoot the binding?

Any luck figuring this one out?

There is no solution to fixing the binding yet… but if you restart the binding with a rule when it goes offline it will restart every 30 minutes but works well.

i upgrade to raspberry pi 4 and installed openHAB 2.5.6-2 and the restart rule doesn’t seem to be working any more.

@Waffskitt this is due to a security update. See my post above on Security of the Kraft Console. Once you enable a trusted host the rule will work.

@Dan_H Thanks for the response. I have installed the keys and can ssh -p 8101 openhab@localhost and it doesn’t ask for a password. So I assume I have that set up correctly but it’s not restarting the modular. I just don’t know how to troubleshoot this further. Any help would be greatly appreciated.

Looks like the restart is working but SleepIQ is going OFFLINE about once a minute.

@Waffskitt I looked at the rule… been a while…

I remember having a similar issue executing the restart with the executeCommandLine via the rule after the security update even with the keys.

Here is what I did… I used the executeCommandLine command to run a shell script to restart it that way… and it worked.

Here is the rule:

rule "Restart SleepIQ Binding when Offline"
when
        Thing "sleepiq:cloud:1" received update OFFLINE
then
        logInfo("rule", "Rule=SleepIQ Binding offline... restarting Cloud Service!")
        var results_script=executeCommandLine('sh /home/openhab/sleepiq.sh', 6000)
        logInfo("results", results_script)
end

Shell Script (sleepiq.sh):

#!/bin/bash

echo **SCRIPT** Starting SleepIQ Binding restart

ssh -p 8101 -i /home/openhab/karaf_keys/openhab.id_rsa openhab@localhost 'bundle:restart org.openhab.binding.sleepiq'

echo **SCRIPT** Binding Restarted Succesfully

Thanks Man that did the job. I did have the key setup incorrectly. Openhabian is the main user on my setup and everything is owned by the openhab user. So basically ssh -p 8101 openhab@localhost then following the key instructions. Thanks again

@syphr42 Any luck in getting your dev environment working? I have the auto-restart thing setup, but it’s really polluting the logs. I’m honestly surprised you’re not seeing this yourself. Can we help you get your environment working maybe?

In case anyone is still subscribed to this thread…

FWIW, I’m seeing the same problems with polling.

I’ve already fixed one problem with a ClassNotFoundException that prevented the binding from even running in 3.2.

Now that the binding is running, I’m getting the NullPointerExceptions and related failures in the getting responses from the API. I’m currently looking into the problem, but I’m not familiar with the SleepIQ API, as well as some of the Java classes that are used by the binding.

It may take me a while to get it sorted out, and it’s possible that I may not be able to get it sorted out. In any event, I’ll post any progress here.

The thing that seems to trigger the issue is when the login session expires. The binding logs in again (as it should), but for some reason, subsequent polling calls are failing.

There’s something in the login code about setting cookies so that they’ll be used in future API calls, but that doesn’t appear to be working. And, I don’t understand the JAX-RS stuff to know why it’s not working.

I don’t know if that’s an issue or not, but it’s the first thing I’m looking at (aside from more gracefully handling the NPEs, most of which I’ve fixed already).