Run IF statement with condition during set time as well as run outside of that time


#1

I’m trying to create a program so that during the hours of Sunrise minus 60 min to 3:00 PM for it to compare outside temp to inside temp and if temp is within 2 degrees for it to turn off the fan (as its getting warmer outside and I don’t want to pull in warm air to the house).
Else If the above condition is met then I want it to run the program. I also want to run the program outside of the time but to not compare inside vs outside temp, as the temp is likely starting to cool outside.

When I try to add a time statement to the if area, it cancels out of the program when its outside of the time variable - like it should so its not running outside of the hours I’d like. I’m trying to keep the code as simple as possible.

I’m also looking to see if I can have it send one message only when the fan status changes - IF it changes to on, send one message, if it changes to off send a message. I currently get a message every 15 minutes.

One other thing I would REALLY like to do is if the attic temp is above 110 degrees for it to run the fan at level 80 for 3 minutes, then for it to run the normal program. I want to only do this once a day, not every 15 minutes.

I may look to have the level at 80% run for more or less time depending on attic temp vs outside temp. IE if the temp is 30 degrees warmer in the attic to run for 3 min, if its 35 to run for 4 mins. If its less than 15 degrees to not run at level 100, but to just run the normal 30%.

Ultimately I’m looking to have the whole house fan become automated.

I do plan to add window sensors to this program as well. Currently Nest Secure doesn’t let me check the status of their sensors.


#2

One key to keeping the code simple is to use multiple (small) pistons instead of one giant piston. It insures much smoother execution, and less likely that one trigger will accidentally affect the other.


This is because you have multiple triggers in your piston. I would move lines 52-62 into it’s own piston, and base it on the switch instead of the cfm (which is always changing).

IF ANY of Dimmer1 or Dimmer2's switch changes to off  <-- Trigger
Then
    Send SMS "Fan turned off"
END IF

IF ALL of Dimmer1 or Dimmer2's switch is on           <-- Condition
Then
    Send SMS "Fan turned on"
END IF

I dropped cfm because the cfm changes very very frequently. You only want a notification when the fan starts or stops, so monitoring the switch makes sense.

Pro Tip:
The reason the second IF works as a condition is because the first IF is already monitoring those devices and attributes.


#3

Thank you @WCmore, I created a new piston for sending a message and am taking that out of the whole house fan piston.

Any thoughts on adding a time value so between X an Y it adds a new temp check, but outside of that time it runs everything else excluding the new temp check? Would I have to add all values into the both IF statements? I feel I’m having it run more lines of code if I have everything in both if statements.

BTW here’s the new check for sending an SMS code:


#4

I tried adding in time to run as well as increasing the level to a higher number if temp is 30 degrees over. I’m not certain if I am doing this right. Note this includes the set piston state as well as SMS message. I have this in another piston but am keeping it here for the time being.


#5

Just to clarify:
It is not the SMS that matters which piston it is in… It is the IF block that you don’t want repeated every 15 minutes that I recommend moving to it’s own piston. (IE: The big piston’s trigger is “Every 15 minutes”, and the Dimmer 1 and Dimmer 2’s Switch trigger moved to a separate piston)


The beauty of it is, even though the piston runs top to bottom on each trigger event, if the IF block is false, it skips right down to the next block outside the IF.


As far as piston “nhfe” goes, I would drop the ELSE block, somewhat combine lines 28-85, and totally move lines 86-99 into a separate piston.

Something like this (untested):


#6

I’m liking what you did much better than what I had.

2 questions:

  1. Is it possible to have the house fan turn on when we get close to home and then do a status check every 15 minutes?
  2. it doesn’t look like the new config turns the fan off?


#7

Yes. It is easy to add this section to your piston that you already have monitoring your location as a trigger. (don’t worry about the 15 minutes since the piston above already checks every 15 minutes)


You are correct. I deleted the ELSE to simplify. I do not fully understand your goals, so I did not know where to insert it


#8

Thanks @WCmore, I think I added the off properly :wink: . I want it to stay off if or turn off if presence is not home, smoke alarm is going off (basically if anything on the first IF fails)

I believe this is set up properly for that.

When I didn’t have check every 15 minutes the fan was going on and off quite frequently as the attic temp would get in range, so I wanted it to wait longer before turning on/off/

With that said I want it to turn on when my presence gets close to the house - to pre-cool the house versus wait for the next 15 min refresh. Is this possible? IE to execute when I get home as well as every 15 mins with getting home being the priority. If I am already home for it to check status every 15?


