Problems with repeat delays and action delays

Hi All, very new to all this, but getting there slowly, dont even know what a boolean is.... :wink:

Heres what im trying to do, and if i get it to work its wife type brownie points...

We have 2 small freezers and the doors sometimes bounce back open when you close them, not enough to notice but enough to make the compressor cut out and defrost the food.

Ive got a couple of door sensors and i want alexa to tell us when we have left the door open after a specified amount of time. I then want her to repeat the message until we have closed the door or cancelled the alarm.

Alexa, not being all that smart cant be set natively to do this, so ive created a virtual sensor which i want to control via hubitat and the physical sensor.

When the door sensor opens i want hubitat to open the VR sensor that alexa can see, this will trigger the message, but of course it will only sound once and if we arnt in, then its soggy food time, so i need hubitat to close the vr sensor and then open it again after a set period of time.

I then need to repeat this action until we close the door or cancel the alarm.

Ive managed to get He to do this but the timings are all wrong, The rule runs once correctly but then for the repeat, it defaults to the repeat delay duration for all of the actions. Ive been playing with this for hours now and cant get it to work, can anyone please tell me what the stupid mistake im making is please?

This would be a lot easier to do with the Echo Speaks App.

Hi. Never heard of it ill look it up, but that being said that wont help me learn rule machine. i dont think that what im trying to do can be that complicated? i thought i was starting out with something simple?

