Over the course of the last weeks a looked at a few smart home videos and in one of them i saw something really interesting. There was a smart home app (i don’t know if this was Homee or Samsung Smartthings) and this app had some predefined events like Coming Home, Going to Bed and so on and so forth.
This Design Pattern will be related to the Proxy Item Design Pattern.
My Core thought behind the pattern is, that we got a central Selection for the current Event which is happening.
What i have in mind are the following:
Leaving Home with guests (and there is still somebody home)
Going to Bed (which doesn’t mean you are going to sleep)
Fall asleep (the process of falling asleep)
Starting to Cook Food
Starting to Eat
So whats the advantage over a lot of simple switches for every “Scene” or in my case event?
You can define one point to start execution for event changes and a lot of places to trigger these events. For example. I started with a lot of switches for different events during the day. So i had a Coming Home/Leaving Home Routine, some Routine for going to bed (which switches everything besides the bedroom off) and a routine for falling asleep (again, turn everything off including the bedroom and starting some audio drama on my wireless speaker). This routines where scattered arround a lot of rules and i wasn’t sure what was happening if i switch something on/off.
So in the end you could define one central rule for setting these events and from there you could branch to a different rule, however you’ll always know what’s happening on one specific events. In addition to that you can use this data in grafana for reporting.
This sounds like an application of the Time of Day design pattern. The whole idea of a DP is that is applies to lots of different situations so don’t be mislead by the fact that the example is based on time. You can use the same approach for lots of different types of events, not just time based events. You can even mix and match.
And the Time of Day DP is itself just a special case for the Separation of Behaviors DP which is exactly as you describe, a centralized Rule to calculate a state and then the rest of your Rules will just look at the state instead of needing to redo the calculation.
Some users prefer using lots of different Switch Items. I prefer to use a String Item as it is more self documenting and requires less book keeping.