Automatic Patio Music (on and off)

So I have sort of got this working, but looking for some expertise help to clean up and combine a couple rules.

Essentially, I want to turn on my Zone 2 (so far so good thanks to @codahq and @mircolino!) for my Yamaha receiver if there is a combined opening of at least 4 times the 2 doors to backyard. If no motion is detected back there for more than 20 minutes, I'd like to turn it back off again.

I have a rule for turning on and separate for turning off. I noticed today that the "on" rule is continuing to add to my door opening count even though it's already on, which I need to correct. Regarding turning it off, I think it's good but might not be the cleanest. In perfect scenario I could rope this all into one rule with else-if structure.

Rule for turning ON

Rule for turning OFF

If the rules work, there is no reason to change them. However, if you want to, you could make some small changes.

On your rule turning on, there are a couple of things I would recommend:

  1. Your “set DoorCount to 2” will occur 15 minutes after every opening of the Back Door or Mud Door. So this might occur many times! To only have it occur 15 minutes after the last time it opened, add “Cancel Delayed Action” at the beginning of your rule.
  2. You could add an “ElseIf Variable DoorCount<4” condition and have it add 1 to DoorCount within it. That way, it will only increase when the count is <4. Not sure you would need to set DoorCount to 2 in that case…?

For the Music Off rule:

  1. You might want to change your trigger to Mode Becomes Night, Mode Becomes Daytime Vacant, Mode becomes Evening Vacant, Rear Yard Motion becomes Inactive or Back Door, Mud Door any Close. It would trigger less often that way
  2. With the change 1., the “Wait for event” will need to change to “Wait for elapsed time: 20 minutes”
  3. It would be good to add an “Endif” though it will work without it.

Download the Hubitat app