hbblebc / homebridge-bed-control

Homebridge plugin to control compatible smart beds
Apache License 2.0
7 stars 1 forks source link

If update interval is set, sync sleep number accessories to current sleep number #3

Closed traviswparker closed 1 year ago

traviswparker commented 1 year ago

Is your feature request related to a problem? Please describe:

If update interval is nonzero, occupancy sensors are polled as expected but number controls do not update to current bed settings. Describe the solution you'd like:

With debug on, I can see the request/response for the occupancy and sleep numbers. Accessories could be updated to match. Describe alternatives you've considered:

Additional context:

hbblebc commented 1 year ago

Thanks for reporting. It is definitely supposed to be updating the sleep number as well, so I will figure out what is going wrong and get it fixed.

Note that at this point, none of the other devices will update with polling. Primarily, polling is really only beneficial for the occupancy sensor, but I added the sleep number to the update routine since the API call returns both values anyway. Updating any other devices would require additional API calls and I am trying to minimize those as much as possible.

traviswparker commented 1 year ago

Looking at debug from snapi, It seems the API or snapi is returning 50/50 no matter how the bed is actually set, tho the SleepIQ app can somehow get the correct numbers. Pressure values don’t change either, but they are different, which makes sense because there is more bedding and such on one side.

hbblebc commented 1 year ago

I will take a look. There are a few API calls that return the sleep number. This particular API call worked in the past but maybe it has been deprecated. If it is non-functional, I will probably just disable it and make the polling only update the occupancy sensors. The numbers should update every time you open the app anyway so hopefully it won’t matter much.

traviswparker commented 1 year ago

I'm not sure but I think the numbers reported in the familyStatus and bedStatus calls are only updated when a bed enter/exit occurs. If privacy is on, they may not be updated at all, just like occupancy will always be false. Try the pumpStatus call, I believe that is what the app uses.

Alternatively, if you can't get reliable numbers from the API, don't update them at all, just keep the "brightness" last set via Home. I think resetting them to the bad values from the API is causing some automation issues. For example, I have automations that run "good morning" to set both sides to 100 once the bed is unoccupied during the day, and run "good night" to set the preferred numbers when occupied at night. Even tho they work when tested, when activated normally the rest of the actions in the automation work, but the request to set the left/right sleep numbers does not happen. I've seen this happen with other plugins, if HomeKit thinks an accessory is already where it should be, it won't hit it during an automation, even tho it does when testing the automation.

hbblebc commented 1 year ago

You are right - when privacy mode is enabled, familyStatus and bedStatus both just return whatever the last number was before privacy mode was enabled. Pump status returns the current value regardless. However, since the polling is primarily for the occupancy sensors and since those values don't change when privacy mode is disabled, I think I will just disable the polling if privacy mode is disabled. Then everything should work as intended.

This is good to know though, because currently the actual sleep number control uses the bed status value, so I will switch that to the pump status value as well.

hbblebc commented 1 year ago

Test out the updates, I think it should work now. Obviously, let me know if you find any new bugs introduced as a result.

As an aside, what are you setting your polling value to? I don't plan on using it but I want to get an idea from those who do use it what they are comfortable setting it to.

traviswparker commented 1 year ago

60 seconds seems to work well for me.

traviswparker commented 1 year ago

1.2.2 seems to be working well but is generating a lot of warnings in the logs. The out of sync warning is useful but there are also warnings about the occupancy sensors being set to illegal values. It might make sense to force the sensors to unoccupied when privacy on/polling disabled as the API will report unoccupied for both sides of a paused bed, even if a side is occupied.

hbblebc commented 1 year ago

Can you give me a snip of the warnings about illegal values? If privacy is on, I don't update the values at all during polling, and manually refreshing the sensor is supposed to set the sensor to "not responding" by giving it a null value. Maybe the null value is causing the warnings you are seeing.

If I can't get that figured out, it won't be hard to just force it to unoccupied. I will also limit the warning messages a bit better, either limited it to a single message per instance, or maybe only printing every 10th or 25th message or something.

https://developers.homebridge.io/#/api/service#serviceupdatecharacteristic

Looks like I need to return an error value instead of null.

hbblebc commented 1 year ago

This should all be cleaned up now. Let me know if it looks good to you.