Folks will generally encourage you to only use Rule Machine when you can't do it in a simpler way with other apps, due to the amount of overhead that Rule Machine requires. Echo Speaks is not necessarily low overhead, but it's designed to allow you to do very customizable notifications through your Echoes, and it supports customizable repetition. If you like to use Alexa to announce things, Echo Speaks will make things a lot simpler than building one off rules for every announcement. It also allows you to do all the automation 100% on the Hubitat side (meaning that you don't use Alexa routines for any part of the process.)

I haven't used repeat at all in Rule Machine, and I am not a Rule Machine expert, but if I were trying to do what you are, I would be inclined to drop the repetition, and add 2 more trigger events - Dining Room Freezer closed, and dining room freezer (VR) closed. Don't put a delay on the action that turns on the virtual switch. Make turning it off cancelable with a 2 minute delay. (Canceled if Dining Room Freezer closed). The else statement would be turning off dining room freezer (VR). This way, turning off the virtual switch causes the rule to reevaluate and trigger again if the freezer is actually still open.

I haven't tested this, but it's what I would try.

1 Like

Thanks for that Ed. Ive installed Echo speaks and am looking at it now. Ill also try your suggestion via rule machine and see how i get on.

While Echo Speaks or Alexa TTS would both work for this, since you just want to speak a specific phrase, an Alexa Routine with a virtual contact or motion sensor on Hubitat isn't very hard to set up and is an "official" way to do things. The other solutions rely on undocumented interfaces into Alexa that Amazon could break at any time (though they have not changed anything insurmountable to date)--just something else to consider. But they do get you more power.

Back to this rule, I often refer people to this post when they have questions about repeats: How to get Repeated Notifications using Rule Machine. There are several examples of how to set up repeats and how to stop them, and even though you aren't really doing a "notification" (from Hubitat itself), the basic idea is the same for any repeat and it's just the actions inside that would be different.

On a related note, since Alexa (last I checked) doesn't support switches for "triggers" for Routines, I'm assuming you're using some sort of custom "motion with switch" or similar driver so Alexa sees it as a contact or motion sensor it can use. If that driver has an "auto off" (or "auto inactive") setting, you could save yourself a bit of trouble in the rule by just configuring that. But if you have to turn it off yourself (and you indeed likely do so Alexa will see it as "active" again), then you'll have to do it yourself in your rule like you are now--almost. What you have now will actually turn the switch off before it turns it in, as the "delay" option on an action does not wait for the delay to be over but rather schedules that action for the future, then moves on to the next action. If you use a plain "Delay" action, then the actions do pause at that spot until the delay is up.

Going back to that post above, one of the formats suggested there could look something like this in your case--except I added the first two lines in the Actions to not start the notification cycle until 2 minutes have passed (a "Wait" with a timeout; the simple condition "IF" after the wait tests whether we got there because the event happened--i.e., the door closed--or the time ran out, and does not proceed if it was the former).

Trigger Event: Freezer door open

Actions:

   Wait for events: Freezer door closed --> timeout 0:02:00 (cancelable)
   IF (Freezer door closed) Exit Rule
   REPEAT Every 0:00:30 (Stoppable)
      IF (Freezer Door Closed Then) THEN
         Stop Repeating Actions
      ELSE
         On: Dining room freezer (VR)
         Delay 0:00:05
         Off: Dining room freezer (VR)
      END-IF
   END-REP

(To be clear on the timing, this starts the notifications if the door stays open for 2 minutes and repeats the notification every 30 seconds. The delay before the virtual switch turns off just needs to be less than that 30-second repeat interval; I choose 5 seconds there because it seemed sensible enough. You can adjust these as needed for your case.)

I'm not sure if Echo speaks can "natively" handle repeated notifications until a certain condition is met. If so, that would certainly be easier. :slight_smile: (Aside from needing to set up ES in the first place.) If not, with either TTS solution, you could use the built-in Notifications app, which can do everything this rule does but with a few clicks of configuration instead of manually specifying all this logic yourself--you just need a TTS or notification device, as the Notifications app cannot work with switches in this manner.

Thanks Bert/Ed.

I have set up Echo Speaks and have it up and running but it falls foul in one important area No interweb... no alarm...

My internet is not very reliable and so im hoping for a solution that will work at least partially, without internet, even if i cant get alexa to trip an announcement ill have all of the lights flash on and off a few times, for that im thinking ill need to do something entirely within HE.

At the moment all of my lights are hue controlled so i dont think that would work without the interweb either, but once ive moved everything over to HE then that will work, at least i think it will!

Lots to learn and im enjoying the experience.

The wife is very impressed with the new alarm, thanks :smiley:

That will happen with any Alexa solution, including the virtual switch. I know options like Sonos will work locally after Hubitat caches the file the first time (assuming the text doesn't change). It can also be used to just play a predetermined local file--that's what I do for my doorbell since I also have a sound effect in there. Sonos isn't cheap, though. The Ikea speakers are compatible and less expensive, and I have a mix of both.

I think the Google TTS (via the Hubitat Chromecast app) might be local after the first time, too, but I can't say that for sure. There are other options like LANNouncer and VLCThing that were popular on SmartThings and (I think?) ported to Hubitat, but I've stopped using the former--which I did for a while--since I've found options that are better suited for me now. But they can operate locally. Just a few ideas I can think of!

But most of my announcements aren't that important, and Alexa works fine for those via official or unofficial means. "The washing machine is done!" :smiley:

Hi Robert,

Ive been playing with rule machine and ive managed to get the code that you posted to work for me. I assume that you wrote the code in some sort of IDE to post it? can that be done in rule machine, if so how, is there a tutorial somewhere?

I have a few questions, if you have the time to answer them. This is the rule as ive set it up with a slight mod (that doesnt work...)

The code that you posted had "stop repeat" insted of "Exit rule" in line 5, The reason i tried this is that when i started the trigger, the action worked fine, but once the sensor was "closed" the log kept repeating entries for the alarm and i thought that this was a bad thing because it must use unnecessary overhead?

So i tried entering an exit rule action at the end and that didnt work and the i change the stop repeat to exit rule and that had no effect on the log entries.

Here is the log with code as you suggested.

And here is the log with my amended code.

I think im correct in thinking that i need an exit rule action somewhere but i cant figure out where, is that correct, if so where do i put it?

Also where can i go to find out how these actions work, what they do and what order they do it in?

Do i need to learn C++?

Ive played with Arduinos as well and this all seems very similar stuff, i really need to learn how it all works if im ever going progress past cutting and pasting other peoples code.

No, "Exit Rule" will not help. There is often confusion about what this action does, but it does not stop or cancel any delays, repeats, waits, or schedules/subscriptions of any kind--it just skips all actions that come after it (for that particular execution of the actions).

From your screenshot, it appears you did not tick the "Stoppable?" box on the repeat action. That should fix your problem.

Actions run in the order you specify (though there is no guarantee that a device will have completed executing a particular command by the time the next action runs). Actions generally correspond to commands on devices, for which I know of no formal list of what corresponds to what, but it's generally easy to figure out: "Turn on switch" runs the on() command on the device, for example.

Some "actions" aren't really device actions at all but are specific to Rule Machine, like "Delay" or conditionals. For those, I highly recommend reading the docs.

You can if you want to, but user code on the hub is written in Groovy if that's why you're asking. :slight_smile:

Some people are picky in insisting that Rule Machine isn't really "code"--and it isn't, though the UI displays what you've configured in a sort of pseudo-code. But it does still require you to think a bit like a programmer: what order you want to do things in, how conditionals (Boolean algebra) work, and an examination of how your triggers (the only thing that make your actions run on their own) interact with these actions, among other things.

In most cases, I'd recommend using one of the built-in apps. The Notifications app would be a good choice here if you had a "real" TTS device, as it can handle all of this configuration with just a couple clicks (both the initial delay and the repeat--that last thing was recently-ish added as a lot of people were previously resorting to rules for this common task). Alas, using the "virtual sensor" workaround on Alexa, you're using devices this app doesn't support, so, a rule it is! (You could certainly do a custom app, but that would probably be even more work.)

From your screenshot, it appears you did not tick the "Stoppable?" box on the repeat action. That should fix your problem.

DOH! Thx. that solved the problem. Do i need to look for a "cancellable" button for the timeout? i cant see one.

actions run in the order you specify

My Bad i know that, what i should have said is that i need to understand how the IF, IF ELSE, THEN & im certain curly brackets will be involved as well somewhere, work.

In most cases, I'd recommend using one of the built-in apps. The Notifications app would be a good choice here if you had a "real" TTS device,

Not sure what a "real TTS device" is? i assume you mean Text to Speech? not certain what a real one is? ill try the notification app as well, but learning about all of these apps is about as much hassle as learning to code :rofl:

Groovy???? never heard of it, things are never easy are they?

Thanks for your help.

I assume you mean the "Delay"? ("Timeout" is a different thing for "Wait" actions, which work slightly differently, though "Wait for elapsed time" is also a thing.) If so, it's first important to note that "cancelable" does nothing without a "Cancel Delayed Actions" somewhere. Like the "stoppable" repeat and the "Stop," they work together to actually make the cancel (or stop) happen; you'd need both. In this case, I probably wouldn't bother since the difference is likely to not matter in real life, though if you close and re-open the door after this repeat gets set into motion it's possible you won't get the full 10 seconds of delay before that virtual device turns off. (Any scheduled delays that aren't called remain, even if the rule actions begin running again because the rule was re-triggered.) Since you want it basically be momentary anyway and "on" is the only important part, I wouldn't bother with the extra clicks.

A classic example of when you definitely want this: if you're creating something like a lighting automation, it does matter in real life. You want the "timer" to restart if motion becomes active again if you're using a delay after motion inactivity to turn off the lights. There are a couple examples of this early on in the docs I linked to above. (Not that I'd recommend RM for that automation when Simple Lighting or Motion Lighting would work, but for the purposes of learning... :slight_smile: )

No i mean this bit on the timeout in your original code?

Ah, sorry, I don't know what I was thinking! There is no "cancelable" option for delay timeouts, so just set the timeout, and that should be good.

2 Likes

Just thought id pop on here and round off the thread so that anyone reading it knows how i achieved what i wanted to do.

AIM
To have an alarm/notification system that tells me when a freezer door has been left open for more than 2 minutes.
The Alarm cannot be totally reliant on WiFi/ internet. ( i suffer from 200 micro dropouts of 30 seconds or less /day)
The alarm must be visual/audio/writing

SOLOUTION

This is the best that i could do with the experience that i have.

Set up a virtual motion sensor the code came from

https://raw.githubusercontent.com/ogiewon/Hubitat/master/Drivers/virtual-motion-switch.src/virtual-motion-switch.groovy

Copyright 2018 Daniel Ogorchock

The sensor has a nice little auto reset feature which ment i could make my rule in rule machine a little simpler.
I altered the code to add a 30 second delay on the reset, as the default had a 5 second max and i had to allow for my micro dropouts!

I then wrote this rule with Roberts help!

image

So at this stage i had an alarm that would activate a virtual motion sensor after a 2 minute delay (the sensor would reset after 30 seconds). and then would repeat the activation every 5 minutes until the door was closed.

I synced the virtual sensor with Alexa and wrote a separate routine for all 8 of my alexa devices with an announcement "your dining room freezer door is open", unfortunately groups arnt supported.

I tried to use Echo speaks for this but it doesnt support the new echo dots and they wouldnt play the announcement.
I also tried Notifications but that also doesnt support the new devices.

So i now have my audio announcement set up and working but its reliant on the interweb so the next stage was a visual alarm that doesnt need interweb.

For this i used a few lamps around the house on zigbee plugs and got them to flash until the door was closed. i used the following rule.

image

so now after a 2 minute delay i have flashing lights on/off every 4 seconds until the door is closed.

I then used Notifications to send a message to all of my devices via the HE app.

Job done!

Had notifications supported the newer alexa devices and been able to set different repeat settings for written and audible notifications this would have been much easier to set up! but hey ho!

if anyone has an easier way to do this, id be interest in knowing about it.

Thanks

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.