dxdc / homebridge-blinds

:sunrise: Homebridge Plugin to control my blinds over HTTP
https://www.npmjs.com/package/homebridge-blinds
ISC License
54 stars 25 forks source link

Feature request - Motion time zones‏ #70

Closed barzoock closed 2 years ago

barzoock commented 2 years ago
  1. I use the original BOND bridge (wifi).
  2. I use Somfy blind.
  3. The problem is that the percentage of the blind position isn't true, even though the "Motion Time" and "Response Lag" and lag. Let me explain.
  4. You probably think that we cannot control the current position on the original bond (not the pro version) - but we can.

Times

A = time till the blind opens to 1% from the floor (as in my case 10sec) This time is the time it gets from full closed to "MY" mode (a close mode with only open between shutters)

B= time till it goes from the floor to the top. (as in my case 15sec)

A+B = Motion time (25sec)

Now if I set the blind to 50% it really opens 6% If I set it to 70% I get really 50%. It's because A time - We should count the percentages from "MY mode" to the top.

To fix it we need set "motion time" that be from 0%-1% (A) and another "motion time" from 1%-100% (B)

Please let me know if you think it is possible. Thank you for your time, I hope you can make it.

Screen Shot 2022-06-30 at 0 53 45

dxdc commented 2 years ago

@barzoock -- wow, I enjoyed your photos and discussion. Have you seen #43? :)

That being said, I am somewhat concerned about this statement:

A = time till the blind opens to 1% from the floor (as in my case 10sec)

It takes 10 seconds to open to 1%? In this case, your motor is not calibrated properly. You can find instructions to do this online, but you basically control/set the upper and lower limit of your blinds. If you have extra fabric there it can make a huge difference.

I would definitely start there. The other thing that I've seen is that the Bond Pro, for example, does this differently. It sends a complete "up" or "down" command and waits for the blind to return to the closest position. Then it sends the command for percentage again.

I think that may be a better strategy, because if you try to adjust from 44% to 45% for example, it isn't possible to have something happen that quickly. The logic to do that is a bit more complicated of course, but anyway, please try starting with the motor calibration and let's see how things are after that.

barzoock commented 2 years ago

@dxdc Thank you for replying. I saw #43 already. that's not my case. The motor is calibrated properly. Many of Somfy blinds have 3 modes (UP, DOWN, "MY") I took a video that shows the case: https://drive.google.com/file/d/125lVn3d8zPyNdnYzCC-ZO2e9vh4Zr8BK/view?usp=sharing (or attached here in low quality)

Hope you understand now :) Thank yo

https://user-images.githubusercontent.com/108406822/176624710-949481b3-9d56-474b-bf6c-1f80fc0a2fd0.mp4

dxdc commented 2 years ago

Interesting. I've never seen this -- is it a security blind? A little hard to tell in the photo. I don't understand the purpose of "MY" mode.

Still #43 seems exactly what you are looking for, if you read to my latest idea at the bottom:

Mark the the following positions for your blinds: 0%, 10%, 90%, 100%, then measure the time: A: to raise from 0% to 10% (use motor noise, not just movement) B: to raise from 10% to 90% C: to raise from 90% to 100% (use motor noise, not just movement) motionTime = B / 0.8 extraTimeFrom0to1 = A - (B / 4) extraTimeFrom100to99 = C - (B / 4) Then, we can apply these extra delays at the edges. Let me know how this compares with your observations!

It can be some variant of this of course. I think it can happen (differently) on both edges, and can be customizable in both ways. Let me know if you agree. Something kind of custom function where starting point is input and it can determine the ending time point. This should include the time lags and everything else.

barzoock commented 2 years ago

about #43 - I want to try. How can I enter the "motiontime" and the "extratimes" in the confing? I don't understand Thank you

by the way- The purpose is to get slight light. like if you just wakeup in the morning or watching a movie... etc... If you open 10% (from the floor) you get slight light only from the bottom of the window and the light doesn't fill the room equally. You should try it one day...

dxdc commented 2 years ago

43 isn't done, it was just an idea. By the way, this isn't a bug, this is a a feature request. You have unusual blinds that move at a different rate at different parts.

Do you read javascript? I'm thinking of something like this, where we can define a series of time-based zones. Not sure how to implement it yet. Probably best if motionTime becomes a function or expression.

function motionUpTime(startPos, endPos) {
  let currPos = startPos;

  // define motion ranges here
  // motionStep = milliseconds per % of motion
  const zones = [
    { pos: 1, motionStep: 10000 },
    { pos: 90, motionStep: 100 },
    { pos: 100, motionStep: 5000 },
  ];

  const motionTime = zones
    .map((zone) => {
      if (currPos <= zone.pos) {
        const zoneTarget = Math.min(zone.pos, endPos);
        const moveDist = zoneTarget - currPos;
        currPos = zoneTarget;
        return moveDist * zone.motionStep;
      }

      return 0;
    })
    .reduce((partialSum, a) => partialSum + a, 0);

  return motionTime;
}
barzoock commented 2 years ago

