Rules Structure
Multiple additional TE are possible but not required. If multiple TE are given, each TE by itself is sufficient to trigger the rule. The sample Reminder Rule Pepper Time illustrates the use of multiple Trigger Events.
Three times per day the occupants of the house are reminded that it’s time for refreshment. At the proper time, a TE triggers our rule. The SC is evaluated. If the house mode is Normal, meaning people are home, the reminder is issued. But it House Mode is Away, meaning the house is empty, then reminder is skipped.
Any Rule may have multiple TE, and multiple SC, but once the evaluation tests True, the actions are executed unconditionally.
Rules Groupings
Assuming your program uses timers, there need to be rules that deal with the consequences of timers expiring. It is helpful to group these Rules together by using similar names, as we showed with Macros.
Another group of related rules might deal with making announcements to the house when status changes. These can likewise be grouped together.
Other logical groupings include sensor Inputs, Status Reporting Rules, Error Recovery Rules, and so on. Grouping related Rules together helps keep the logic simple and easy to understand and troubleshoot.
Advanced Logic Structures
Rules are a very simple IF/THEN program statement, and many folks with some programming experience lament that lack of advanced control structures that they are used to seeing in “real” programs. What is less than totally obvious is that many of these structures may be easily simulated. The secret is to spread the logic across multiple rules. Consider this sample rule designed to remind the users when to take refreshment.
Nested IF/Then
One limitation often cited is that once a Rule is evaluated, the Actions execute unconditionally. Many times we would very much like to write something like the logic in the Nested IF/THEN example.
Note that the second Action is not executed unless the evaluation of the Flag named GuestsPresent returns TRUE. While this example is trivial, it serves to illustrate the power of a nested IF/Then construct.
Unfortunately, HAL doesn’t support this sort of nested logic structure. It is necessary instead to rewrite this logic in a format more compatible with HAL logic. This means that the logic must be spread across multiple rules. Write the logic as illustrated in the sample RULE Nested IF/THEN and it will function exactly as if it were a true nested IF/THEN program statement..
|