Variables Not Getting Set Within


#1

1) Give a description of the problem
I want an event to run everyday.

2) What is the expected behavior?
At a specified time everyday, the program assigns variables to turn lights on and off.
The timings change by season in this program.

3) What is happening/not happening?
Outside of the “while” statement which will eventually be triggered at a set time everyday (in the screenshot, it’s an always-true condition for testing), the “IF” statement accurately sets the 4 Time variables.
However, inside of a WHILE or a TIMER, the variables don’t get set, regardless of the state of the “while”

I want to be able to “initiate” the times at 9:30 AM everyday, and then using those times, have the light on/light off events trigger daily.

**4) Post a Green Snapshot of the piston

*5) Attach any logs (From ST IDE and by turning logging level to Full)

3/17/2018, 12:12:18 AM +545ms
+1ms	╔Starting piston... (v0.3.000.20180224)
+155ms	║╔Subscribing to devices...
+287ms	║║Subscribing to Light One...
+288ms	║╚Finished subscribing (137ms)
+313ms	║Comparison (string) 12:12 A.M. is (string) 12:12 A.M. = true (1ms)
+331ms	║Comparison (date) 1521259200000 is_between (date) 1537675200000 .. (date) 1543640400000 = false (4ms)
+353ms	║Comparison (date) 1521259200000 is_between (date) 1543726800000 .. (date) 1521604800000 = true (5ms)
+374ms	║Comparison (date) 1521259200000 is_between (date) 1521691200000 .. (date) 1527825600000 = false (4ms)
+395ms	║Comparison (date) 1521259200000 is_between (date) 1527912000000 .. (date) 1537588800000 = false (6ms)
+409ms	║Comparison (time) 738947 is (time) 0 = false (4ms)
+419ms	║Comparison (time) 738956 is (time) 0 = false (4ms)
+441ms	║Calculating (decimal) 0.0 - (decimal) 2.0 >> (decimal) -2.0
+454ms	║Comparison (time) 7*

#2

Wow… there is soooo much wrong in that piston I don’t know where to start lol.

while $time = $time

This will just flood your system with events, maybe even DDOS.

All you need there is a bunch of IF’s

**While **
(time()) is {timeOn}
OR
(time()) is {timeOn2}

Use:

IF 
$timeNow is {timeOn}
OR
$timNow is {timeOn2}
THEN

And unless you plan to do something different with each light, you don’t need to use for each

just use

with {lights}
turn off

#3

Oh… and your defining the value of the timeOn and timeOn2 variables at the top of the piston, so those variables can never be anything except the set values… if you want to set a variable dynamically you need to leave the variable value as ‘not set’


#4

This might work better for you?


#5

thank you very much for your code and comments above. Just to clarify, I only used time()=time() after I realized something was wrong in the code and I wanted to make sure the code was true at all times, for testin purposes.

While I approached this problem differently in my final solution, I did take some of your edits in the code as well as knowledge on features

And unless you plan to do something different with each light, you don’t need to use for each
to build the final product.
I now have a Piston that runs daily at 9:30 AM that sets a global Time On / Time Off variable. I then have a second simple Piston that turns lights on and off based on those global variables.
While I didn’t realize it at the time, I like this method better because then I can have different events happen on special days… Or also force the light on if accidentally turned off at night… Or force the light off if accidentally turned on in the morning.

Eventually, I think this becomes easier to program with a light sensor instead.

Again, thank you very much, I appreciate the help.