It looks amazing solution. I wish i knew how to implement it. I'm here to be a tester for you :)

dxdc commented 2 years ago

We could try something at least roughly in a beta version, hardcoded for now, to make sure it's working on your end.

I will need 2 lists from you, will look like this:

Position Time (in seconds or ms)
0% - closed 0
1% 10.0
50% 13.0
99% 15.0
100% - open 25.0

Feel free to add more rows / change the percentages as appropriate.

I need it when opening and when closing. The point is, we need to figure out which time ranges are linear. Once you know which ranges are linear, you can simplify the list.

One easier way to do this is by recording a video of your blinds and then going back to the exact points using the timestamps in the video.

barzoock commented 2 years ago
Position Time up Time down
0% 0 23.72
1% 9.25 15.35
10% 11.09 13.42
25% 14.02 10.76
50% 18.16 6.8
75% 21.76 3.38
90% 23.62 1.58
99% 24.72 0.55
100% 24.87 0

https://user-images.githubusercontent.com/108406822/176699128-cccd23d2-4e0a-4ff6-86bf-537fc90b0ef8.mp4

barzoock commented 2 years ago

@dxdc Hey! anything new?

dxdc commented 2 years ago

I appreciate your excitement, but I only work on this project in my free time. This isn't a paid service, and when I have something to share, I will let you know. In the meantime, you're welcome to submit a PR for review.

barzoock commented 2 years ago

Thank you! How can I submit a PR review? I'm a pretty beginner

dxdc commented 2 years ago

Just write the code and submit a pull request...

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests

barzoock commented 2 years ago

Just write the code and submit a pull request...

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests

Sorry I still don't get it. When I click "new pull request" it opens "Compare changes" ?? Thank you

dxdc commented 2 years ago

I have a version available for testing. I've also made several updates so you may see warnings about deprecated parameters, but everything should work properly.

  1. Add motion_time_graph parameter to your homebridge-blinds config. You can remove motion_time, since this will replace it.

    "motion_time_graph": {
        "up": [
            { "pos": 0, "seconds": 0 },
            { "pos": 1, "seconds": 9.25 },
            { "pos": 10, "seconds": 11.09 },
            { "pos": 25, "seconds": 14.02 },
            { "pos": 50, "seconds": 18.16 },
            { "pos": 75, "seconds": 21.76 },
            { "pos": 90, "seconds": 23.62 },
            { "pos": 99, "seconds": 24.72 },
            { "pos": 100, "seconds": 24.87 }
        ],
        "down": [
            { "pos": 100, "seconds": 0 },
            { "pos": 99, "seconds": 0.55 },
            { "pos": 90, "seconds": 1.58 },
            { "pos": 75, "seconds": 3.38 },
            { "pos": 50, "seconds": 6.8 },
            { "pos": 25, "seconds": 10.76 },
            { "pos": 10, "seconds": 13.42 },
            { "pos": 1, "seconds": 15.35 },
            { "pos": 0, "seconds": 23.72 }
        ]
    },
  1. Install the latest version of homebridge-blinds, e.g., sudo npm -g install homebridge-blinds@2.0.0-beta.6

  2. Restart homebridge

Please share your feedback when you can.

barzoock commented 2 years ago

@dxdc WOW! it works!!!!!!!

