Please critique my first rule


#21

@asj I'll add a delay cancel at the end JIC, but excuse my ignorance, What is an edge case?


#22

An edge case is part of a problem that happens in frequently, and also a bit outside the norm. So in your case if you don't cancel the delay if the door open, closes, then opens again you would not get the delay you're looking for before the warning played. Sometimes edge cases don't mater much since they're so infrequent no one cares. Other times when things appear random/hay wire etc it really hurts the WAF.


#23

What's wrong with this? This will work correctly.

Trigger stairs door changed.

IF(Stairway door open) THEN
   Speak on living room mini: '%device% 
   %value%'
   Delay 0:02:00 (cancel)
   Repeat every 0:05:00 (stop)
   Speak on living room Mini: ' please close the 
   %device%'
   END-REP
ELSE
Stop repeating actions
Cancel delays
END-IF

My rule I have had for months


#24

Thanks @asj, that makes sense. might as well write the code the best way to begin with. and the WAF is a Huuge consideration in this household... :grimacing:


#25

@borristhecat I had tried a rule similar to that. What happened for me is that after the initial Door opened played, if the door was closed after 2:05 minutes, the first 5 minute warning would still play even though the door had been closed for 3:55 minutes. The only thing that worked reliably for me was to put the door check inside the repeating loop.


#26

You obviously didn't tick the cancel box and OR didn't have the else cancel delays that's the only reason that would happen. Only other reason is if you just had trigger of open not changed. I promise if you do exactly as I have told you it will work.


#27

I think you have a race condition, albeit pretty small, and I bet it would have hard to show since it's probably 100ms-1s long. But what happens when you can cancel the delay and the repeat has yet to start, so there's nothing to cancel. Could you cover your bases this way?

IF(Stair way door open) THEN
   Speak on living room mini: '%device% 
   %value%'
   Repeat every 0:05:00 (stop)
     Speak on living room Mini: ' please close the  %device%' delay 0:02:00 (cancel)
   END-REP
ELSE
  Stop repeating actions
  Cancel delays
END-IF

#28

the delay is what gets cancels so that stops everything, before it starts.


#29

@BorrisTheCat Here is where I have arrived and it seems to be working great now. The trigger seems to have been the issue. I have tested both open and changed triggers several times before when others suggested it, but I always had issues with reliability before. Evidently the changed trigger doesn't work unless some action statement is present.
Here is the rule without the door check...

IF (Stairway door open(F) [FALSE]) THEN
Beep: Kiosk - Kitchen
Speak on Living Room Mini, Kiosk - Kitchen: '%device% opened'
Delay 0:02:00 (cancel)
Beep: Piezo Buzzer, Kiosk - Kitchen
Repeat every 0:05:00 (stop)
Speak on Living Room Mini, Kiosk - Kitchen: 'Please close the %device%'
END-REP
ELSE
Cancel Delayed Actions
Stop Repeating Actions
END-IF

This looks clean and efficient, a long way from where I started and I thank you and everyone else for the advice and knowledge! Hope I wasn't too frustrating for you guys. This is like a totally different way of thinking. One in which I am not to versed in but I am starting to get the gist of it.


#30

Ah of course that makes sense, was thinking it was more like a timeout where the next step would continue on timeout, but that makes it consistent with canceling a delayed action.


#31

I just noticed the delay on the speak command, If you have a 5 min delay and then a 2 min delay on the speak command doesn't that set it to speak every 7 minutes if the contact remains open?


#32

It is but the key thing is about thinking about what you want it to do 1st then work out when you want it to fire. By only having a trigger of open it will only start on OPEN and never again until the next open event.
So if your after a basic action then a single trigger to do this is fine. BUT when your doing a conditional action in needs to see both or more events to then decide what path to take IF OPEN then this, ELSE then this. The else would never come in because its only ever seeing the IF OPEN whereas "changes" means when this device sends a event (ANY) flow though these conditions and decide what i want it to do.


#33

once the time elapses it will continue but a standard delay kind of pauses the rule (for clarity it doesn't actually pause the rule its schedules a wake up in x time) but when you cancel it, it will stop everything below it.


#34

That makes perfect sense, evidently it wasn't common sense for me but having it explained makes it understandable...


#35

Its a 5 second delay and its not needed really.

how the rules runs is, the door has to be open for 2 mins if it is it will then start the repeat, it will say the message after a further 5 seconds then as long as the door stays open in 1 min and 5 seconds it will speak again. As there is a limit to how many times it will repeat it will only do the cycle twice. So if it does the full cycle then essentially the else statements become pointless because there is nothing to cancel or stop. But if the door closes during any point of the cycle everything will stop.