mtgeekman / Home_Assistant_NeoSmartBlinds

Adds NeoSmart Blinds support to Home-Assistant.
46 stars 14 forks source link

Feature Request - Working with the HomeKit Integration #46

Open jvmahon opened 1 year ago

jvmahon commented 1 year ago

I have a feature enhancement suggestion (and proposed implementation method with nodejs code example) to better support bridging shades controlled by this plugin to iOS Home.

The issue: I'm using this plugin to control shades with the "bf" motor type, which does not support an absolute position. In the HomeSeer interface, I can see both a positional slider interface to control the shades (i.e., position mode), as well as up / down button controls (button mode). If I use the positional mode sliders, they do nothing, but if I use the up/down buttons, all works as expected.

I'd like to be able to export these shades from HomeSeer to iOS Home using HomeSeer's built-in HomeKit Bridge integration. The problem is that the HomeKit environment only supports shades allowing positional control, so it currently can't be done.

Proposed Solution Before I was using HomeAssistant, I used Hubitat and had a similar issue. For Hubitat, I wrote a homebridge plugin that solved this in a simple way. Instead of having a "do nothing" positional slider, the slider code was set to have 3 positions (you could slide to anywhere in iOS home, but only 3 positions had a real meaning). Normally, the slider is at 50% and this is what you see in iOS Home. I chose this because with the "bf" motor type, you can't really tell where the shade really is, so 50% allows the iOS Home user to either slide to open or slide to close. If the user then slides the slider up to 100%, this triggers an open and the slider stays in the 100% position for a few seconds, but then reverts back to 50%. Similarly, if you slide down to 0% the slide closes, but the positional indicator goes back to 50% after a bit. If you slide to anything but 0 or 100%, the positional indictor returns to 50% with nothing happening..

Here's the code that I used for Homebridge and the Hubitat environment: https://github.com/jvmahon/homebridge-smartshades

If you look in the index.js file, at lines 118-153 you can see the implementation. The "on('set'..." at line 119 gets called when the iOS user moves the shade position slider. If the position goes to 0 (close), the case at line 121 is called, and the shade gets commanded to close (line 122). The position slider will then be shown at 0% in iOS, but a timeout is then set (line 123-126) that returns the iOS position indicator to 50% after a 25 second delay (line 126).

Opening the shade is similar (see lines 138-145).

Could some similar logic be added to his integration so that HomeAssistant's interface's positional slider becomes functional and, thus, allows its export to HomeKit via the HomeKit integration? I'd try adding it myself, but I'm relatively new to HomeAssistant and don't (yet) know Python or the device model well enough to program it.

Thanks for considering this.

JBDenton commented 1 year ago

Hey, I'm actually in early stages of writing an update to the existing integration to read the JSON contained in the neosmart web app, it will be able to read in the hub IP, all the blinds, rooms, scenes, etc. It has some position info in the JSON so hopefully I can get HA to give users a choice of either directly talking to the hub without position info or via the web app with position info. My main want for the JSON was for getting the list of blinds and motors so wasn't focusing on position but I'll look into it more now that I know others would like it. I'll try and get some of my code updated to my fork in a few days once it's a bit more reliable.

gee-jay-bee commented 1 year ago

Fwiw I added percentage based positioning and async to this integration a couple of years ago so that I could use it with HomeKit. It works really well for me. Take a look at the documentation for 'percent_support' ... I set it to 2 to have the integration emulate position as my blind motor doesn't support explicit positioning commands. You can even interrupt positioning and change direction.

As for the ask to have coarse up / down, I think the positioning support I added replaced that kind of behaviour because it didn't play nicely with HomeKit! That's not to say it couldn't be added back but I think it would need to be another positioning mode in percent_support so it doesn't break what's there now.