Help determining time of day


#1

Hi all! I’m new to webCoRE and trying to make my way through the immense possibilities it has. One of such things is that I am trying to write a piston to create a global variable that will simply set the time of day as either morning, afternoon, evening, or night.

1) Give a description of the problem
Variable always reports as night

2) What is the expected behaviour?
Variable will change based on the time of the day.

3) What is happening/not happening?
Variable is not changing

**4) Post a Green Snapshot of the piston

5) Attach logs after turning logging level to Full
2/28/2020, 2:33:50 PM +336ms
+1ms ╔Received event [Home].time = 1582929231189 with a delay of -853ms
+89ms ║RunTime Analysis CS > 29ms > PS > 5ms > PE > 55ms > CE
+92ms ║Runtime (40312 bytes) successfully initialized in 5ms (v0.3.110.20191009) (89ms)
+93ms ║╔Execution stage started
+138ms ║║Comparison (datetime) 1582929230438 is_between (datetime) 1582901460000 … (datetime) 1582920000000 = false (5ms)
+141ms ║║Condition #3 evaluated false (38ms)
+142ms ║║Condition group #2 evaluated false (state did not change) (41ms)
+156ms ║║Comparison (datetime) 1582929230483 is_between (datetime) 1582920000000 … (datetime) 1582941060000 = true (4ms)
+158ms ║║Condition #7 evaluated true (13ms)
+159ms ║║Condition group #6 evaluated true (state did not change) (14ms)
+162ms ║║Cancelling statement #8’s schedules…
+167ms ║║Executed virtual command setVariable (1ms)
+184ms ║║Calculating (string) Fri, Feb 28 2020 @ 7:51:00 PM PST + (string) >> (string) Fri, Feb 28 2020 @ 7:51:00 PM PST
+191ms ║║Comparison (datetime) 1582929230509 is_between (datetime) 1582941060000 … (string) Fri, Feb 28 2020 @ 7:51:00 PM PST = false (5ms)
+194ms ║║Condition #11 evaluated false (21ms)
+195ms ║║Condition group #10 evaluated false (state did not change) (24ms)
+209ms ║║Calculating (string) Fri, Feb 28 2020 @ 7:51:00 PM PST + (string) >> (string) Fri, Feb 28 2020 @ 7:51:00 PM PST
+219ms ║║Comparison (datetime) 1582929230536 is_between (string) Fri, Feb 28 2020 @ 7:51:00 PM PST … (datetime) 1582901460000 = true (6ms)
+221ms ║║Condition #15 evaluated true (22ms)
+223ms ║║Condition group #14 evaluated true (state did not change) (25ms)
+226ms ║║Cancelling statement #16’s schedules…
+231ms ║║Executed virtual command setVariable (2ms)
+236ms ║╚Execution stage complete. (144ms)
+238ms ║Setting up scheduled job for Fri, Feb 28 2020 @ 2:48:51 PM PST (in 900.616s)
+247ms ╚Event processed successfully (247ms)

It seems it has something to do with the way it interprets AM and PM, but I don’t know that format the time/date is in when it’s doing the comparison. Do I need to somehow “translate” that @now time to something else first then compare?

Also, as a tangent to this, when I have a piston running in a loop like this, I know I want to be conservative with resources, but I assume these pistons execute remotely and not on the hub itself, correct?

Thanks in advance!!


#2

I would do something like this in a single piston:

Every day at Sunrise (preset)
    Do Set @global to "morning"
END EVERY

Every day at Noon (preset)
    Do Set @global to "afternoon"
END EVERY

Every day at Sunset (preset)
    Do Set @global to "evening"
END EVERY

Every day at Sunset + 2 hours (preset with offset)
    Do Set @global to "night"
END EVERY

Alternatively, you can use specific times, instead of the presets sunrise or sunset.


#3

Sorry, I finally got the image to work. I completely missed the little picture icon to upload it.

As you can hopefully see, I am specifically after the sunrise and sunset times because I’m trying to automate my lights based around sunrise and sunset using this variable.

Thanks!


#4

I would delete the “EVERY 30 MINUTES” portion, and structure using 4 separate IFs as seen in my last post.
(using precise times, instead of a large window)


#5

I just edited my original post to better suit you.


#6

Ah yes, that’s much more simple it seems! Thank you. How can I set an EVERY to day? Do I just set it as 1 day?


#7

Add a new statement (top level) > add a timer


If a visual helps, here is the last block zoomed in…

pic

This portion of the code will execute every day at two hours after sunset…
(a negative offset would happen before sunset)


#8

Sorry, I should have been more clear. I assume that in your example that ‘EVERY DAY’ is just a shortened version of ‘EVERY 1 DAY’?

I wrote the new piston already and figured out the offsetting. This is so much more simple. I was trying to overcomplicate it for sure. I just want to be sure about the every day versus every 1 day.


#9

I do not understand what you mean… Can you post a green snapshot?


My last post results in this code:

pic


#10

Wow. You’re right. I feel silly. I just assumed it would have read out ‘EVERY 1 DAY’ because 1 was the value when creating the ‘EVERY’ statement. However, looking at it after its made, it does in fact say ‘EVERY DAY’

Thanks!


#11

Don’t sweat it… Sometimes I have to remind myself that the pistons we create on the Dashboard, are actually a visual representation of the underlying code…


In the case of popup editing windows, oftentimes the resulting code may change wording slightly after editing.

For example, if the “Every” value is 1, it is displayed as:

pic

If you change the “Every” value to 2, then the display changes to:

pic

… and changing it to 3 makes it:

pic

I think this grammatical change was added to make the code display more “naturally”, but I believe only the numbers (not the grammar) is really stored in the code.


Personally, I think it is seamless, so this is really an extreme compliment to the GUI creator(s)!!
(I sincerely hope they are also a part of the new GUI as well)