The function AddMinutes is not subtracting minutes from sunset

variables

#1

1) Give a description of the problem
I’m using Robin’s 4mau4 with some minor changes. One is to set evening mode to 120 minutes before sunset using addMinutes with a negative value
2) What is the expected behaviour?
I expected the mode to change 120 minutes before sunset

3) What is happening/not happening?
I created another trigger to text me when the mode changes to Home - Evening. It texted me at exactly sunset

**4) Post a Green Snapshot of the piston![image|45x37]

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

Which part of this piston is not working?

The function works…
(expression) formatDateTime($sunset) »»» (string) Wed, Jul 31 2019 @ 7:27:00 PM MST
(expression) formatDateTime(addMinutes($sunset, -120)) »»» (string) Wed, Jul 31 2019 @ 5:27:00 PM MST


#3

Your variable {eveningTime} is not calculated until after the piston runs. This means, if you recently edited this piston, it might trigger once at the wrong time.

I suspect that variable has simply not synced up yet. If you don’t change anything, I think tomorrow it should trigger within one minute of sunset-120min.

If not, please post a Full log showing the error.


Edit:
I just noticed that you have no code using {eveningTime}.
Perhaps you want to add that trigger down below line 59??


#4

@WCmore eveningTime is used at line 24. The location mode is set at line 33. I’ve been running the piston for a few days. I created the test piston last night.

@eibyer - I don’t know what is not working. As I stated, a different piston testing for the mode change triggers at sunset. Your test clearly show the code should work.


#5

In your picture above, line 24 is {dawnTime}, not {eveningTime}…
temp
The line numbers we see in your green snapshot, will not match what you see when editing.

To point out again, there is absolutely no reference to {eveningTime} anywhere inside piston 3f29o.
(the define section is useless, if it is not referenced in the body of the piston)

If you want a trigger at {eveningTime}, you can add the line:
-OR- Time happens daily at 20 seconds past {eveningTime}
down below line 59. Otherwise, it will never fire at $sunset-120min.


#6

@WCmore, I was off by one line. It’s 23. I can’t cut and paste from the code. Here’s the expression from edit:
($time24 < dawnTime ? ‘Sleep’ : ($time24 < dayTime ? ‘Home - Dawn’ : ($time24 < eveningTime ? ‘Home - Day’ : ($time24 < nightTime ? ‘Home - Evening’ : ($time24 < sleepTime ? ‘Home - Night’ : ‘Sleep’)))))

Are you saying the segment $time24 < eveningTime is not a reference to the variable?


#7

Your wording in the “define” section looks good.

What I mean is, this piston will only trigger when someone comes home, as well as five times a day. (lines 51-59) It is not programmed to run at $sunset-120 minutes.

If you want it to run at $sunset-120min, you can add the line:
-OR- Time happens daily at 20 seconds past {eveningTime}
down below line 59


#8

I just realized the problem: line 55 should be changed to use the variable eveningTime. Line 53 should have used dayTime. Be that as it may, I wrote a new piston that uses an if statement for each case. It’s not nearly as elegant Robin’s original. It is, however, much easier to understand and maintain.