User Tip: In fact you need to calculate the seconds more than once and adjust averages as this may vary between opening and closing by a few milliseconds. (Expect 99% accuracy, You won't get 100%).

I have an extra idea. maybe add a button for setting it to 1% (or another % at user's choice) Tell me what do you think.

Thank you

barzoock commented 2 years ago

@dxdc WOW! it works!!!!!!!

User Tip: In fact you need to calculate the seconds more than once and adjust averages as this may vary between opening and closing by a few milliseconds. (Expect 99% accuracy, You won't get 100%).

I have an extra idea. maybe add a button for setting it to 1% (or another % at user's choice) Tell me what do you think.

Thank you

Even add the ability to create a dummy button for personal use

dxdc commented 2 years ago

WOW! it works!!!!!!!

Great! I've officially published this as v2.0.0.

In fact you need to calculate the seconds more than once and adjust averages as this may vary between opening and closing by a few milliseconds. (Expect 99% accuracy, You won't get 100%).

Even 99% accuracy, particularly over time, is not going to happen. I think you'll be lucky to get 90% or so.

There are too many factors to be able to get 100% accuracy, including:

The plugin works by sending the "up/down" command, followed by a timer, followed by the "stop" command. Each of these commands have potential delays and variation associated with it external to the plugin. You can also imagine that changing from 53% to 54% will have such a small delay, that the network delay will likely exceed this value. It could not possibly send all the commands quickly enough to have that kind of control, since the HTTP-based API you are using will be too slow.

The only way to make it perfectly accurate is to send the target position to the blinds, and let the blinds control it and update the plugin with its current position. There are blinds with motors that support this feature.

I have an extra idea. maybe add a button for setting it to 1% (or another % at user's choice)

This kind of functionality is already enabled by HomeKit scenes. You can add as many devices as you like, and then force-press on the blinds to set a preferred position for that scene. I think this is a more appropriate use for Scenes... particularly since, most people have multiple blinds, and creating individual buttons to control each blind seems cumbersome.

You can also use the webhook functionality of this plugin (see: Wiki) and then create an unlimited number of buttons with another plugin to send it any commands you like using homebridge-http-switch or a similar method.

For example, http://192.168.1.40:51828/?pos=1.

You would have to use separate ports for each instance of the blinds plugin.

slavikme commented 2 years ago

@dxdc BTW, these shutters are widely used in Israel. Actually, it is hard to find electric shutters in the country that are not of this type. Mine are the same.

This update is very helpful! Thank you so much for this great plugin and an amazing support! ❤️

barzoock commented 2 years ago

@dxdc BTW, these shutters are widely used in Israel. Actually, it is hard to find electric shutters in the country that are not of this type. Mine are the same.

This update is very helpful! Thank you so much for this great plugin and an amazing support! ❤️

hahahah... Yes, I was thinking the same thing this morning, I'm from Israel. @dxdc This feature of "the 1%" is highly used - we would appreciate having a dummy switch option anyway... Thanks a lot

dxdc commented 2 years ago

Awesome! I'm glad to know that we have a good market for future homebridge-blinds users :) I've been to Israel many times and seen these in residential places, but never knew about you 1%'ers.

As far as the "1%" button, it's possible, I just feel there are so many existing solutions for it.

Can you tell me why native installation is somehow better?

For example, here's how to do it with http-switch, and you can add/remove as many buttons as you like. If this is helpful, I can add to the Wiki:

  1. Install homebridge-http-switch plugin. Add to config.json like this, customized for your blinds, and change the IP address to match your device.

You will need to choose an open port on your device, 51828 in this example (see: Step 2), but choose something to match. Each set of blinds will use a different port.

    {
      "accessory": "HTTP-SWITCH",
      "name": "Kitchen Window Shortcuts",
      "switchType": "stateless",
      "onUrl": [
        {
          "url": "http://192.168.1.40:51828/?pos=1"
        },
        {
          "url": "http://192.168.1.40:51828/?pos=50"
        }
      ]
    }   
  1. Add webhook_port to your existing blinds configuration.

Note: You may wish to add basic authentication for security on your local network, this would be up to you. See the Wiki for details.

"webhook_port": 51828
  1. Restart homebridge and test
barzoock commented 2 years ago

@dxdc Well, it would make it easier if all blinds' buttons were in one place and weren't separated into many different buttons (like now: blind slider + to stop button + on/off toggle). I came up with a solution for myself - I don't use the "on/off" toggle, so I made an automation that when the toggle hits, It sets the blind to 1%. It's a little confusing for the blind since I'm sending 2 requests at the same time, but it's the best I can do at the moment

dxdc commented 2 years ago

OK. Can you explain why HomeKit Scenes doesn't work for your purpose? @slavikme would you find this valuable as well?

barzoock commented 2 years ago

@dxdc A scene or "http-switch" button will separate it into 2 accessories, now all the buttons (blind slider + on / off switch + stop) in 1 accessory. It makes it more user-friendly and helps differentiating between blinds (I have 7 blinds). If I would make for each blind a button or scene for that I would waste x2 time on finding the right button. Well, now i found a solution for myself but just in case anyone else will need better compatibility

dxdc commented 2 years ago

@barzoock OK.

Add this to your config. You can define an array here of an unlimited number of favorite positions. Please test/report.

"show_favorite_buttons": [1, 50],
slavikme commented 2 years ago

@barzoock This will definitely be convenient to have such features in the Home app, BUT, unfortunately, AFAIK HomeKit does not support these types of shutters, the protocol only support blinds, which is a simple version of shutters (without the significant delay, before it starts to open the shutters). HomeKit protocol also support Garage door, which is another type of shutters with a similar behavior, but still in its simple way.

barzoock commented 2 years ago

@barzoock OK.

Add this to your config. You can define an array here of an unlimited number of favorite positions. Please test/report.

"show_favorite_buttons": [1, 50],

I love it. WORKS PERFECTLY! I greatly appreciate you. thank you so much