#9

Yup. I believe you nailed it then. :sunglasses:


Yes. Just add that one command to your piston that triggers when you get home. Just add a “Turn on Fan” command to the appropriate section of that piston.


#10

So should I create a new piston - called “near home”, and one of the commands is to run the whole house fan piston when the new piston “near home” is triggered with presence?

If I do that does the 15 min interval restart, so that the “near home” restarts the clock? So if the whole house fan piston had started a new cycle and was 1 min into it and I get close to home, the close to home turns the fan on and the 15 min interval restarts?

Note that I don’t want to turn the fan on if the original IF statement paramaters are not met, IE too hot outside, smoke alarm going off etc.


#11

It is totally your call. I like “complex simplicity”.

I would use your CURRENT welcome home piston to turn on the fan the moment your presence sensor is detected. I would not add any extra triggers, but maybe a condition check to make sure it’s not too hot etc.

This external logic plays no part in resetting the 15 minute timer. My logic is, if you are home, then the fan should be on… If you are just driving by your house, then the fan will turn back off within 15 min or less.


Edit:
The only way to restart the 15 minute timer is to pause then resume that piston, but I do NOT recommend this path! (the 15 minutes begins the moment the piston is saved or resumed)


#12

Fortunately its hard to just drive by my place to have it turn on when it shouldn’t - but completely understand the logic as it could play a big part in others who may want to use what I’ve been working on. Ultimately I don’t want it to check the status of whose home but more of the status of open/closed windows and % of them open. Unfortunately my current alarm system doesn’t allow me to monitor the open/close status of windows but my wife and I know to open when we get home. Once I change alarms (or my current one adds window sensors) the presence will not be based on whose home or not but what number of windows are open. I have it work on if my wife or I are home as we know to open windows, but would love for it to start the fan as soon as we get home (or close to home)

With that said is it possible to have the main Whole House Fan (WHF) piston execute when presence is arrived/near but to only do a status check every 15 mins? Before I had the 15 min check it would cycle the fan on/off too frequently as either the house got cold and then the fan would cycle on/off every min or two as it wanted to stay in range, or the attic to outside temp was out of range again cycling the fan to on/off to frequently.

It sounds like I’d need to add the main IF statement which I have in the WHF to the welcome home piston to check temp, smoke, other items. I need the main IF statement from the WHF to be executed so that the environmental checks are clear.


#13

My first thought?
A Whole House Fan should never be turned on without at least one window open! So please code cautiously. Those babies are expensive to replace!!


Do you only want it to check for presence every 15 minutes? Or do you want the fan to turn on when you are a half mile away? If your answer is a half mile away, then forget about the 15 minutes. The piston we’ve been working on will pick up the slack.

If your answer is every 15 minutes, then the fan will usually not turn on until after you’ve arrived home


#14

Another method to stop the fan from cycling too much (without using the 15 minute check) is to leave a gap between conditions.

Such as:

IF Temp is above 80
    Turn on fan
END IF

IF Temp is below 75
    Turn off fan
END IF

Obviously, you can “complexify” this, but notice how the large gap ensures that the fan stays on for awhile


#15

Completely get you. If Nest secure allowed me to check window open/close status I’d be off and running to the races. Unfortunately they don’t so my wife and I know to open a few windows - the fan is really effective/efficient where we live. Plus if the weather is really warm and its not going to be efficient to run the fan, the AC turns on which turns off the whole house fan :wink:

As to turning on, I’d love for it to turn on when I get home (or a door opens to the house) so that the fan starts to operate while we are opening windows. Since I can’t check if windows are open yet, the best thing I can check is my presence being home or on the way home - I really want an alarm system that I can check window status but integrates well into Nest/Google. Was hopeful Secure would work but am currently disappointed with it.

I like your gap - if temp is above 80 turn on, or below 75 to turn off, but I’d really like for it to always run unless the house gets to 60. What was happening is the outside temp, inside temp and attic temp were close in range so the fan turned off, then the attic got warmer and it would turn the fan on which cooled the attic. it may only run for a few minutes before the attic temp cooled off to the outside temp which is awesome for efficiency, but caused the whole house fan to cycle on/off a lot! Seeing that the attic warms up quickly I don’t know where I’d want the gap temp to be, is it if the attic is over 15+ but less than 5 to turn on? Reality I’d rather the outside and attic range stay close in temp since this will keep the house temp to be the most efficient. I could likely try and figure out what the delta from attic to outside should be before turning on/off the fan but don’t know computational fluid dynamics well enough to put this into code (yet), hence I opted for a 15 min window to cycle thru before running the program again.

