A rule that looks something like this should do what you want. The most helpful feature is the ability to use the "variable math" option when setting a variable to assign a random value to it:
Some comments: the scene will effectively be set at some random interval between sunset-15 and sunset+15 (i.e., the total time between the earliest time the delay could be up, which would be immediately after the rule triggers at sunset-15; or the latest the delay could be up, which is 30 minutes; most times, you'll get a value in between those two times). This could be simplified a bit if you want things to happen at the same time every day, but this is one way you can get in the time randomization that it sounds like you wanted.
Them, it checks if HSM is disarmed; if so, the rule exits (i.e., no further actions run). This is a "simple conditional," but you could expand it into a full IF THEN
if you wanted to check for something more complex (i.e., not being armed to any of a few different modes, for example). Since you said you're not using HSM at the moment, you can probably leave this out for now--easy to add in later.
Then, we get to the "random scene" part. The trick here is creating two local variables, one to hold the "scene number, and the other to hold the maximum number of scenes you want, minus one (more on that in a second). In this example, I chose 10--which is actually 11 total since this starts counting at 0. These variables are sceneNumber
and maxSceneNumber
, respectively, but you can call them anything. They should be of type "number." (You actually don't need the maxSceneNumber
variable; you could just use a literal value--the maximum number--instead of this variable on the "Set sceneNumber to random..." line, but I think the intent is clearer if you do it this way. Imagine yourself trying to edit this rule half a year from now.) The "Set sceneNumber to random(maxSceneNumber)line will set the
sceneNumbervariable somewhere between 0 and
maxSceneNumber`, so in my example 0 and 10.
The rest of the rule just checks for the random number, which has now been assigned to the sceneNumber
variable. To activate the CoCoHue scenes, I am calling the "push" command on button 1 (treating them as buttons). You could also use the "Turn on" (treating them as a switch) action, though I generally recommend the former for reasons you may have read about elsewhere by now.
What I didn't include here is how to turn them off. The easiest way is to add another action:
Wait for event: Time is 10:00 PM
Then add another action to turn off the affected lights or groups (or the scene device, though again I would generally not recommend that--all it does is the former, anyway, and the behavior is clearer that way). Perhaps you will want to wrap this "turn off" action after the wait in a conditional so it only happens if HSM is disarmed (or your presence device is not present, or however you want to handle this). Perhaps you want to add another random delay before this to make it happen at not exactly the same time every time as well.
Alternatively, you could just call "Cancel rule timers" on this rule from any rule. For example, you could have another rule that triggers on HSM becoming disarmed (or your presence device becoming present, or again however you want to handle this) and then runs that action on this rule. That will cancel any waits, delays (cancelable or not), and a host of other things, though for this rule that should work. (I'm pretty sure it won't erase the time-based trigger, but I suppose that's worth testing; I know it does affect periodic triggers until the rule is re-initialized.)