Do, If, When, Repeat, While loop Help


#1

1) Give a description of the problem
While Loop not repeating

2) What is the expected behavior?
A loop to maintain sensor temperature with thermostat

3) What is happening/not happening?
Repeat, While loop is not running until break


#2

You don’t need a while loop for any of that, just IF statements. The IF statements will trigger whenever your temperature sensor reports a new temperature (as long as you have them subscribed.

Another reason it doesn’t work - you have our WHILE loops nested inside a “every day at 4am” loop. That will trigger one time at 4am - the next time the piston runs it’ll evaluate false and kick out of it.

Why don’t you put in a few words here what you’re trying to do - I’ll see if I can come up with something much simpler to get where you’re trying to go.


#3

Michicago,

Thanks for your reply…

I took your advice and tried to simplify the cooling piston code attached.

The goal is to have the piston look at the forecasted weather and then determine a cooling schedule for the day…for example if the forecasted high is 65 F then turn the heat on to 68 F. If the forecasted temp is 88 F then turn the cool mode on and cool the to 73 F.

To complicate things a little more. I have used a remote sensor that controls the thermostat. The way I do that is to limit the main thermostat settings. For example, if the remote thermostat is desired to be a temperature of 72 F in the cool mode, then when the remote sensor is above 72 F I have the main thermostat cool to 68 F until the remote sensor reaches 72 F, then I have the main thermostat set at 74 F which basically keeps the rest of the house at a maximum temp of 74 F. To keep the loop if the remote sensor is below 72 F then the main thermostat is set to 74 F and the loop continues until the next time break to set up for the later day Forecasted events…

In Colorado, evenings drop down to 50 F and days can vary from needing heat, to needing the windows open for a 68 F day, to needing Air Conditioning at 80 F days.

Here is the simplest loop statement I have been able to develop, but I get:

  • Semaphore errors; so I tried to enable Parallelism but then get the Piston is randomly not subscribed error.
  • The forecast function has also been very random, either not getting any value or getting false values randomly as well.

If you have time and any suggestions, they would be appreciated.

Jeff


#4

Hey Jeff,

I think I understand what you’re trying to do now, and it can be done pretty simply in a single piston. I’ll work something up and post it later today so you can see if it’ll work for you - then we can tweak it as needed to get it finished for you.

PS - very jealous you live in CO - I’ve wanted to move out there for a long time!

Cheers,
-Dan


#5

Start with this and build upon it to meet the other conditions you want. There isn’t a need for an “every day at” trigger, or repeat/while loops for what you’re trying to do.

If you have other questions, go ahead and post up! I changed the WEATHER string so it only gets the high temperature for today, too. Your original was grabbing 11 hours ahead… that would certainly throw things off a bit.


#6

Dan,

Well your profile pic is enough to make any guy envious…

If you are ever in Colorado for white water rafting, skiing, or just hanging in the mountains let me know and I will buy the beer.

Appreciate the help.

Jeff


#7

I am going to try to tweak this a little and see how it works.

The problem with this in Colorado is that sometimes you want to use the cool morning temperatures to help cool the house for days that are going to reach the 90s or even start to cool the house early to get ready for that East West Sun exposure. But, sometimes the cool morning temperatures are exactly what you do not want when the high is going to reach 68 F. The 10 hours forecast is being used to prep the house for what lies ahead…Cooling the house to 72 only when it reaches an outside temp of 77 that is going to 90 is a lot of catch up for my A/C system and leaves an inside temp of 76 degrees while it tries to cool. If it can predict a 90 degree day I will force the A/C system to keep it cool and send a SMS text to open the windows to grab that cool morning air. If the forecast is only 68 then I will send a text to keep the windows closed, open those shades and grab that solar heat…The forecast is actually the key to this program.

…Okay I am editing this because I tried this, but this is a one time event…The goal is to maintain a constant temperature with temperature sensor by adjusting the main thermostat…So to maintain a remote sensor at 72 the main thermostat will need to loop between 68 to cool remote thermostat to 72 and 74 to maintain the current 72 remote temp of 72, then when the remote thermostat temp rises it needs to cycle again to 68 to cool the remote to 72 and then return to 74 until needed again to cool.

Jeff


#8

So here is how I loop the remote thermostat by itself with no forecasted condition statements…

But I really do not want to just maintain a temperature in one room…sometimes I want the temperature to get ahead of the very hot day coming, sometimes I want it to change for cool mode to heat mode based on the high of the day…Sometimes, I want it to go into ECO mode and just use the outside air temp…This is all based on the the forecast at 3 pm which is the high usually in Colorado…The process starts at 3 am to take advantage of the cold outside temperatures.


#9

Ok, now the forecast temp makes sense. In that case, I’d just make a single check inside the “once daily at xxx” trigger.

Define variable hotDay (boolean)
Every day at 5am if $weather.forecast.blah.blah.blah.hourly[10] is greater than 77
Then set variable hotDay True
Else set varaible hotDay False

Then by plugging that variable into the rest of your piston, you can see if determine if it’s going to be a day you want to start cooling your house ahead of time.

If that’s clear as mud, let me know and I’ll try to throw together an example. You still don’t need to loop anything for this. :slight_smile:


#10

Thanks Jeff! I wish I got out there more often but with work travel and stuff to do around the house, it’s harder to get out there to blow off steam.

I’ll definitely be out there skiing sometime, and I’ll absolutely take you up on the beer!

Happy to help! :slight_smile:


#11

Read your suggestion a few times…

Not quite sure how to do what your saying and keep the remote sensor looping the thermostat.

If you have an example that I can try I can replicate the rest of the scenarios.

I have been able to control the variance in the remote sensor with the
Piston above.

Thanks again for the help.

Jeff


#12

Ok, let’s try this way… maybe I’m missing something. Why do you want to loop to the thermostat? You’d just be hitting it with the same command repeatedly, no? What are you gaining by looping?

If I can understand that, I can offer an explanation and/or samples to meet what you’re after.


#13

Fair enough…

There is a nest series 2 thermostat that was not designed to have a remote temp sensor…it does what you are thinking; you set a temperature and it maintains it.

A remote temp sensor has to control the dumb thermostat by setting fictitious settings. So a remote temp sensor that is too hot has to send a signal to the dumb thermostat (nest version 2) to set a temperature in which would turn the A/C on (for me it is a temperature of 68 because I never want the rest of the house cooler than 68°)…Once the remote temp sensor no longer needs cool air it has to send a signal to the dumb thermostat to turn off the A/C. I do this by telling the dumb thermostat to turn off by setting a cooling temperature of 74° which is 2° warmer than the desired temperature of the remote temp sensor and it prevents the rest of the house from exceeding 74°.

The loop basically does this by saying IF the remote temp sensor is above 72° THEN when true set the dumb thermostat to cool at 68° when false set the dumb thermostat to 74°…in 1 minute check if the remote temp sensor is below 72° then set the dumb thermostat to 74° when true and when false set dumb thermostat to 68°. Repeat this loop to make sure the remote temp sensor room maintains a temperature of 72° .

Does that make any sense?

If I just set the nest thermostat to a schedule it would maintain the house and not a room temperature…The den is where we spend the most time and would like to keep that temperature constantly comfortable.


#14

Ok, that’s what I thought you were trying to do but I wanted to make sure. There’s still no reason for a loop though - you write your piston so [when you’re using the remote sensor] it will set the A/C to 68° if your remote sensor is warm, and sets it to 74° when your remote sensor is at the desired temp. You only need to send the command to your thermostat once, not repeatedly as long as you want the A/C to run.

The example I posted earlier does that already.

As far as checking the temperature in one minute - you don’t need to do that either. Your remote temperature sensor (in the thn4 code sample I provided) will automatically send an update to SmartThings/webCoRE whenever the temperature changes.

If your sensor reports 73 degrees, it’ll turn your A/C on at 68°. When it cools down a degree, it’ll send 72 to SmartThings/webCoRE and your A/C setting will be changed to 74°. Two simple steps, no loop required.

Make sense?


#15

Is this something like you were thinking?

Thanks

Jeff


#16

Yep now you’re getting closer! I think we can clean it up quite a bit but you’re getting the logic of webCoRE better defined now!

First thing I see is gaps in your hot/med/warm day temp ranges. For example, if the forecasted temp for the day is 74, all your boolean variables will be set false, so none of your steps below would run. Is that the way you want it to be?

Line 154 message content doesn’t jive with the action taken.

I’ll look through this later and see if I can offer up any suggestions.


#17

Cleaned this up a little, I think you can see where it’s going now and customize it the rest how you want. Post up your next attempt and let me know if you have any questions!


#18

My last attempt did not go through…

Do you have a donation sight for all of your hard work?

This morning ran the piston, the hotday Boolean ran true, but the piston is registerering false and not controlling the temp through the remote sensor…just a constant 74 degrees on downstairs thermostat an 80 degrees in Den.

Thanks.

Jeff


#19

Haha, I appreciate it but not necessary!

That’s interesting - especially the 80 on one thermostat since that seems to indicate the piston never sent it anything. Can you turn on logging (full) and post them up here? With those we can figure out where it’s tripping up and fix it.

Edit to add: can you post your piston, too? It’s helpful for me to see it when running through the logs.


#20

On the road right now, will send asap in the next day or two.

Thanks again for helping.

BTW the 80 degrees and climbing was the temp sensor not the controlling thermostat that was set at 74…

How do you send event logs? Just screen capture or is there something fancy that I am missing?

What does it mean when the Piston says false, even though the Boolean hotday says true?

Thanks again.

Jeff