5) Attach any logs (From ST IDE and by turning logging level to Full)
(PASTE YOUR LOGS HERE BETWEEN THE MARKS THEN HIGHLIGHT ALL OF THE LOGS SND CLICK ON THE </> ICON TO FORMAT THEM)
Try using the trigger āhappens daily atā rather than the condition. āis beforeā is ambiguous. If you want it turning on at a random time between 24-36 minutes before sunset, you will need to use an expression for your offset and generate a random number.
Thanks for the comments. New to webCore. Here is another followup question. Same topic just more specific. Letās say sunrise is at 0800 and I want to turn on a light turned on randomly from 0642 to 0700 (which i think is sunrise -49 +/- 9 minutes). Would someone look at my screen shot and tell me what is wrong with my logic expression.
To output a random integer between 5 and 20 use (5 + random(15))
but thereās an undocumented method that also works and is simpler
random(5,20)
(Note that this does not work with negative numbers ā i.e., random(-5,-20). Not sure why, it just doesnāt.)
Anyway, Iām a little unclear on your precise intent, insofar as your description of what youāre trying to accomplish doesnāt appear to match the numbers or the formula you posted. So Iām just going to provide a couple of examples of the way you might use this.
If Sunrise is at 8:00 AM and you want the light to turn on randomly between 6:42 and 7:00 AM, then the expression -random(60,78) would work as an offset. You will get an offset between -60 and -78 minutes.
If Sunrise is at 8:00 AM and you want the piston to trigger between 6:51 and 7:09. Then you could simply set your offset as -random(51,69) You will get an offset between -51 and -69 minutes.
Again, itās possible I misread your post, so feel free to clarify if necessary.
FWIW, Iāve never been sure whether the wiki needed to updated, or whether this capability was purposely omitted from the wiki for some reason (like it not working with negative numbers).
The wiki says the expression returns āa randomly selected argument if two or more arguments are provided,ā which is a bit of doublespeak and doesnāt really make any sense. But I think it was in part that language, proposing the possible use of two arguments, that made me try this approach way back when.
Maybe @ipaterson knows something about this. Iāve meant to ask, but it was never really all that important.
Very interesting! Given negative numbers rather than returning a negative integer it is returning a - negation operator and a positive integer. The expression evaluator doesnāt know what to do with that and shows undefined and attempting to assign to an integer variable results in 0.
I think the problem here is that the random function is receiving negative integer parameters as expressions rather than values. When called random(-5, -1) it gets two parameters, but they are each represented by parsed expressions ā a pairing of the negation operator and the positive integer:
Since those values are not integers it does the thing it normally does when given text parameters ā chooses one of the parameters randomly and returns it as-is.
This is probably far too core of an issue to consider fixing, high risk of breaking other stuff. If you ever do need to use negative numbers it should be just fine if you store them to variables first.
Thanks for the insight. Now that you mention it, I remember using variables in place of integers successfully in one of my vacation lighting pistons, but itās been a while.
Still oddly fascinated by the language in the wiki that states the function returns āa randomly selected argument if two or more arguments are provided.ā My first thought was that It sounds like something that happens when Iām explaining something to one of the kids.
Yep the docs seem outdated, currently that statement only applies to two non-integer non-decimal arguments (e.g. random('a', 'b') chooses either a or b) or three or more arguments of any type (e.g. random(1, 2, 4) returns either 1, 2, or 4). Seems the docs predate the decimal/integer range random(1, 10)
Thereās no reason to use variables instead as long as your the numbers you put in the random function are positive. The discussion was mostly academic and had less to do with your particular circumstances and more to do with why the function wasnāt working in certain circumstances. Perhaps you would have been better served had we moved that discussion to a separate topic.
However, as you create larger and more complex pistons, using variables can make it much easier to modify your pistonās operating parameters, particularly if those parameters are used multiple times in different parts of the piston.