Adjusting Thermostat Scheduler based on Temperature crossing a threshold

I was only commenting on the temp range not the once per range. You don't need to check both bounds. You put that check inside each if and it makes it more efficient.

The temp range has to be high and low in each range because you also have to add the variable check. Because the value of the temp isn't the only thing you are checking. But don't use it....when it doesn't work, you'll see.

I did, worked splendidly. I put the temp range check in a different if inside each else if. Less comparisons on each pass that way.

So, what you posted didn't work then. Thanks.

It worked fine, I abreviated the earlier code since I was writing on an iPad. Now I'm sorry, I had to write the whole thing out for you to show an alternative way of doing something that was more efficient and easier to upkeep.

How do you figure? You have a nested if within an if. This is just one if, else-if. I think mine is a lot simpler to understand. Yours isn't simpler at all.

And how am i supposed to know what you intended. I can only see what you posted.

If temp>50
    if not tempMode =warm
         set tempMode = warm
    endif
elseif temp>40
    if not tempMode = cool
    `set tempMode = cool`
    endif
elseif temp>30
etc

each step keeps the conditionals simple for easier editing(if you mess up a comparison you have to start all over), not the 3 you had.
the max comparisons will be 4 compared to the 12 for your code
the minimum comparisons will be 2 compared to 3 for your code

I don't believe it is simpler for a new person to understand. People get into trouble with nested ifs. You are not going to convince me otherwise. That is my opinion and I am entitled to it. So, give up.

Wow...

2 Likes