That looks good, fingers crossed! I’ve already added it, hopefully tomorrow i’ll be able to delete the 7 other pistons i’ve got to try and get this going! i appreciate your effort.
Vacation light help
The only thing I can see wrong is that it will not run the first time until the variable has been set to false at midnight.
You could put in another set var so that you have 2 of them.
Say sunset and midnight set the variables.
This way you guarantee it to run on the day.
i’ve just manually set the boolean variable to “false”, so it should start correctly first time. something else, i’m not sure if its significant or not, on the list of pistons, i have a countdown timer on the right of 10.40.30 (hrs/mins/secs) but sunset is closer to 4 hours away from me, does that matter? my other failing vacation light pistons have at least 04.04.50… correct to when sunset starts.
Its probably set up a schedule for 10hrs time.
This is when the piston will fire and turn the light on I would think.
Time is before midnight
will never evaluate to true, you would need to use Time is before 1 second to midnight
or similar to compare to 11:59:59 rather than 00:00:00
i adjusted the piston you gave me bobbles to include before 2358 instead of midnight.
but it’s still giving me a countdown timer of 10 hours, which is midnight for me, when the piston would end. thinking it was when it would randomly turn on would of been too clever!.
so i varied another piston to be rather than “while time is between sunset and 2358”,
to “executes at sunset plus 30”, and “if time is before 2358” on this one i’m getting a countdown timer of 4 hours which is close to sunset for me.
hopefully something will fire as expected. i have other versions of these pistons with and without the boolean variables to give greater chance of success.
OK…here’s my stab at this… Take a look and see, but I believe this will pass the test.
I’m going outside the lines a little bit…that’s for sure. So I take the value for $sunset and convert that into a 24 hour clock value and then stuff it into an Integer…which I then subtract from 2400 to get the number of minutes between sunset and midnight. Then now that we know the number of minutes, it’s just a simple matter of waiting a random amount of time with that value being the upper limit. If you want to wait 30 minutes after sunset, I’d advise adjusting the lower limit of the Wait. Basically you want the piston to fire every day AT sunset.
Awesome Mike, this looks very cute, and how i would of imagined it looking if i had the necessary amount of grey matter to work with. I’ll be back…
@Alwas
As I was near to sunset here in the UK I thought I would give @Mike1616 version a go as it is certainly a lot cleaner than the way I suggested.
Seems like its working like a charm.
I hate to rain on the parade but subtracting a time in Hmm
format from 2400
will not give you the number of minutes until midnight. Consider 23:59, that math would calculate a difference of 2400-2359
or 41 minutes when it should actually only be 1 minute.
The following should work, datetimes are represented as milliseconds since 1970 so you can subtract them. The only problem is that $midnight
is midnight today rather than tomorrow so you will use $nextMidnight
instead. ($nextMidnight - $sunset) / 60000
will concisely and reliably give you the number of minutes from sunset to the end of the current day.
BIG thank you Mike, you did it. This piston is perfect, it does exactly what i want so i’m very happy indeed. It’s simple, clean, logical and clearly going to work going forward. i like how i can adjust the start time to 30 minutes after sunset, by changing instead of wait from 0 minutes, wait from 30 minutes, so when it’s darker. One question i have, IF i wanted to bring the end time of the piston down, from midnight to say 11pm, how would i adjust ($nextMidnight - $sunset) / 60000 ?
would it be ($nextMidnight-60 - $sunset) / 60000 ?
Well, I certainly can’t take all the credit. There were many great suggestions before I came along. Now my initial answer would have been right…but I forgot to account for the fact that not too many hours have 100 minutes in them.
So, if you want to make it 11:00PM instead of midnight, then no it’s not going to be -60. You’d need to subtract an hour’s worth of milliseconds, since that’s the format that $nextMidnight is using.
So…it’s more like -3600000 (double check my math here…but 60 minutes * 60 seconds per minute * 1000 milliseconds per second). Actually probably triple check my math…that seems to be my downfall.
OK…this works too if you want to have an hour before midnight as the upper limit…and might be easier for others to modify down the line…and hey guess what, very little math needed.
i just started to move my pistons from CoRe to WebCore and also remembered i needed a random light piston for whenever when are on Vacation.
How do i make this piston run ONLY while the ROUTINE is set to VACATION?
THANKS.
i may have found it but correct me if im wrong.
thanks again.
The one issue with that Restriction on a Timer is that they do not evaluate on the fly.
So if you change the Mode in the middle of the day it won’t take effect until the NEXT time the timer resets. So a day later, for example. Or…more likely…the Timer determines that it’s not in “Vacation” mode so it never even sets at all.
There is supposedly a way to get it to reevaluate the Timer by adding in an empty block that would look at the events from Mode changes. Something like “On events from Mode”, and the whole thing would just be blank.
The other way would be to add an IF block just after the Do…
So, every day at Sunset
Do
IF Mode = Vacation
Then do the light stuff
Otherwise do nothing
If you do it that way then it will always evaluate properly changes to the Mode at any time during the day…but it will also always run every day (but not like this is a very tasking piston).
So take your pick…but I don’t think the way you have it right now will work. You need to give the piston the ability to know that the mode changed.
this?
again added the location mode by showing restrictions. im not sure if its the same as “IF Mode = Vacation”. If not, im not sure ive found a way to do it.
thank you for your help again.
I believe you can do it this way, with the restriction, as this will (so I’ve been told, which means untested) cause the piston to check the timer when the Mode changes.