If you’ve got some thoughts or know others who have thought about this would LOVE to know.

I really like what this person did - https://community.smartthings.com/t/beta-whole-house-fan-automation/74602
My goal is to keep the inside as cool as possible. Eventually I’ll add humidity as well as air quality to the check (living where I live, Air quality can really suck so would rather have it tell me that air quality is poor, to tell me to close windows and turn on the AC) as well as check humidity, and if over % humidity level to turn off the fan and run AC.

Not being an expert here a lot of this is trial and error, but people like you add a new dimension and really help people like me out!


#16

I am out of freetime at the moment, but a single “SmartThings compatible Contact Sensor” on your “dominant” window could resolve it as well. Then you only have to “train” the family to always open/close that window first (and let that contact be used in your conditional checks)

As you add additional sensors in the future, you can just add them to the previous condition.
Total edit time = 5 seconds


#17

These numbers are definitely meant to be played with. It was just an example. The gap may only need 2 or 3 degrees separation to keep it on or off for an acceptable amount of time. You can tweak those numbers over the first couple of days of use to achieve perfection.


#18

I hope I am not out of line for suggesting this:
I would like to encourage you to think a bit differently on this…
It is much more useful to check if devices can integrate well into the HUB


My logic is:

  • Any given company only connects with a few other company’s devices
  • but a good hub’s sole purpose is to connect with as many as possible

In other words, I believe Nest / Google / AlarmCompanyX should not be your dominant brain power for your SmartHome. Those company’s devices should only be used as tools for programming that you control.

Just my two cents


Edit

Another way to say all of this:
It doesn’t matter if two devices cannot communicate with each other as long as they can both communicate with the hub…


#19

Thanks for the feedback. I’ll go in line with what was written earlier.

Appreciate all the help, I will play with this more - in fact I created two Whole house fan pistons, one for master the other for rest of house as I added a temp sensor into the master room seeing that its the high point in the house and the temp gets quite warm during the day. This will allow for better control of temp in the house as well :wink:

I plan to add a contact sensor (or more) but see my comment below for alarm and adding that condition should be easy ;-). I hate having multiple sensors on a window, really want a system that can tell me open/close as well as act as an alarm.

For the gap, I need to figure this out as it makes sense. I think its very easy to accomodate. I really only need to do it after sunrise plus 4 hours and before sunset plus 30 mins as that is when the temp is likely the warmest. I could likely set the comparison of outside temp vs attic temp over 10-15 degrees as that’s easy to do when the sun’s out to cool the attic, and hence cool the inside of the house. I need to think more about attic temp, inside temp and outside temp and the ranges of each, as well as time of day and time of year. I’d love to run the fan as often as I can but don’t want to pull in warm air outside if the house if colder than outside, but then need to pull in outside air if the attic starts to get too warm. I’m certain there is a way to do this, I just need to think outside the box and write it down. Then try and figure it out in code.

You’re definitely not out of line, in fact I am open for alarm suggestions. I have traditionally been a google home - in fact my cameras, smoke/CO2, thermostat, google home are all google. I thought that the nest secure would be able to integrate into my thermostat for example and turn off the thermostat if the windows were open, but they are on a closed system and don’t talk with one another. Since this was the case I am now looking at alternative alarm systems. I don’t mind getting in early on a company, but secure has not updated much nor been able to integrate into the other nest products. I was hopeful that Nest Secure would allow me to integrate into my smartthings hub but it doesn’t work ;-(

So if there are a few good systems out there I’m all ears. :wink: . But I really only want one sensor per window if possibly (and a smaller sensor/embedded in the window) if possible :wink:


#20

These are words of wisdom for sure!!

I usually go one step farther and mentally step thru the code, top to bottom, with every possible scenario (and trigger) in mind. It helps me to see the branching off under different circumstances.


Most hard wired alarms systems are designed to be closed. (they only want you buying their products). This is quite unfortunate. I usually recommend reliable door/window contact sensors and motion sensors that work well with our ST hub. Yes, this usually means battery changes, but I am all about full home integration, so I try to avoid companies or ecosystems that are closed (minded), or who do not play well with others.

With strategic door/window sensors and a few motion sensors scattered about, SmartThings can be a great alarm system, thanks to webCoRE’s powerful logic.