SWITCH case evaluation


#41

Writing up a response to show you how to step through something like this. This shouldn’t be an issue though as 90 would be above your 32 degree threshold and the setpoint shoud be 45, right?


#42

Ok, I’m seeing the same thing with the initial box:

So we’re going to break the function down and slowly rebuild it so we can see where it goes wrong:
image

By stripping it down to the first layer of the expression, we can see it reports 90 is located at position -1. This is software’s fancy was of saying it doesn’t exist in the array.

This is fine and should be of no consequence for your piston. But it throws the evaluation a curve ball because in a webCoRE array you can also get to the LAST character of an array by using -1. Or the 2nd to last by using -2, etc.

Since our next function, MID, only looks for two things… a starting point and a number of character to return, the -1 value from above makes MID start here:

54,54,53,53,52,52,51,51,50,50,49,49,48,48,47,47,46,46,45,45,45,45

Since it’s starting at the last character, and there’s nothing after it, all the expression returns is the 5. We can replace the indexof stuff with a hardcoded -1 to see the same result:
image

Now for the million dollar question… is your piston actually setting the heat setpoint to 5? Or are you only seeing that when you open up the expression box?


#43

It’s setting the heat point at 5. The thermostat will not go lower than 40 so that’s the end result. Here’s a log of the mayhem.


#44

Ha…I forgot to set Outdoor_Temp to a real value. So the whole piston is getting someplace it should never get to because the previous conditions use the straight value from the weather station. I changed that up as I was finishing it up and just made a mistake. Head slap


#45

Ah, got it! So the IF statements are using your weather station temperature of 29 and working properly, but the expressions we built are still using Outdoor_Temp, which is currently set to 90 in your piston.

First, delete the variable Outdoor_Temp.

Then change your expressions for your Log to Console and Set Heat level from this:

“Set heat to “mid(ITemps,indexOf(OTemps,Outdoor_Temp),2)”.”

to this:

“Set heat to “mid(ITemps,indexOf(OTemps,[Temperature Sensor : temperature]),2)”.”

But change “Temperature Sensor” to the name of your device that is measuring outdoor temps.

Edit to add: looks like you figured it out! But using the method above, you can see how you can pull data from physical devices into expressions now, too. :slight_smile:


#46

LOL, you read my mind. My question was going to be how to embed a value from a device directly into the expression. You answered my question before I asked it. :rofl::rofl::rofl:. Well done sir and thank you!!!


#47

Also, I’m finally diving into the docs on functions and now fully understand everything you’ve done here. For anyone that might stumble across this highly education thread, the link to functions is here. Very useful!! https://wiki.webcore.co/Functions.


#48

I have a headache from all of this…:exploding_head:


#49

Welcome to the wonderful world of coding! LOL