New to webcore. Need a timer that monitors a variable

webcore

(Wes Treihaft) #1

I need to create a timer that will watch a condition to manually turn it off. This is for a sprinkler system with 6 zones. I wanna set a timer for each zone and sequence through them. I also want to create a virtual switch that if I turn it off the system shuts down, rests and sits in pause mode till that virtual switch is back on. So my question is whats the best way to create a timer to turn off a zone then start another that constantly checks a virtual switch? While loop and increment a variable each second or is there a better way?


#2

Please join us over at https://community.webcore.co

There’s over 500 people there just focused on WebCoRE.


( I hate Mondays) #3

There are better ways. You can start with something along these lines:

if
   time happens daily at 3am
   and
   virtual switch is off
then
   Turn zone 1 on
   Wait 5 minutes
   Turn zone 2 on
   Wait 5 minutes
   ...
   Turn zone N on
end if;
Turn all zones off

(Wes Treihaft) #4

Problem is I wanna monitor the switch while the sprinklers are on so if the front door opens and zone 2 is on Its paused for 10 min etc. I want them to run for say 10 min each zone but I need a way to pause and rest the system. A wait command is blocking code isnt it?


( I hate Mondays) #5

The virtual switch turning on will cancel all waits and continue executing the last command, which turns it off. This is event polling… every event will start the piston execution - so in your case, at 3am (arbitrarily selected by me) or the switch turning on or off. You need to force subscription on the virtual switch though - on that condition, check the cog (advanced options) and change the subscription mode to always - this way, they only start at 3am - but if during their work the switch comes on, they all stop - the code above has no way to resume the work though, that’s a bit more complicated and can be done, if you need that.


(Wes Treihaft) #6

I am still trying to understand how the “wait” is bypassed? Are you saying that each time the virtual switch state is changed the piston will re-run? As in it is consistently looping the same piston and if the first if state changes it will run the “else”?

Thank you for your help :slight_smile:


( I hate Mondays) #7

If you meant constantly, then no. Each event will cause it to run again. You can control whether an action is cancelled or not when the condition applied to it changes during such a rerun.