Need to Replace a Repeat Loop

I’m new to SharpTools and coming over from WebCoRE. I’m down to 25 pistons that I wasn’t able to make work using simple SmartThings Automations, so this may be the first of many posts like this, but I’m trying to tackle the most important ones first. Maybe I’ll get the hang of this.
The below piston controls a water valve that flushes sediment out of a water filter every day at 5:15 AM if the HVAC is off. It’s a Geothermal unit that uses well water, and I can’t run the flush while the water is running. I have a contact sensor on my HVAC unit that tells me if it’s running. If it’s open, it’s not and the flush can run at 5:15 AM as planned. If it’s closed, then the HVAC is running, and I need to wait until it’s off to start the filter flush. In WebCoRE, I was using a repeat loop to wait (1 minute at a time) until the HVAC Status changed to open. I’m including my WebCoRE script.


Any idea if I can re-create this here in SharpTools?

I’m great at over complicating these things. But I’d use a variable to store if the flush was succesfull for that day, reset it every night.

Then I’d use the time and the HVAC contact as a trigger, if the time has triggered it succesfully, change the variable.
If the HVAC contact triggers, check if it’s after the specified time and if the flush has already executed with the variable. If not, do the flush and set the variable.

I appreciate the idea, but if I use both the time and the HVAC as the trigger, won’t the flush trigger every time the contact opens (or every time my AC or heat turns off all day)? That could trigger the flush many times that day and I only want it to happen once. I don’t see a way to set triggers so that all triggers must be met instead of any, or preconditions like you can use in regular SmartThings automations.

One thought that I did have was that I could create a virtual switch in place of the variable to get around the SharpTools limitation of no preconditions. I could set the trigger as the time, and if the contact is open, run the flush; else, turn on a virtual switch. Then, in a SmartThings automation, set that virtual switch as a precondition with the HVAC Status as the trigger there. Then, the first time the HVAC Status opens after the virtual switch turns on, I run the flush AND turn off the virtual switch. I know that would work, but I wanted to try and avoid creating a ton of virtual switches to achieve my automations.

It’s really surprising that the option to select any or all triggers or to be able to use preconditions is missing here. I am very new to this though, so I may have just overlooked something.

Couldnt you use an If Condition for that? You can switch between ANY/OR and unlike ST Routines, you can nest conditions or use multiple in a row for more complex rules.

Its a bit different coming from WC. Have to wrap your head around the idea of rules being triggered by the Triggers and the flow always running top to bottom. Sometimes I find it easier to split up rules. Or context vars are perfect when you have multiple triggers and you want them to do different things.

I’m not sure it would work in this case, because I believe a trigger is something that happens in that moment. For example, if I set a variable in SharpTools to true if the contact sensor is closed at 5:15 AM. I can use the variable becoming true as the trigger, but if my If statement is for the contact sensor to open, then I don’t think the rule is going to wait for it. It’ll just register it as false and I’m right back to where I was. The functionality of a precondition here in SharpTools is what I think I’ll need in order to avoid using a virtual switch, a SharpTools rule, and a SmartThings automation all for one action. I am really looking for better alternatives.

It sounds like @Sgt.Flippy_PJ is suggesting using both potential triggers and then using a variable to determine if the action should actually occur or if it’s already occurred for the day.

It might look something like:

Triggers

  • Every Day at 5:15 AM
  • Contact Sensor 2 changes to open

Flow

IF (Contact Sensor 2 is open) AND ($IsFlushedToday is false) AND (time is after 5:14 AM)
THEN
  Set $IsFlushedToday = true
  Outlet 8 ▸ on()

The idea being that your primary trigger would be the 5:15 AM and would run the flow if the sensor was open. Otherwise whenever the contact sensor changed to open, that event would trigger the rule and as long as the $IsFlushedToday variable hadn’t already been set, then it would run through the flow.

Of course, you would need to reset the $IsFlushedToday variable to false each day. You could have a separate rule that triggers each day at 12:01 AM and has a single action of setting the variable to false… or you could add it into this existing rule using Context Variables to differentiate on the trigger type (eg. Trigger: 12:01 AM, Flow: IF time < 5:00 AM and $context.event.type is ‘timer’ THEN Set $IsFlushedToday = false). The separate rule approach is easier to understand, but I wanted to include the version with context variables to touch on the reply by @Chris_C about advanced techniques.

2 Likes

Thanks Josh. This will do the trick and no worries on more than one rule. I just like that I can avoid using the virtual switch and it keeps it all in SharpTools. I hadn’t stumbled across that “time is before or after” option yet. That opens up a lot of other doors too. Thanks again!

1 Like