Jump to content

Simple Arithmetic - Help


mmb

Recommended Posts

I wonder if anyone can help me and thanks in advance for any suggestions.

I want to do a simple conversion of Fahrenheit to Celsius but I'm not getting the calculation behavior I expect from the ISY. 

Below is the calculation.  Note I added Notify statements to track progress of the calculation.

285314920_SimpleMath.JPG.256461964e51516acd41742ff8145a37.JPG

The Variable $Temp_Current is defined as an Integer.  I would prefer floating point but it seems it's not available.

The initial Temperature is supplied by a weather service which is retrieved through my Polyglot.  Initially the Temperature is set properly to 15F in both Polyglot and the ISY

When the Program runs the calculation to subtract 32 it results in 15

Then the calculation to multiply by 0.5555 it results in 15

So the final Calculation results in$Temp_Current = 15C which is wrong, it should be -9C (or so)

Any idea where I'm messing up?

Thanks !

 

Link to comment
12 minutes ago, mmb said:

So my arithmetic is fine and it corresponds to your, but the code isn't working.

I'm using v5, but I thought the code was working under v4

Maybe I'm missing something, this should be simple

Thanks!

I'm not following exactly what the input value and output value you are getting are.  However, ISY does not necessarily do sequential steps of a program in order.  The only way to be certain of steps happening in order is to put a "Wait" between them.  Otherwise, all items in the "then" clause are presented for processing simultaneously and the first thing may not be first done.  

So, try putting waits between each step and see what happens.

Link to comment

I put waits but no change.

This is the Program with Input, Calculation and Output with the result of each step

Input

Temperature = 15

Calculation according to ISY

Temp_Current = 0                                ----->result--->  (initialize to 0, not required but did it anyway)

Temp_Current = Temperature            ---->result----> 15  (initialize to current temp and this is correct)

Temp_Current =- 32                            ------>result-----> 15  (15 - 32 should be -17 and is step incorrect)

Temp_Current =* 0.5555                   ------ >result------->15  (-17*0.5555 should be -9 and this step is incorrect)

Output

Temp_Current = 15                             ----> result ------>15  (should be -9)

Not sure how I can make it more clear

Thanks

Link to comment
On 11/6/2019 at 3:33 PM, gviliunas said:

I just tried this under v5.0.16 and it works

Thanks maybe I'll try an update.  Are you running the RC1?

Update 1:

Update didn't help.  I'll delete and recreate the Program

Update 2:

Deleting and Recreating the Program worked - all good

Link to comment

@mmb

