I have a hot water circulation pump that I control with a smart plug. When I want hot water primed though the house, I just tell alexa to turn on hotwater. Here's the code I used then (req exp section was not in this first version).
Then, I wanted to set a schedule for the pump to run in the morning and dinner time, so I wrote a second code. Obviously to many of you, when the second code ran it turned on the hotwater which triggered the first code which turned the pump off after 10 minutes. So, I created a global variable so the first code won't trigger if the second code launched it. That also didn't work because I think the first code was launching faster than the second code could set the variable. Anyway, here's the second code with all my attempts to make it work. There has to be some more elegant solution and I'd love to learn something.
FWIW, I also use one of those circulating pumps and had rules that turned it on for a set period of time when a virtual switch turned on, or during specific times of the day. While I don't have those rules anymore, they worked quite well.
However, for the last year, I have used something much simpler, where the pump in triggered using input from a temperature sensor. Also, this rule only runs when the house is in Home mode. It has just worked a lot better, and I don't have to teach any visitors how to get hot water. Here's what it looks like:
That's what I had originally, but the issue was that once rule 2 turns the pump on, it triggers the first rule which is on a 10 minute timer before it turns it off. The first rule is there so we can verbally (alexa) turn the pump on so we don't have to wait 4 minutes with the shower running to get hot.
So, explicitly, How can we not have the first rule turn off the pump if the pump was triggered by the second rule.
I think I answered my own question by just focusing on whether the first rule should turn the pump off where, previously, I was focusing on not having the first rule run at all. Also, a system resource question: I structured the second rule in that way since I felt that using delay would keep the rule running in memory the whole time, and that I assumed it would be a big resource drain. Is that true or false?
No, the rule exits for a delay, so they don't cost anything other than a schedule entry.
Above you posted a test in the first rule that stopped it from running at those two times, and that should be fine to prevent rule one from messing up rule two.
correct me if i am wrong but this rule will never run.. you cannot have a required expression and the opposite in a trigger. as soon as it changes to true i believe it is a race condition.. the required expression now is false but does that change before the trigger. if so it will never run..
I can't answer your specific question about what order the rule runs, unfortunately.
It actually worked where the rule would not run based on the variable set from rule 2. However, in rule 2, it seemed that sometimes it would take too long for rule 2 to set the variable quick enough where it got picked up correctly in the req expression--mostly on the 4:30PM section. Here's the log from 5/11 where 7:00AM worked, but 4:30 didn't.
The only think I can think of is that it took too long for the variable to propagate, but I don't know why.
Instead of using variables, it would probably be easier to use a virtual switch with Alexa rather than the hot water switch itself. This way, you can set up your Alexa controlled rules and automated rules separately:
Rule 1 - Alexa
Trigger - Alexa Virtual Switch turns on
Actions - turn on hotwater; turn off hotwater (delay 10 minutes)
Rule 2 - automation based on time (what you currently have)
This approach removes the hotwater heater itself from the triggers and only has it turning on and off in actions.
I just have mine turn on when certain light switches turn on I.e Bathroom or Kitchen. I also have a rule than when the main TV is on it will run once an hour for 8 minutes. That way when someone is home they don't always have to turn the light switch on.
Failed again last night. Wondering if these actions are wrong. They should be IF THEN statements, but thinking they are all running through so at the end of the rule, the variable is always going to be false. Is there not a way to write some of this stuff in the actual code language?
That is exactly what is happening. Your last action is setPumpisOn to False, so your variable is always being set to False after each trigger. Rule Machine does IF-Then, Else-IF type logic. Look under conditional actions at Rule 5.1 | Hubitat Documentation. You could turn this logic into:
If time is 7am, then On hotwater; set Variable to True
Else-If time is 10am, off hotwater; set Variable to False
Else-If time is 4:30pm, on hotwater; set Variable to True
Else-If time is 7:30pm, off hotwater; set Variable to False
End-If
Wow! OK, just my understanding of the interface. Even in the guide, I see more of what I am familiar with in programming, such as:
IF (Living Room Dimmer is on) THEN
IF (Mode is Day) THEN
Dim: Living Room Dimmer: 75%
On: Kitchen Lights
ELSE-IF (Mode is Night) THEN
Dim: Living Room Dimmer: 25%
Off: Kitchen Lights
ELSE
Dim: Living Room Dimmer: 50%
END-IF
I did figure out the interface and understand what/how it is doing things, so I think it will work fine, now. But, is there someplace you can code it directly that you are aware of like in the guide or as you described. I would much rather use that. Thanks for validating.