Jump to content
C4 Forums | Control4

Stop and Break Commands Clarification


Don Cohen

Recommended Posts

This is a very basic question, but I'm looking for clarification of when and how Stop and Break commands should and shouldn't be used, especially as related to Conditionals.  For me, it's mostly the Stop command, but I'd also like to better understand this with Break commands as well.

I have read through the Composer Pro manual sections on this several times, and didn't find it helpful to get the 'big picture'.  It takes you through the mechanical steps of how to add various commands, but for me anyway, I didn't find it helpful in terms of understanding the overall logic of why and when these commands are needed.

Is there a source that I can read to better understand this?  Something that would present a few scenarios, explaining what would happen if they weren't included when needed, and problems that might occur if they were used when not needed.

I've been adding programming for a Vacation mode for my home, especially for controlling Thermostats (2 Control4, 1 Ecobee 3), and running into some unexpected results.  It just hasn't 'clicked' in my mind, to provide that intuitive understanding of why and when these commands should be used.

Thanks.

Link to comment
Share on other sites


Not sure of any other source material for you to read, I personally have not read any of the manuals.
And I personally do not use Break in any of my coding.

Stop will exit the function immediately so no other code is executed:

Break can be used to exit the current clause you are in (If or While loop)
If you are like me and prefer to use macros to execute very specific single routines, then you will find your functions are very short and you never need to use Break

Link to comment
Share on other sites

I appreciate these 2 replies, and offers for assistance.

I was able to get things programmed to behave as I'd like, so I'm good on that front.

I'm just trying to understand when a Stop command would be necessary, and when it isn't, in a general protocol sense.

Let's use my Vacation experience button as an example.  I have 2 Control4 Thermostats on the lower level, and an Ecobee3 on the Upper level.  When Vacation mode is activated, I want to set both downstairs thermostats to Vacation Mode, with a Permanent Hold.  Programming for the Ecobee3 didn't work as expected, so you can see the Conditional statements I put in: what temperature to set if Heat is on, and what temperature if Cool is on, with Permanent hold in both cases.

In addition, I set a Conditional that if either of our Garage Doors was opened while we were away, I'd receive an email notification.

I have Stop commands in the Conditionals, as I've seen them used in examples online in similar situations.  But I don't know if or more importantly why, they would be necessary.

I've attached a screenshot showing the programming I've created.  And please be gentle in critique - other than the 'Associate' Certification through Control4 about 6 months ago, I'm basically self-taught in this.

Screenshot 2020-01-12 21.32.52.png

Link to comment
Share on other sites

There are two reasons to use the Stop command:

 

1. To prevent the program from progressing further if certain conditions are met, because you only want the commands outside the conditional to execute if it isn't met. This would be strictly necessary to do because if the program was allowed to proceed, it would have unintended outcomes.

 

2. If you have a fairly complicated program and you want it to stop executing once a certain condition is met, because you know that executing it further is worthless. You'd be doing this just as a way to reduce the computational load on the system, because letting it proceed would have no user facing effects.

 

The Stop command simply stops the program from being processed further.

 

In your case, your programming will not achieve what you're trying to achieve. The first two Stop commands will prevent the third IF condition from executing if the thermostat is set to either cool or heat, so you should get rid of them.

 

Since the cool and heat modes are mutually exclusive, you can add an Else condition to your first If condition, and nest the second one inside it. This makes it slightly more computationally efficient, because the controller won't bother checking if the thermostat is set to cool if it is set to heat.

 

It's not a big deal the way it is currently set up either though.

 

The most serious problem with your program, however, is that the third condition will only execute a single time when the user taps on the experience button, and never after that while the house is unoccupied—and that too only after you get rid of the first two Stop commands.

 

The program is executing based on the event that the button is turned on once, not continuously as a result of the button's state being on. This is the fundamental conceptual problem with your approach.

 

Get rid of that last conditional and select both the doors (one at a time) from the devices column on the left. Using the door open event for each door, program it to fire the email based on the condition that the vacation mode button is in the on state. Again, no Stop commands necessary there either.

 

Please let me know if you run into any problems or need clarifications.

 

 

Sent from my iPad using Tapatalk

 

Link to comment
Share on other sites

Your detailed reply is most appreciated, Aayush.

I deleted the 2 Stop Commands, along with the entire 3rd conditional.  I programmed for the 2 Garage Doors as suggested.  For the Conditional for the Vacation Button, I had to use the "STATE" Device Variable for the Vacation button, manually typing in "On", since there was no Conditional option for the Button itself.  I assume this is correct, but please let me know if I overlooked something.

I somehow thought the Stop command in a conditional impacted only the programming *within* that conditional, but based on what you're saying, this was quite wrong.  Once again, I really appreciate your taking the time to help.

Link to comment
Share on other sites

Your detailed reply is most appreciated, Aayush.
I'm glad you found it helpful.

 

I deleted the 2 Stop Commands, along with the entire 3rd conditional.  I programmed for the 2 Garage Doors as suggested.  For the Conditional for the Vacation Button, I had to use the "STATE" Device Variable for the Vacation button, manually typing in "On", since there was no Conditional option for the Button itself.  I assume this is correct, but please let me know if I overlooked something.
I've yet to use these experience buttons in my own programming, so I cannot be sure. You should definitely test if it's working as intended.

 

I somehow thought the Stop command in a conditional impacted only the programming *within* that conditional, but based on what you're saying, this was quite wrong.
That would be the function of the Break command you referred to before, but even then, its use would be within FOR WHILE loops rather than IF conditionals, to allow you to break out of the loop based on certain conditions being met while a separate set of conditions that keep the loop running remain true. I've never had to use the Break command in any of my own programs.

 

 

 

Sent from my iPad using Tapatalk

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.