Action X Minutes After an Event?


#1

Hi. I have a virtual (simulated) switch that is turned on when a Lux sensor detects low light levels in the afternoon. The virtual switch gets turned on at random daily times when the light level goes below a defined threshold. The virtual switch turns on several living room lights (in ST) and also kicks off a webCoRE piston automation to randomize the lights.

I’d like to begin the piston randomization of the lights some time after the virtual switch gets turned on.

I’m stumped - how can I get the time the virtual switch turned on, add 30 minutes to that, put that value in a time or date/time variable, and use that variable to start the randomization?


#2

Hi OldPro,

I am not 100% sure what you want to do so I hope I am pointing you to the right direction.

About the WAIT part you can simply add WAIT x minutes.

IF myswitch is ON
Wait 30 minutes
(after that what ever you want here)

For randon, there is a command RANDOM actually.
I have used the RANDOM for an mp3 play list but I haven’t use it for lights but I know its almost the same.

I tried using LUX sensor for lights but i had a serious problem.
Lux sensor doesn’t report the change immidiately and it does not report incrementally.
Meaning :
Let’s say out side is 7000 and you want your lights to turn on below 500.
a) It gets darker and darker and darker and outside is actually 100 now but your sensor is still not reporting.
b) Lets say outside (Cloudy day) went down to 450 for 10 seconds and reported it. Your lights ON now. But 20 seconds later outside is back to 1000. The sensor JUMPS up to 1000. Your lights are On and OFF and ON and OFF again:)))

Please share here if you figured this part already because I would love to go back to that idea for my office lights.


#3

What you say about Lux sensor readings is true. I measure the light in my front yard with a sensor on a window sill. Readings vary all over - big differences day-to-day and big differences within the day. My Aeotec Multisensor 6 reports light level every hour which is good enough. I have it turning the lights on after 1 PM if light is <200 lux. Sometimes the lights go on at 1:10 PM. Other days they go on at 4:30 pm. It depends on the light reading and the time the light is reported. That variability actually helps make the house look more lived in, so the lack of precision doesn’t bother me a bit.

Note that I DO NOT turn the lights off if it gets bright outside again. Once they go on due to low light, they stay on (with randomization). You can see that this has happened several times in the chart below. I figured this is no big deal as it doesn’t happen too often and it mimics real “at home” behavior (i.e., if you are home and turn the lights on when it gets dark, are you going to run around and turn them all off as soon as it brightens a bit outside? Are you going to run around and turn them back on the next time a dark cloud rolls in?)

Here’s a chart of my illuminance data for the past three weeks. The red points indicate when the light is <200 AND after 1 PM (i.e., when the living room lights turned on). I’ve been plotting this to see how the system behaves and if I need to change any parameters.

Here you see how much earlier than sunset the lights were turned on. You can clearly see the difference between bright sunshine days and dark cloudy days:

Date Light on Before Sunset (h:mm)
10-Oct 1:50
11-Oct 2:12
12-Oct 1:35
13-Oct 4:54
14-Oct 2:19
15-Oct 1:42
16-Oct 2:03
17-Oct 1:26
18-Oct 1:48
19-Oct 2:11
20-Oct 1:58
21-Oct 1:56
22-Oct 1:20
23-Oct 4:38
24-Oct 3:04
25-Oct 3:26
26-Oct 3:47
27-Oct 1:12
28-Oct 4:33
29-Oct 3:56
30-Oct 4:19

#4

What was I asking?

It boils down to "how do I set a variable with the date & time 30 minutes AFTER an event occurred? The event in this case is the virtual switch getting turned on.


#5

Here’s my webCoRE logic “code” for randomizing lights starting after the living room gets dark in the afternoon.

The OR clause starts the lighting randomization when:

  1. light is <200 lux after 1 PM (done in ST Smart Lighting) OR
  2. 60 minutes before sunset

That way lighting randomization is assured to occur on bright, sunny days where light never goes below 200 lux.


#6

I would consider this approach:

IF virtual switch stays on for 30 minutes
Then 
    Set variable to $now
    Begin randomization
END IF

I would likely add this to the piston that is already monitoring the virtual switch.

If your virtual switch is already programmed to only turn on after a certain time of day, then you don’t really need any time checks in this block of code. (just make sure some code somewhere is turning off the virtual switch at the end of the day)


#7

Thanks. I think I figured it out. Did a bunch of testing and it works. Will see what happens this afternoon.

I created a new short piston with a global variable to store the date/time of the “Turn On” event for the virtual switch (“Switch 2”).

Then, in the “Vacation 1 - Main” piston, I use that global to determine when the random lighting should start. The OR’d lines will either start randomization 30 minutes after the light gets dim or 60 minutes before sunset:

Clip%202

Finally, at the end of the day, I reset the virtual switch to off (as you pointed out) and set the global to the next midnight. If I didn’t set the global to a future date/time, it would retain the prior value and “Time is after 30 minutes past…” would always evaluate to TRUE, thus always starting the lighting randomization at incorrect times.


#8

