RM timed power monitoring

I have searched and tried to wrap my head around this I am wanting to do and it never works 100%, so I am hoping to get some smarter RM people here.
What I am trying to do is this. I have a small water heating device that is turned on with a remote. I am wanting to monitor that wattage when it goes > 50W and then delay 45 minutes (usage). After that 45 minutes I want it to monitor the wattage for an hour and if it goes above 50W again it turns off the switch. This is just incase someone forgets to turn off the water heating 45 minutes after it was turned on. I have tried everything I can think of that I would think would work and it doesn't. Thanks in advance for your help.

Would this work?

Trigger: switch *changed*

Actions:

IF (Switch on) THEN
    Wait for condition: Power > 50 W
    Wait for event: elapsed time --> 0:45:00
    Wait for condition: Power > 50 W
    Off: switch
END-IF

This rule will trigger when the switch turns on or off but really only do something when the switch turns on. then it will wait for power to become >50, then wait 45 minutes, then wait for it power to become >50 again, and then turn off the switch if that happens. (I'm using "wait for condition" instead of "wait for event" here so it will continue if power is already at that level; if you don't anticipate that happening, "wait for event" is what I usually prefer instead). If usage never goes above 50, you'll be stuck at that first wait indefinitely, which is good since you don't want to continue yet; if the switch turns off, any "wait" is cancelled (and nothing after it run), which is why I'm using a "changed" trigger and not just an "on" trigger, though I'd generally prefer the latter kind if I can. When the switch turns off again, the rule will trigger (cancelling your wait, if still going) and your actions will "run," but they won't actually do anything since the conditional they're all enclosed in is false.

Hum, I was in the process of writing the rule to test it out and I guess I left out the part where I want the switch to be on indefinitely. I want the wait condition power > 50W to time out after an hour so the device can be turned on again after a hour and 45 min without tripping the rule and turning it off. Basically in a hour and 45 min the heater device can pull >50w without turning off the plug but starting the rule all over again, but it it comes on after the first 45 min wait, during the hour wait, it kills the switch.

Now I'm confused--just having problems piecing the two explanations together, I suppose. :slight_smile: Can you explain it all in one piece?

Otherwise, if it helps, you can set expiration times on "Wait" actions (but you'd need to test something after the wait to see if it went on to the next action because of that or because an event actually happened).

Ok device is powered on (already). You turn the water temperature up that causes the wattage to go more than 50W which will trigger the rule. The rule waits for 45 minutes before doing anything else. After that 45 minutes the rule "monitors" the wattage for an hour to see if it goes above 50W again and if it does, it turns off the plug. If not then it exits the rule or times out after that hour and the plug stays on. So lets say in two hours after the first time it was triggered, you can trigger it again without the plug turning off since the rule would just start over again.

I got it to work with this, however, every time it goes above the 50W in that first timer (45 Minutes) it resets the timer to 45 again. That is the only thing I have to get working now, where it only triggers the first timer once. *I have the times to 1 minute for now to make testing quicker.


It will never turn off with it resetting the timer over and over. I tried private booleans but that just exited the rule all together.

If that rule does everything you want it to except not "reset" the timer, then there is an adjustment you can make that would help. It's also worth noting that there's no need to enclose your actions in this conditional, since it will always be true any time the actions are running--this condition completely overlaps with any event that triggers the rule, and triggers are (besides calling the rule from another rule) the only thing that makes your actions run. The first "Wait" is also pretty much unnecessary too since it would run nearly immediately after the trigger, which again is an event that would meet that condition.

Private Boolean may also help, but it's not clear how you were using it before.

If that's all correct other than the one thing you mentioned, then maybe:

[EDIT: Nevermind, I don't really like this given the overlap between the trigger and "Wait." Will have to rethink....]

Trigger: Power > 50

Actions:

IF (Private Boolean is True) THEN
  Set Private Boolean False (this rule)
  Delay 0:45:00
  Wait for conditions: Power > 50 --> timeout 0:45:00
  IF (Power > 50) Off: Outlet
  Set Private Boolean True
END-IF

If you want more things to be able to "reset" Private Boolean, it may be easiest to combine this with another rule that modifies Private Boolean on this rule. You can also cancel that delay from another rule with a "Cancel rule timers" (or by marking it "cancelable" and using "Cancel delayed actions" in the same rule, but that might be difficult here). In any case, a "delay" here does not get cancelled unless you do so explicitly, so that's why I'm choosing it instead of a "Wait for event: elapsed time."

Or if I'm misunderstanding something, maybe try explaining it again (sorry! :rofl:) without thinking about it in terms of Rule Machine--just a description of what you actually want to happen.

1 Like

Thanks! I will give that a shot tomorrow when I get home from work and report back. Thanks for your time. I was going to delete the first wait after I got it working since, like you said, it was not needed. I just didn't mess with it since it wasn't hurting anything at the time :grin:

I was able to VPN into the house from work and pick my wifes wax warmer to test with. It worked great the first time it ran after I created the rule and now it doesn't seem like the boolean wants to go back true. I even stopped the rule and started it back up again but it keeps skipping everything on the next run (after waiting > 3 min from the last trigger).


Just noticed this, this might have something to do with it (error). Going to reboot hub and try again.

I don't like when the Event for a Trigger and a Wait are the same. When the Event happens, which is executed first? If it's the trigger then you'll cancel the Wait and be stuck with a false Private Boolean and you'll need to reset the PB to get this rule working again. This is probably a case where I would use IF-THEN-ELSE.

I hate to ask this but where would you put the If-Then-Else? It seems like that is exactly what is happening because I am having to manually set the PB back to true before I can test the rule again. I am sure that java error isn't helping either. I have been working on this rule most of the weekend, trying to get it to work so my brain is mush from this dang rule.

Here's an option to try:

Trigger:
Power level of Living Room Smelly reports > 50.0

Action:
IF (Private Boolean is true) THEN
    Set Private Boolean False
    Delay 0:45:00
    IF (Power level of Living Room Smelly is > 2.0) Off: Living Room Left Window
    Set Timer True
    Set Timer False --> delayed 1:00:00
    Set Private Boolean True --> delayed 1:00:00
ELSE-IF (Timer is true) THEN
    Off:  Living Room Left Window
END-IF

Variable:
Timer (type Boolean)

@pseudonym It actually looks like it is working which is great! The only thing I see is this error, not sure why it is throwing this error. The times and device is temporary to test with until it works 100% then I will put the correct device and times in.


I believe a pop() error indicates an issue with multiple instances of the rule running simultaneously. You can see the rule is triggered when the power is 7 and again when the power is 13. I need to look at it more to see why it's identifying delayedActs.

I'm not sure why the pop() error is being thrown. Would you try moving
Set Private Boolean True --> delayed 0:02:00
to before the Delay and change the delay to 2 minutes and see if you get the same error?

Yes, the same error came up.

@jonathanm8 I don't see how the rule is colliding here. Try the Run Actions button to run only one instance and see if it's still happening.

Looks like the error didn't come up this time with running it on the run actions button.

Odd, I ran it again this time and it worked without error. Thank you @bertabcd1234 and @pseudonym for your help with this. I would probably have gone mad trying to come up with that kinda logic for this rule to work. I am going to put it in place and out of the testing stage to see what happens but I am sure it will work.

It still isn't working, I think the power is triggering the rule again and turned off after about a min or two from being turned on. I don't even know what to try with it anymore, about to say the heck with it. Is there such a thing where a global variable can be set and the rule won't try to run again no matter how many times the trigger is triggered in that 45 min delay window? It's almost like it is ignoring the 45 minute delay.