02.07.2015, 09:33 (This post was last modified: 02.07.2015, 10:46 by rocfusion.)
Hi,
If you need to know if the current time is equal to an minute offset ( + or - ) of Sunset or Sunrise place these scripts in the Common script. For example, if its 40 minutes before sunrise, you would create a resident script to run every minute.
Code:
123
if( isSunrise(-40, 51.5072, 0.1275) == true) thendoSomething()
end
example 2, if its 30 minutes after then you would use
Code:
123
if( isSunset(30, 51.5072, 0.1275) == true) thendoSomething()
end
And when you need to know if its Sunset or Sunrise then set the offset parameter to 0.
Thank you Roger for the functions. However, when I place the functions in the common functions script after the rscalc function, I get an error message "Lua syntax error at line 109: '=' expected near 'local'". The error corresponds to line 2 in the function. This is probably because the rscalc function takes three arguments in my version of the software (the recent one):
07.07.2015, 16:25 (This post was last modified: 07.07.2015, 16:34 by rocfusion.)
Hi Pontus,
The when is an optional parameter, so you you can then ask for the sunset \ sunrise for next Tuesday. Your rscalc function is different to mine. Here is mine which is from the Feb 2015 release of the firmware.
Thanks Roger, now it works. I have the firmware from february as well, but guess I overwrote the new rscalc with the old one when restoring my config from the backup file...
23.09.2015, 16:30 (This post was last modified: 23.09.2015, 16:34 by Peter.)
Hello guys,
I tried both your scripts, and in both I keep getting an annoying mistake.
In Matts script I keep getting: Lua syntax error at line 111: '=' expected near 'local', see screenshot 1.
I also tried Rogers scripts with his version of rscalc function. In this case I get an error even in the rscalc function itself: Lua syntax error at line 46: '=' expected near 'pi', as in screenshot 2.
Maybe you browser pasted some non-printable characters? Try doing copy/paste via a text editor so it strips unnecessary stuff. If it still does not work then post your whole userlib source including bits that fail during save.
I found the mistake!! If I copy the text from this forum into the script it will remove one space "character" on the very beginning of each line where there should be two of them. So basically every line inside a loop or a condition (if, while, ...). Strange thing is that if I delete the remaining one space it works. Even when I type it back again .