HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Help => Topic started by: nolio on April 20, 2014, 02:47:55 PM

Title: Decimal value comparison
Post by: nolio on April 20, 2014, 02:47:55 PM
Hi,

I try a simple automation wizard script :
Code: [Select]
If the temperature is more than 19
Then close shutter
But after some test (value at 19.1) :
1/ Greater than 19 => No close shutter
2/ Equal 19.1 => Shutter close

So my question, is the comparison : "greater than" and "less than" doesn't manage decimal value ?

Bye
Title: Re: Decimal value comparison
Post by: nolio on April 20, 2014, 02:58:14 PM
After a look in the source code, i think i can confirm :) "ComparisonOperator.cs" :
Code: [Select]
.......
    public enum ComparisonOperator
    {
        LessThan = -1,
        Equals = 0,
        GreaterThan = 1
    }
....
Title: Re: Decimal value comparison
Post by: Gene on April 20, 2014, 03:00:44 PM
It manages decimal value:

https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Automation/ProgramEngine.cs#L677

Cheers,
g.
Title: Re: Decimal value comparison
Post by: Gene on April 20, 2014, 03:18:43 PM
I think there might be a bug with parsing "," and "." as decimal separator with different locales.
What locale is set in the hg hosting server?

g.
Title: Re: Decimal value comparison
Post by: nolio on April 20, 2014, 03:44:13 PM
I don't understand why but :

My "locale" :
Code: [Select]
LANG=en_GB.UTF-8
Title: Re: Decimal value comparison
Post by: Gene on April 20, 2014, 03:52:50 PM
Look how the sensor value is store by searching for it in the modules list:

http://192.168.0.2/api/HomeAutomation.HomeGenie/Config/Modules.List (http://192.168.0.2/api/HomeAutomation.HomeGenie/Config/Modules.List)

Does it have a comma separator or a dot one?
Btw... one question... why would you close the shutter on a temperature basis? =D

g.
Title: Re: Decimal value comparison
Post by: nolio on April 20, 2014, 04:22:22 PM
I have dot separator.

I prepare for hot summer, with some parameters (interior+exterior temperature, interior luminance, and alarm on), it will close the shutter to prevent south windows to have so much sun. So it won't be 19 or 18 for interior temperature but probably 25 ;).
Title: Re: Decimal value comparison
Post by: Gene on April 20, 2014, 04:33:47 PM
Cool idea =)
In the meantime I changed some lines of code that should fix the issue.

https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Automation/ProgramEngine.cs#L677

Code: [Select]
                    else if (double.TryParse(parameter.Value, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out dval))
                    {
                        lvalue = dval;
                        rvalue = double.Parse(comparisonValue, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture);
                    }

perhaps with LANG=en_GB.UTF-8 locale, by default double.Parse is looking for comma separator.
Specifying InvariantCulture may fix the bug.
I also remove the surrounding try...catch so that any parsing error will be reported to the UI.

Do you have any chance to recompile and test by yourself? After compiling you've to copy just the HomeGenie.exe file.

g.
Title: Re: Decimal value comparison
Post by: Gene on April 20, 2014, 08:11:43 PM
Hi nolio can you test the fix I posted here:

http://www.homegenie.it/forum/index.php?topic=156.msg843#msg843 (http://www.homegenie.it/forum/index.php?topic=156.msg843#msg843)

it also fixes the Wizard Script values comparison bug.

g.
Title: Re: Decimal value comparison
Post by: nolio on April 20, 2014, 09:48:00 PM
Thank you for compilation.

I try again, but it doesn't work.
I got the following message :
Code: [Select]
Errors:
[{"Line":0,"Column":0,"ErrorMessage":"String was not recognized as a valid DateTime.","ErrorNumber":"-1","CodeBlock":"TC"}]
Program disabled, fix errors first.

Bye
Title: Re: Decimal value comparison
Post by: Gene on April 20, 2014, 10:32:49 PM
My gosh! :) this has never worked since any number was interpreted as a DateTime =/
I switched the two if blocks so that it first tries to parse the value as a number and then, if it fails, it tries to parse the value as a date.
Let me know if this work now. I did a quick test and it worked.

g.

Title: Re: Decimal value comparison
Post by: nolio on April 20, 2014, 11:11:12 PM
Yes, it work fine.
But when i save the script (several times), i have still a pop "Errors" but with nothing else in the popup ... Juste the "close" button :)

Title: Re: Decimal value comparison
Post by: Gene on April 20, 2014, 11:20:57 PM
I think that updating to r366 from the Configure->Maintenance section should fix this too (refresh the browser by pressing F5 after the update).

Cheers,
g.
Title: Re: Decimal value comparison
Post by: nolio on April 21, 2014, 07:05:59 PM
Hi,
Woo. I updated from webUI, but now when i
So i don't really understand :/

Bye
Title: Re: Decimal value comparison
Post by: Gene on April 21, 2014, 07:36:50 PM
If you updated from HG < r364 probably the HomeGenie.exe got overwritten.
So copy the fixed HomeGenie.exe again.
Let me know if it fixes the problem.

g.
Title: Re: Decimal value comparison
Post by: nolio on April 21, 2014, 08:57:37 PM
I try to replace the HomeGenie.exe again and replace the html dir by the one here :
http://www.homegenie.it/forum/index.php?topic=129.75 (http://www.homegenie.it/forum/index.php?topic=129.75)

But it still does the same problem with "save" and "run".
Title: Re: Decimal value comparison
Post by: nolio on April 21, 2014, 09:24:27 PM

woo, this pop-up message doesn't appear again, after a copy of the "html" dir of the zip file to update from r364->r366 (because i erase then whitout backup (not good;))).
So it's probably a trouble

So, no trouble with my running version ...