technicalpickles / sleepyq

SleepIQ API for Python
39 stars 20 forks source link

Adjusting firmness #2

Open technicalpickles opened 7 years ago

technicalpickles commented 7 years ago

Over in https://community.home-assistant.io/t/feedback-on-component-for-sleepiq-beds/3132/7?u=technicalpickles there is some discussion around SleepIQ supporting setting firmness without needing to be in BLE range.

It seems to only be available through the mobile app. If you try to go to sleepiq.sleepnumber.com in a browser (mobile or not) and control it that way, you'll get an error that the functionality requires Bluetooth Low Energy and is not available on this device.

There is a thread over in the smart things forums, but there's nothing conclusive.

technicalpickles commented 7 years ago

Some ideas for figuring out how the call is made:

CCOSTAN commented 7 years ago

This just made me jealous.. @quadflight

https://images.discordapp.net/attachments/330944238910963714/332514297752190976/Screenshot_20170706-063255.png?width=325&height=669 image

MYeager1967 commented 6 years ago

I'm expecting delivery of my new bed next week. I'll be watching your thread and experimenting with your python code. Any chance you're still around to guide me a bit while I figure out what you've already done?

homer-aty commented 1 year ago

here you go:

    def set_Number(self, side, setting, bedId = ''):
        if side.lower() in ('r', 'right'):
            side = "right "
        elif side.lower() in ('l', 'left'):
            side = "left "
        else:
            raise ValueError("Side mut be one of the following: left, right, L or R")
        data = {"args":side + str(setting), "key":"PSNS", "sourceApplication":"Android Consumer Mobile app"}
        r=self.__make_request('/sn/v1/accounts/'+self.default_account_id(bedId)+'/beds/'+self.default_bed_id(bedId)+'/bamkey', "put", data)
        return True

make sure you also have this function to define the default_account_id var:

```

def default_account_id(self, bedId):
    if not bedId:
        if len(self.beds()) == 1:
            accountId = self.beds()[0].data['accountId']
        else:
            raise ValueError("Bed ID must be specified if there is more than one bed")
    return accountId
MYeager1967 commented 1 year ago

I guess it might be time to look at this again. After a long time of nothing, someone appears to be working on it....

homer-aty commented 1 year ago

I have all of the functions of the climate360 mapped out now with the rest API commands needed to control/automate it. Let me know if there's any particular thing you're looking for. The logic is fairly straightforward though unfortunately undocumented. It starts with a PUT request made to the API with the json data containing your sleep number username and password. the Server responds to that query with a "key" variable in the body and sessionId cookies in the header. That key needs to be appended to the url future calls to that API during that session or it will need a login again. Additionally the cookies returned from the first login query also need to be included in any headers sent. From there it looks like retrieving data through GET requests is unchanged from this library and fairly straightforward. controlling the beds requires API calls to api.sleepnumber.com/rest/sn/v1/accounts/youraccountid/beds/yourbedid/bamkey The bed Id and account id can be obtained from a simple get request as in the library already. The bamkey control needs json data formated as "args:" with the command and "key:" with a four letter key telling it what it is controlling ("PSNS" for firmness, "FWTS" for foot warming, etc.)

Hope this helps

MYeager1967 commented 1 year ago

Are you using this library as part of your solution or can you do it with straight API calls? I looked into integrating my bed way back and was far from happy with the little bit of info, and even less control, that was offered. Have been holding out for something better but far too busy to spend much time looking for it.

homer-aty commented 1 year ago

Are you using this library as part of your solution or can you do it with straight API calls? Yes. The library is just using python's built in requests.session to make the actual http request. The logic above tells you what calls to ask the library to build for you if you want to modify the library vs. what calls you need to make if you're making your own. The current library handles the session cookies and key variables, which is nice. But needs to be extended to allow the functionality I mentioned above. The code snippet I posted is an extension to the current library and would be added to the jnit.py file. I ended up porting the library to Arduino IDE so that I could make a "remote control" for the bed based on an ESP8266 wifi board. I think my next step will be to make a Samsung smartthings edge driver so that the bed can fully integrate with Samsung smartthings at the end user level.

MYeager1967 commented 1 year ago

I'll look at this as soon as I get a chance. It looks as though you may have gotten a lot further into it than anyone else I've seen. I'm sure I'll be hitting you up in the not to distant future. 😃

On Thu, Apr 13, 2023, 8:31 AM homer-aty @.***> wrote:

Are you using this library as part of your solution or can you do it with straight API calls? Yes. The library is just using python's built in requests.session to make the actual http request. The logic above tells you what calls to ask the library to build for you if you want to modify the library vs. what calls you need to make if you're making your own. The current library handles the session cookies and key variables, which is nice. But needs to be extended to allow the functionality I mentioned above. The code snippet I posted is an extension to the current library and would be added to the jnit.py file. I ended up porting the library to Arduino IDE so that I could make a "remote control" for the bed based on an ESP8266 wifi board.

— Reply to this email directly, view it on GitHub https://github.com/technicalpickles/sleepyq/issues/2#issuecomment-1506883569, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGBF5SCSVKT7TKUPFQJIKLXA7W33ANCNFSM4DKPW2HQ . You are receiving this because you commented.Message ID: @.***>

MYeager1967 commented 1 year ago

Just installed the SleepIQ integration again for HA. Seems this is what it's running???

Seems I can do almost anything I wish to do but I'm going to have to figure out how to read the saved firmness setting as set in the app. Is there an easy way to set the head/foot to something other than what's current?

technicalpickles commented 1 year ago

Just wanted to let y'all know I've not been using this library for a long time, and don't even have a sleep number anymore (RIP). If you end up with something to contribute as a PR, I'm happy to review and add as a maintainer.

MYeager1967 commented 1 year ago

For anyone using Home Assistant, this has been integrated quite well already. I never got into this project much, but I'm willing to bet it was the groundwork for the HA integration.