Vacation light help


#1

1) Give a description of the problem
"The “wait randomly between” sunset and midnight isn’t working correctly.

2) What is the expected behavior?
I’m just trying to get a single light to come on once randomly between sunset and midnight, but if I put a random wait of between 1 minute and 400 minutes in 3 months it won’t work.

3) What is happening/not happening?
Can’t get the “random wait” to stay between sunset and midnight.

**4) Post a Green Snapshot


#2

Sunset and midnight are times, not durations… as those times are based on a constant timer going back to 1974(ish), you’ll be waiting a very very long duration lol.


#3

You’re right, it doesn’t work. I’m not sure webCoRE can do what I want. I’ve read the wiki, and hundreds of posts on the matter.

Would you be able Robin, to create a piston, that
Everyday day,
Between sunset +30 and midnight,
Turn a single light on,
Once,
Randomly within that time frame,
For a random amount of time (say 2-5 mins)
That would work the whole year?


#4

Every day at sunset +30
IF
time is before midnight
with light
wait randomly between 0 and {(($sunrise/60000)+30)-($midnight/60000)} minutes
turn on
wait randomly between 2-5 minutes
turn off


#5

Here’s the piston, I’m sure you meant “$sunset” instead of “$sunrise”, but everything else is the same. Now to wait until tonight to see if it works. If it does I’ll click the solution button.


#6

Yep, I meant $sunset

You missed a bracket… should be:

(($sunset/60000)+30)-($midnight/60000)

Not

(($sunset/60000+30)-($midnight/60000))

And if you place this into an expression field you don’t need the {…} brackets… it does that for you (hence why you have double {{…}} brackets)


#7

@Robin it didn’t work :sob: nothing happened as expected, I stayed up until midnight too! Could you see if there’s a typo in the Piston somewhere please? And do I need to turn off TCP per chance? That’s usually been my downfall.

Test TraceTrace Delete »
Logs
02/01/2018, 17:22:59 +107ms
+0ms ╔Received event [Home].time = 1514910180000 with a delay of -894ms
+120ms ║Runtime (39415 bytes) successfully initialized in 63ms (v0.2.101.20171227) (119ms)
+121ms ║╔Execution stage started
+169ms ║╚Execution stage complete. (48ms)
+171ms ║Setting up scheduled job for Wed, Jan 3 2018 @ 5:23:00 PM CET (in 86400.723s)
+177ms ╚Event processed successfully (177ms)
02/01/2018, 12:28:35 +812ms

+1ms ╔Starting piston… (v0.2.101.20171227)
+612ms ║╔Subscribing to devices…
+825ms ║║Subscribing to Z Garden Orange…
+826ms ║╚Finished subscribing (223ms)
+915ms ║Setting up scheduled job for Tue, Jan 2 2018 @ 5:23:00 PM CET (in 17663.273s)
+925ms ╚Piston successfully started (925ms)


#8

Looking at the code above you have sunset - midnight. As midnight is after sunset then wouldn’t it be a larger number, resulting in a negative answer? Maybe midnight - sunset would be better?


#9

I appreciate the reply Si.
Are you saying changing what i had from …

Wait randomly from…
At least 0
At most (($sunset/60000)+30)-($midnight/60000)

Changing to…

Wait Randomly from…
At least 0
At most (($midnight/60000)-($sunset/60000)+30)

that comes up with a value -59040000 in the Expression box.

The first one had a value of 62640000

I’ll give it a go if it’ll work…


#10

You should be getting a much much smaller number (in the 500 range)… the ‘/60000’ should be converting milliseconds (your long number) to minutes… it does when I try that expression???


#11

if i change the Expression from “Minutes” to “Milliseconds” i get a value of 1044
using (($sunset/60000)+30)-($midnight/60000)

Would it work with that? still sounds rather high.


#12

Here’s what I’m getting precisely…


#13

Hmmm… When I tested it yesterday I’m sure it wasn’t doing that… but now it is!!

I think it might be a bug of sorts… changing the attribute between minutes and ms shouldn’t change the calculated value of the expression… but it does!!

@ady624 @ipaterson

Any thoughts?


#14

Ooo you brought the big boys in Robin, hopefully they’ll give us a resolution.


#15

That is currently a known display bug… the value that will be used when the piston runs is what you would expect but the evaluation is displayed incorrectly. The original discussion has a few more examples but there is not a clear-cut way to fix this yet.

Ady and I thought about perhaps having the expression display divided by the appropriate number to show correct units but that has a slew of potential issues. It seems like it will be necessary to pass along some new parameter to identify that the value will be displayed or request the evaluation with a different data type to avoid conversion. This is the third time I’ve seen a post reporting this issue so it might be worth more of my time to find a fix.


#16

Thanks @ipaterson, the good news is i haven’t broken webCoRE, the bad news is this piston isn’t working. All i’m trying to do is randomly turn on a light between Sunset+30 and midnight, for a random amount of time, say 2-5 minutes.
Can you have a look at my piston please and see what i’m doing wrong? Robin suggested to calculate the minutes of Sunset+30 to midnight which sounds good but something in my setup clearly isn’t working.

(($sunset/60000)+30)-($midnight/60000)
any reason why this isn’t working? or can you suggest a better way please.

Here is a copy of the piston with the logs.

Logs
04/01/2018, 06:00:19 +331ms
+8ms ╔Starting piston… (v0.2.101.20171227)
+588ms ║╔Subscribing to devices…
+885ms ║║Subscribing to Z Garden Orange…
+886ms ║╚Finished subscribing (310ms)
+1044ms ║Comparison (time) 25220359 is_before (time) 1515020400000 = false (9ms)
+1106ms ║Setting up scheduled job for Thu, Jan 4 2018 @ 5:25:00 PM CET (in 37479.568s)
+1121ms ╚Piston successfully started (1116ms)
03/01/2018, 16:23:59 +118ms
+1ms ╔Received event [Home].time = 1514996640000 with a delay of -882ms
+160ms ║RunTime Analysis CS > 34ms > PS > 93ms > PE > 33ms > CE
+163ms ║Runtime (39496 bytes) successfully initialized in 93ms (v0.2.101.20171227) (161ms)
+164ms ║╔Execution stage started
+210ms ║║Comparison (time) 62639316 is_before (time) 1514934000000 = false (9ms)
+212ms ║║Condition #9 evaluated false (13ms)
+213ms ║║Condition group #2 evaluated false (state did not change) (15ms)
+216ms ║╚Execution stage complete. (52ms)
+218ms ║Setting up scheduled job for Thu, Jan 4 2018 @ 5:24:00 PM CET (in 86400.665s)
+226ms ╚Event processed successfully (226ms)


#17

This works. Import or modify yours accordingly.


#18

Hi bobbles, yes I tried that one and it didn’t work for me, also 4 variations of it! Nothing happened. And it’s not exactly what i’m looking for, i prefer Robins idea because that fits exactly what i need, i’m hoping andy or ipaterson can help me with this wait randomly from 0 to (($sunset/60000)+30)-($midnight/60000) minutes.

it’s really quite frustrating, not being able to simply randomly turn a light on once, between sunset+30 and midnight for 2-5 minutes. There are no examples of anyone else doing this, at this point i’d even consider Paypalling someone to do this, I’ve been on this nearly a week now.


#19

Will post something for you to try.


#20

How about this. Haven’t tried it but I think it should work.