Just keep in mind that “Vacation 1 - Main” has to run once before it updates to the new global variable.


#9

Yep. I already set the variable manually to get it started this afternoon. I did that by going into ST / My Home / Thinks and manually turning the virtual switch (Switch 2) on and off. That created the event which executed the code and set the global.


#10

What I mean is, after “Vacation 3 - Low Lux Event” piston runs, it is important to note that your “Vacation 1 - Main” piston will not see the new time until after it runs the next time.

I guess you will be ok though since it runs every 30 minutes anyway. (and will update the global time fairly often) Just keep in mind it may run 30 minutes behind schedule.

I would change the ‘30’ in your highlighted line to say ‘31’ though. Otherwise, it will occasionally miss an event.


#11

Thanks. Good insights there. Getting the timing right on these pistons is quite a challenge.

In this case, the main ST automation turns on four lights in the living room when the room gets dark after 1 pm. So I’ve got four lights on. The piston just starts the randomization of the lights that are already on.

Maybe I should reduce the 30 minutes to zero or 1 minute because I’ve got the potential to randomly stack up multiple delays.

  1. The piston runs every 30 minutes, so it could run 30 minutes after the lights turn on.
  2. The separate piston setting up the global variable which could cause another 30 minute delay.
  3. There is the 30 minute delay line you flagged.

So, in the worst corner case, I think I could have a 3 x 30 = 90 minute delay after the low light condition is reported by the sensor.


#12

Worst case scenario:

Let’s say your lux drops low at 2pm… the global would be set at 2:00:01.
If the “Every 30 minutes” happened to run at 1:59:59, then it would not run again until 2:29:59.
(At which time it would see the new the global variable) It would actually go into the randomization mode you mentioned at 2:59:59.
(not sure where your extra 30 minutes came from. Is your lux code on a timer as well?)

One way to limit the random start time is to simply change the line:
IF Time is after 30 minutes past @global
-to-
IF Time is after @global

This means it would start the random (30-60 minutes) after the global changed.


My two cents? I would avoid this like the plague.


#13

I just realized that my last two posts may be complete nonsense.

All of my global times are used as "triggers", and fit my description above.
I have not tested a global time as a "condition" in quite awhile…

For example, as a trigger, this would never run at the correct time:
temp
unless that same piston also had this code in there to force a time update:
temp

(I actually have the update code in there 3 times a day, every 8 hours, since the moon is always up or down longer than that. The main thing is, I want the time to be updated before the event should occur)

Now that I think about it, in your case, I believe webCoRE will read the global the moment the piston fires up the first time after the change when used as a condition.

(I am leaving my old posts up as a reference for when used as a trigger)

I apologize for any confusion…


#14

Thanks. I’m still trying to learn the intricacies of webCoRE timing including Triggers and Conditions.

Given these possible stacked delays, it probably makes sense to revert to my original approach which avoided the global variable and the “helper” piston to set the global. Instead, I simply read the Virtual Switch state directly:

Clip%204

This original approach eliminates all that needless complexity of storing the Event time to a global variable and delaying execution by X minutes.

I still have the possibility of up to a 30 minute delay from the switch state change because the main piston runs every 30 minutes. Also, the four lights will go on one-by-one as the timers expire and the switch is toggled.

My core ST Smart Lighting logic turns all the table lamps on at 60 minutes before sunset. Then the randomization logic in webCoRE takes over. I used that approach so that local control still works in case the Internet goes down. So there may be a bit of weirdness where the Lux logic starts randomizing lights 2 or 3 hours before sundown, then 1 hour before sundown all four lights go on, then start randomizing again. I don’t think anybody watching from outside would see that, though.


#15

I agree with you… Simplification is good. Personally, I have never put too much faith in randomness to create the illusion of being home… Anyone watching your house that closely is determined to get inside anyways…


#16

Yep. After a while, this just becomes a compulsion to get the programming right. We have a large TV in the living room that can be seen from the street. The big “tells” are that the TV is not going on while we are away. The biggest “tell” is our car is not parked in the driveway. At least I have somebody lined up for snow removal.

I think next up will be putting in a Logitech Harmony to turn the TV on now and then via Z-Wave.

I installed a new security system this summer, too. The old system that came with the house was a decrepit piece of junk with only five monitored doors (nothing on the garage door), no window sensors, and only two motion detectors. I greatly expanded what we are monitoring and that gives much improved peace of mind.

In the end, there’s only so much you can do.


#17

You could always attach a cardboard silhouette to a toy train located near the front window, LOL


#18

But not that one, LOL … that’s just asking for trouble from the stalkers of this world.


#19

LOL, I might not leave the house with that silhouette hanging around. If I don’t leave the house, I won’t need any security system at all, either. So this whole discussion becomes moot!


#20

@WCmore and I were going to work on random lights scenario but we figured my 3 cats are doing a great job randomizing the lights when we are not around LOL

IF coding FAILS
THEN
GET 3 cats.

Free wake up timer, free alexa (Cats won’t understand you so doesn’t Alexa), No down time for the sensors LOL