Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite tilt and position calculation #6

Merged
merged 10 commits into from
Nov 27, 2022

Conversation

pawelma
Copy link
Contributor

@pawelma pawelma commented Nov 6, 2022

Hello 👋 .
Finally, found some time so raising PR related with issue #5 I raised week ago. I do understand that it does bring breaking changes and changes the philosophy of the current component, so if it doesn't suite this project, feel free to close the PR. I'm just raising for visibility ;).

WHAT

  • Uses ESPHome TimeBasedCover implementation as a base.
  • Calculates tilt and position using milliseconds for open/close and tilt
  • Extend setup logging
  • Tilt is now a part of position, so tilting from 0 to 100% does not change position BEHAVIOUR_CHANGE
  • Unifies the tilt and position direction, so that whenever position is closed tilt is going to be closed as well (BREAKING_CHANGE - current 100% tilts will mean that tilt is in open, not closed state)
  • Runs clang-format on top of code to unify styling with other ESP components
  • Position calculation formula changes from conditions to following:
# veriables
direction_of_travel = 1 # -1 for close
move_time = now - last_recompute_time
tilt_boundary = tilt_duration # or zero for close

# calculation
tilt = tilt + direction_of_travel * move
tilt_overflow = (tilt-tilt_boundary) * direction_of_travel
position = position + direction_of_travel * tilt_delta if tilt_overflow > 0

WHY

Previous implementation seemed not accurate enough, and I was unable to set deterministic tilt for my blinds.
I used TimeBasedCover as a base, as its loop reads nicer than multiple conditions.
Also have other features in mind that I could build on top of this solution like: include interlock while switching from open/close to improve precision, keep tilt on position change, add motor build in 'endstop' config value, to allow going back to 0 tilt after small tilt increase when motor build in end stop has not been released yet (so we need to open tilt to release end stop and close).

Notes

Tested on sonoff dual r3 and ESP32 node mcu.

Run time performance for recalculate function and according to ESP millis() it takes 0 ms to calculate each round. Only time, consuming operation is publishing as it escapes out of the board, but changing that does not impact number of loop calls within constrained time.

@bruxy70
Copy link
Owner

bruxy70 commented Nov 7, 2022

This is excellent, thank you. I will test over the weekend. If that works, I'll merge it. I thik if this is consistent with the core component, we might possibly try to make it part of the ESPHome standard integrations...

@pawelma
Copy link
Contributor Author

pawelma commented Nov 7, 2022

Thanks. I don't think it suits the standard component since this is a very specific kind of cover, and it would have to be made more generic to merge it. Unless that would be a different type of cover for this specific use case that we have 🤔.

@bruxy70 bruxy70 changed the base branch from master to test November 27, 2022 10:26
@bruxy70 bruxy70 merged commit e2f60d6 into bruxy70:test Nov 27, 2022
@bruxy70
Copy link
Owner

bruxy70 commented Nov 27, 2022

@pawelma I've finally found the time to test it. I put that to a separate branch, so that I can switch between the two in ESPHome (just changing ref between master/test).
I'll have to make the changes for the inverted tilt position. Other than that, it seems to work fine.
One thing I have noticed is, I do not get position updates whilst the shutter is moving. Is that by design?

@pawelma
Copy link
Contributor Author

pawelma commented Nov 28, 2022

Position updates are made but every 1 second AFFAIR. It can be changed I guess, but I wanted to reduce IO as it might make covers less accurate since it's synchronous.
Actually, that could be an easy addition to say how often someone wants the position to be updated.
The inverted tilt might be annoying for someone who uses current version as it is breaking change and will require some modifications into the automations and control cards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants