Looking for sample of a composite device

Hi, I’m relatively new to Home Assistant and haven’t done any development on it yet. I’m looking for an example project that I can look at and use a guide to get started. I’d like to develop an add-on/package/component (I’m not even sure the right word to use at this point) that takes two (or more) existing devices and creates a new composite device with additional intelligence. For example, a light switch combined with a motion sensor; or a smart lock combined with a door sensor. The idea is to encapsulate the intelligence into a separate codebase so it’s more easily modified and can be replicated (for multiple doors for instance). In particular I’d want to maintain state (e.g. did the light get turned on manually or by the motion sensor) within these composite devices.

I figured there must be existing projects like this and I’m hoping someone can point me in the right direction. Thanks!