AT Smart House

For the sprinkler see Design Pattern: Cascading Timers for an alternative way to implement it. The key features your current approach lacks are the ability to cancel the irrigation and handling the case where OH goes offline while the irrigation is running.

I’ll also note that in your first rule, zone 1 will turn on then off almost instantly because of the plusMinutes(0), then zone 2 will run for 2 minutes, then zone 3 will run for 2 minutes. This is not the behavior described in the comment.

The only real difference between the two rules is the trigger, why not combining them? One of your major goals should always be too avoid duplicating code.

For the minor differences between the two rules you can test to see if receivedCommand is null. If it is null you know the rule was triggered by the time trigger. If it isn’t null you know it was triggered by received command.

1 Like