bruxy70 / Venetian-Blinds-Control

Control Shutters or Venetian blinds via buttons and MQTT. Use 2 relays (up and down) and 2 binary inputs to independently control position and tilt.
MIT License
44 stars 19 forks source link

Rewrite tilt and position calculation #6

Closed pawelma closed 1 year ago

pawelma commented 1 year ago

Hello 👋 . Finally, found some time so raising PR related with issue https://github.com/bruxy70/Venetian-Blinds-Control/issues/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

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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.