On the variables page where you have your Temp_Current defined, right click on the row and select "Change Precision".  I'm pretty sure that's how you change it from "Integer" to a "Floating Point" (even if it's defined on the "Integer" tab! ;) )

You can select from 0 up to 8 digits of precision.  

I think that should fix your problem.

Link to comment
22 minutes ago, Toddimus said:

You can select from 0 up to 8 digits of precision.  

I think that should fix your problem.

That was my thought initially too, so I setup the following program to test what happens if the precision is set to 0.  The program worked perfectly.  Besides, even in theory a precision of 0 wouldn't effect the "-= 32" operation.

Precision Test - [ID 0044][Parent 002B]

If
   - No Conditions - (To add one, press 'Schedule' or 'Condition')
 
Then
        $Temp_Current  = 0
        $Temp_Current  = $Temperature
        $Temp_Current -= 32
        $Temp_Current *= 0.5555
 
Else
   - No Actions - (To add one, press 'Action')

image.thumb.png.b64b6499ba5667c77757c3362c4e5ab1.png

The program above (with both variables being Integer and a precision of 0) gives -9 as the final value in $Temp_Current every time.  I'm using v5.0.15A.

35 minutes ago, mmb said:

Update didn't help.  I'll delete and recreate the Program

Are you judging the programs success by the values you see via the SEND notifications?  I don't know when variables are bound to output, but I'm guessing that's one problem you are seeing.  It would be better if for testing purposes you created your variable as a STATE variable.  Changes in state variables are shown in the Event Viewer.  So you could open the Event Viewer and then run your program and you will see every time your variable changes value.

Also, if you right-click on a program's name, and choose "Copy to Clipboard", you can then paste your program into your messages and we can see it in its entirety.

Link to comment
32 minutes ago, Toddimus said:

@mmb

On the variables page where you have your Temp_Current defined, right click on the row and select "Change Precision".  I'm pretty sure that's how you change it from "Integer" to a "Floating Point" (even if it's defined on the "Integer" tab! ;) )

You can select from 0 up to 8 digits of precision.  

I think that should fix your problem.

That fixed it perfectly - thanks!. 

I think the Variable/Integer tab should be renamed Variable/Numbers - makes more sense

Thanks again!

Link to comment
Just now, mmb said:

That fixed it perfectly - thanks!. 

I think the Variable/Integer tab should be renamed Variable/Numbers - makes more sense

Thanks again!

Because of the post by @kclenden I had to test it out myself too.  One weird thing is that when you manually change a variable on the variables tab, you need to hit enter or it doesn't "stick".

Here's programs that works both ways:

FtoC.png.217bae6a1cdbc59f233e989db50d8a29.pngCtoF.thumb.png.7dbeedb8ba0bc78abb106a1b4ada8647.pngVariables.thumb.png.d0f1ea74b96781367edaeccb16c5784f.png

Link to comment

Just to close the loop on this post, this is the result of the recreated program.  The code is the same but I added Wait 1 sec to be sure.

Btw references to set point is the humidifier control to avoid window sweating - yes, it's that cold and snowy.  (where is the global warming!)

Indoor
Temperature: 20.9 C
Humidity: 27.0 % (Set Point 30%)

Outdoor
Current Temp: -9.2 C (Set Point -5 C)
Forecast Temp: -13.5 C (Set Point -10 C)
Humidity: 53.0 %

Thanks for all the help!

Link to comment
20 minutes ago, Toddimus said:

Because of the post by @kclenden I had to test it out myself too.

What did your testing show?  When the precision was set to 0, did the program work for you as it did for me?  I still have the variables that I setup for the test and they are definitely set to a precision 0 (as my original variable screenshot also shows).  In fact, when I created the variables the precision defaulted to 0 and I never put my cursor in the precision field.

Link to comment
57 minutes ago, Toddimus said:

One weird thing is that when you manually change a variable on the variables tab, you need to hit enter or it doesn't "stick".

I noticed that as well.  A couple of times I went to the Notifications area after creating the variable and I would get the Row/Column reference instead of the Variable name.

Link to comment
2 hours ago, kclenden said:

What did your testing show?  When the precision was set to 0, did the program work for you as it did for me?  I still have the variables that I setup for the test and they are definitely set to a precision 0 (as my original variable screenshot also shows).  In fact, when I created the variables the precision defaulted to 0 and I never put my cursor in the precision field.

Yeah, it did work with precision set to 0 or 1.  When the precision is set to 0, I think it just drops whatever "mantissa" there is, rather than rounding.  So 99.9 would equal 99. 

EDIT: I stand corrected.  See the second set of variables below:

prec0.thumb.png.38e59be47fb1f621cf88d35dcc5d5805.pngprec1.thumb.png.69682b82c494c0589ee68a21d4c1ce6e.png

Precision set to 0 does seem to do rounding:

prec0_rounded.thumb.png.2cf97d24654474f03506af5ee1c5842c.pngprec1_no_rounding.thumb.png.477cc531d86196712539696c3b0cf287.png

Link to comment
2 hours ago, Toddimus said:

Yeah, it did work with precision set to 0 or 1.

Interesting.  I wonder why it didn't work for @mmb with precision set to 0 and then worked when precision was increased.  Wonder if it was actually the change in precision or deleting and then recreating the program that fixed it.

Link to comment
On 11/6/2019 at 9:47 PM, kclenden said:

Interesting.  I wonder why it didn't work for @mmb with precision set to 0 and then worked when precision was increased.  Wonder if it was actually the change in precision or deleting and then recreating the program that fixed it.

I suspect it would work. 

Thanks for the follow up!

Link to comment
27 minutes ago, gviliunas said:

@mmb  I am sorry, I was moving too quickly and forgot to mention that I had set all of the variables used in my test to precision = 1. All of my temperature devices report to 0.1 degree precision so that is what I used in my test. 

No worries, once I knew the feature was there I did some quick playing around with it.  Prior to recreating the Program, changing precision didn't do anything - the arithmetic result was always the same.  After recreating it worked perfectly - both results and precision.  Fortunately this is the only program that had any amount of calculation in it.

I suggested further up that the Integer Tab is misleading and probably more appropriately should be identified as a Numbers tab.

Link to comment
3 minutes ago, mmb said:

No worries, once I knew the feature was there I did some quick playing around with it.  Prior to recreating the Program, changing precision didn't do anything - the arithmetic result was always the same.  After recreating it worked perfectly - both results and precision.  Fortunately this is the only program that had any amount of calculation in it.

I suggested further up that the Integer Tab is misleading and probably more appropriately should be identified as a Numbers tab.

While I did not have any mis-behaving programs during my migration to 5.x firmware, I have seen other people say they had a few programs that needed to be re-created.  I did have some problems, but those programs turned yellow indicating that ISY knew there was a transfer issue allowing me to fix them.

Link to comment
On 11/6/2019 at 1:34 PM, apostolakisl said:

ISY does not necessarily do sequential steps of a program in order.  The only way to be certain of steps happening in order is to put a "Wait" between them.  Otherwise, all items in the "then" clause are presented for processing simultaneously and the first thing may not be first done.  

I've been using ISY and reading this forum for many years and have never known this before.  Could be the source of several issues I've had.  Hmm.

Link to comment
3 minutes ago, carealtor said:

I've been using ISY and reading this forum for many years and have never known this before.  Could be the source of several issues I've had.  Hmm.

This was a topic a very long time ago.  Could be about 7 or 8 years ago.  LeeG who used to be a constant on this forum but for some reason is no longer around pointed it out.  Lee seemed to be someone who was privy to ISY firmware code and was often referenced by Michel for answers.  He clearly was more than just a "user".  The thing is that usually things are executed top to bottom, but it is not guaranteed.  The fact that almost 100% of the time it is top to bottom leads most people to believe that it always is top to bottom.  I do believe at the time we had found some examples of things that ended up not going top to bottom.  As far as I know, ISY code has not changed this behavior in its current iteration.  

Link to comment
1 hour ago, apostolakisl said:

This was a topic a very long time ago.  Could be about 7 or 8 years ago.  LeeG who used to be a constant on this forum but for some reason is no longer around pointed it out.  Lee seemed to be someone who was privy to ISY firmware code and was often referenced by Michel for answers.  He clearly was more than just a "user".  The thing is that usually things are executed top to bottom, but it is not guaranteed.  The fact that almost 100% of the time it is top to bottom leads most people to believe that it always is top to bottom.  I do believe at the time we had found some examples of things that ended up not going top to bottom.  As far as I know, ISY code has not changed this behavior in its current iteration.  

@LeeG was definitely an Insteon bit pattern and logic guru. He is greatly missed here.

Link to comment

So, my problems continue to persist – sorry!

As mentioned, I use a Weather Service to provide the current outdoor temperature in F - currently it's 15.5F

My testing yesterday used a manually inserted 15.5 F in a Program then performed the necessary calculations to get to Celsius which is -9.1 C *this is where I thought things were fixed.

1305136904_ManualSetto15.5.JPG.b1daf2f2aa40941beb080826edafe167.JPG

And the Result

484754903_ManualSetto15.5Result.JPG.4ac7465c01061cdd0020fcc1ce4c0ec9.JPG

Excellent!  *This is where I figured everything was fixed*

However, when I reference the Polyglot / ISY Device variable that the Weather Service provides the calculations stop working.

Below is the correct temperature as displayed in the ISY Devices.

1593594980_WeatherServiceSuppliedTemp15.5.JPG.b36a106532b91a80033957c25a427126.JPG

Below is the Program that converts the Temperature supplied in F to C.  Note the only change in the Program is the first line.

2098951717_WeatherServiceSuppliedTempVariableReference.JPG.10880748bc4b9634deac404456db6ece.JPG

And the Result

977829365_WeatherServiceSuppliedTempResult.JPG.dc8a67b5e75d2d1c855136c690360919.JPG

Seems you can assign the temperature to a variable but then you can't touch it.

Has anyone seen this before?

 

Thanks!

 

Link to comment
52 minutes ago, mmb said:

So, my problems continue to persist – sorry!

As mentioned, I use a Weather Service to provide the current outdoor temperature in F - currently it's 15.5F

My testing yesterday used a manually inserted 15.5 F in a Program then performed the necessary calculations to get to Celsius which is -9.1 C *this is where I thought things were fixed.

1305136904_ManualSetto15.5.JPG.b1daf2f2aa40941beb080826edafe167.JPG

And the Result

484754903_ManualSetto15.5Result.JPG.4ac7465c01061cdd0020fcc1ce4c0ec9.JPG

Excellent!  *This is where I figured everything was fixed*

However, when I reference the Polyglot / ISY Device variable that the Weather Service provides the calculations stop working.

Below is the correct temperature as displayed in the ISY Devices.

1593594980_WeatherServiceSuppliedTemp15.5.JPG.b36a106532b91a80033957c25a427126.JPG

Below is the Program that converts the Temperature supplied in F to C.  Note the only change in the Program is the first line.

2098951717_WeatherServiceSuppliedTempVariableReference.JPG.10880748bc4b9634deac404456db6ece.JPG

And the Result

977829365_WeatherServiceSuppliedTempResult.JPG.dc8a67b5e75d2d1c855136c690360919.JPG

Seems you can assign the temperature to a variable but then you can't touch it.

Has anyone seen this before?

 

Thanks!

 

I never do my calculations in a State variables. You could trigger a dependant downstream program multiple times with nonsense intermediate values. Do the calculation in non-triggering variables and then copy it to the trigger State variable, last. I assume the waits are for testing. They can other programs to inject other values into variables.


You are sending the latest updated variable value and receiving the correct response.. See my first sentence above.

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...