Global variable time value


#1

1) Give a description of the problem
I’ve created a global variable which captures a time in a piston. In a different piston, I want the piston to run when it reaches the global variable time, but it won’t run.

2) What is the expected behaviour?
(PUT YOUR INFO HERE)

3) What is happening/not happening?
The piston won’t run once the global variable time is reached. See the very basic piston and also see the global variable

4) Post a Green Snapshot of the pistonimage
(UPLOAD YOUR IMAGE HERE)

5) Attach logs after turning logging level to Full
(PASTE YOUR LOGS HERE THEN HIGHLIGHT ALL OF THE LOGS AND CLICK ON THE </> ICON TO FORMAT THEM CORRECTLY)

REMOVE BELOW AFTER READING
If a solution is found for your question then please mark the post as the solution.


#2

I forgot to say. So in this case, the value time captured in the global variable is from the piston. I’ve not pre populated this time


#3

A change to a @global time will not be seen by any piston until after that piston runs again.

One workaround for this is to add an empty block to force the piston to run a bit earlier…
(not to do anything, but just to recheck the current @global time)

Something like:

Every day at 4am
    do
End every

(that block is intentionally left blank)


#4

Hi, I’ve not been leaving this for 24 hours but have been forcing the piston by adjusting the global variable. So what I’ve been doing to test this is:

Eg, force the global to capture the time 17:00 but this takes place at 16:45
Then when 17:00 arrives, I would expect my other piston to run.

I’m quite new to WC, am I way off the mark here. Thanks in advance


#5

So, in short, do you mean that the piston needs to run twice before it recognises the global time?


#6

Your piston is only automatically fired when it receives a timer event at a time it has scheduled itself.

When it is first saved it sees it needs to run at the time in the global variable, say 5:00pm, and schedules a timer for that time.

If you then change the global variable to, say, 4:00pm, the piston won’t know about it. It will still fire at 5:00pm. When it does so it will see the global variable has changed and see that it isn’t 4:00pm so it has nothing to do. It will then set the next timer for 4:00pm.

On the other hand if the timer had been set for 5:00pm and the global variable had been changed for 6:00pm, the piston would wake up at 5:00pm and realise it needs to wake up at 6:00pm instead.

So what you need to do is make sure the piston runs between changing the global variable and the new time so it can reschedule. You might be able to do this by having the timer run at a certain time every day and do nothing, as @WCmore illustrated. Just running suffices to reset the timer. Alternatively you can subscribe to changes in the global variable (‘if @sunset_offset_tester changes’) and again do nothing.


#7

can’t you subscribe to the global variable changes?


#8

In many cases, yes.


#9

Thanks to yourself and to @wcmore. Very helpful and makes sense. Appreciated :+1:


#10

@orangebucket many thanks :slightly_smiling_face:


#11

In my experience, as long as the recalculated Global Variable(s) is/are used as triggers (i.e., subscribed) in other pistons, then those pistons will get the Global Variable’s new value immediately. If the global time variable triggers those other pistons, the pistons will run as expected for the next (now rescheduled) run.

@WCmore - is that a correct understanding?


#12

my understanding is no, global variable changes are notified when the piston run that changes them exits

On ST, I think all pistons subscribed to any global variable get notified. On HE, only the pistons subscribed to that global variable change get notified.


#13

OK. I think we agree on this - Global variables are updated only after the piston that calulates them completes and exits. But what I was trying to say above may have been unclear. Saying it longer, here’s what I meant.

I have a Piston that runs at 04:30 every morning. It recalculates @PMOn and @PMOff and then stops. These newly recalculated @PMOn and @PMOff variables are then used as timing triggers for a total of (15) other pistons later in the day. Because those (15) pistons have @PMOn and @PMOFff acting as triggers, they automatically notice the time change to the timing trigger variables @PMOn and @PMOff and then they each run run without doing anything - other than setting the new trigger times.

I know this to be the case because all (15) pistons fire with the new times and because I often see ‘waiting for semaphore’ messages in all or most of the (15) pistons as they all recalculate their new trigger timing at the same time.

So although calculating a Global Variable and using it in the same piston won’t work because the change is unseen until the piston completes, using a seperate recalculation piston with one or more other pistons that use the changed Global Variable(s) as timing trigger(s), will work.

In a nutshell, the key is that the Global Variable recalculation cannot be in the same piston as it is used.


#14

In some cases… yes.

The most common failure is for triggers like:

Every day at @globalTime

will not adjust to a new time until after the piston runs once.
At that time, it sees the new time, and re-schedules accordingly.