Looking for good examples on how to use List type variables


#1

I have two different applications within one piston that I think using list variables will streamline the coding. This is in my front exterior lighting piston:

Application Inquiry No 1

The first item is in the assignment of lighting colors to individual bulbs. I have 7 hue bulbs across the front of my house and normally they are set to 3100k (100%) in the evening and 2700k (70%) overnight. For holidays, I manually change these to colors in the Hue App. I would like to fold this into my Front Exterior Lighting Piston.

The first item is the actual assignment of colors. Currently, I have 7 variables for light color, one for each light and currently setup like this:

String Lighting_Color_1 = ‘#DD1FF
String Lighting_Color_2 = ‘#DD2FE
String Lighting_Color_3 = ‘#DD3FD

with Front Garage Right do Set Color to {Lighting_Color_1}
with Front Garage Left do Set Color to {Lighting_Color_2}
with Front Porch Light do Set Color to {Lighting_Color_3}

What I would like to see is can I instead make this a single string list type variable called Lighting_Color_Set and set it equal to (#001AB, #002AC, #071FD, etc)? I could then seasonally change this variable manually…or do it automatically (see below). My question is then within the Action statements, how do I retrieve the item in the list?

String Lighting_Color_Set = ‘#DD1FF#DD2FE#DD3FD

with Front Garage Right do Set Color to {Lighting_Color_Set [1]}
with Front Garage Left do Set Color to {Lighting_Color_Set [2]}
with Front Porch Light do Set Color to {Lighting_Color_Set [3]}

Is this the correct syntax and would you all agree this is more streamlined?

Application Inquiry No 2

Same piston (or maybe its own), the actual assignment of the colors in the lighting set, these colors would be assigned by holiday. So I will need a string variable for holiday (ie “Christmas”, “Mardi Gras”, “Valentines”, “Easter”, “Flag Day”, “Halloween” and then “Normal”).

String Home_Holiday = “Normal” (perhaps this needs to be global, “normal” by default)
If Time Happens Daily at $midnight (trigger)
If Date is between 01/01/2018 and 01/05/2018 Then Set @Home_Holiday as “Christmas”
If Date is between 01/06/2018 and 02/13/2018 Then Set @Home_Holiday as “Mardi Gras”
If Date is 02/14/2018 Then Set @Home_Holiday as “Valentines”
If Date is between 02/15/2018 and XXXX Then Set @Home_Holiday as “Mardi Gras” (most years spans past Valentines, just not this year)
If Date is between 03/30/2018 and 04/01/2018 Then “Easter”
If Date is 05/28/2018 Then “Flag Day” (memorial day, same color theme)
If Date is 06/14/2018 Then “Flag Day”
If Date is 07/04/2018 Then “Flag Day” (independence day, same color theme)
If Date is between 10/01/2018 and 10/31/2018 Then “Halloween”

My thinking here was instead of having nine different If Then Else ElseIf End statements, I could some how simplify this with two lists fields. The first list would be the first calendar day of a holiday and the second list would be the name of the holiday. I would use the current day to return the list position and this use that list position to obtain the holiday name and assign the variable. I can do this very easily in Excel, but no idea how to here. Indexing exact dates would be easy, the question becomes how do I poll/index 12/5/2018, which is clearly falls in Christmas. I would need to search the list with an “approximate match” or last date less than current value some kind of way.

Any ideas?

The color string list above would then be populated based on the holiday variable.

And finally, the reason I want to assign a holiday variable based on date, then separately assign the light colors based on the holiday variable is to just organize the piston for annual updates to change the dates since Mardi Gras and Easter float. I don’t have to go through all the color assignments to update these dates. Then if I ever want to tweak the colors, those are all in their own section, instead of mixed in with date assignments.

As stated before, I may do this in its own separate piston and create the variable globally - I just prefer not to as they wont be used anywhere else in my house.

Thanks!


#2

Nr 1

Define
Device deviceList: x,y,z
String colorList: red,blue,green

execute
For each $device in deviceList
set color to colorList[$index]

This will set x to red, y to blue, z to green

Referencing:

colorList[0] will return red
colorList[1] will return blue
colorList[2] will return green


#3

Nr 2

Just use a series of timers

Every year on the 1st day of January
DO
set @Holiday to Christmas

Every year on the 6th day of January
DO
set @Holiday to Mardi Gras

Etc etc.


#4

I like this option and it streamlines a lot…except that I do not see a DeviceList type variable to set…


#5

Never mind, lol, I got ahead of myself.


#6

Sorry @Robin but Im just not getting there tonight. Below is the current code and full logs.

What is happening:
I have added two GE switches as an ‘or’ condition to the timed conditions for debugging. I have a timed event at my Evening Time that turns all lights on to 100% and sets the color temperature to 3100K. I then have an event at my Evening Time +1 that then attempts to set the device list to the color list. I tried to follow your recommendation as best as I could. I could not get to “For each…”, I just can’t find it.

According to the logs, what ends up happening is all the lights in the device list are assigned to black. It seems each device is being executed properly, but the color assignments are not working. I have tried with color names and with color hex strings. Same result.

I appreciate any guidance.

Logs
1/23/2018, 11:06:26 PM +213ms
+1ms ╔Received event [Foyer Switch A].switch = on with a delay of 225ms
+98ms ║RunTime Analysis CS > 21ms > PS > 35ms > PE > 42ms > CE
+100ms ║Runtime (44376 bytes) successfully initialized in 35ms (v0.2.102.20180116) (99ms)
+101ms ║╔Execution stage started
+110ms ║║Comparison (time) 83186320 happens_daily_at (time) 62940000 = false (0ms)
+111ms ║║Condition #44 evaluated false (5ms)
+112ms ║║Cancelling statement #44’s schedules…
+116ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 5:29:00 PM CST
+124ms ║║Cancelling condition #45’s schedules…
+125ms ║║Condition #45 evaluated false (7ms)
+126ms ║║Cancelling condition #38’s schedules…
+127ms ║║Condition group #38 evaluated false (state changed) (21ms)
+133ms ║║Comparison (time) 83186343 happens_daily_at (time) 62940000 = false (1ms)
+134ms ║║Condition #11 evaluated false (4ms)
+135ms ║║Cancelling statement #11’s schedules…
+139ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 5:30:00 PM CST
+145ms ║║Comparison (enum) on changes_to (string) on = true (0ms)
+146ms ║║Cancelling condition #37’s schedules…
+147ms ║║Condition #37 evaluated true (6ms)
+148ms ║║Cancelling condition #1’s schedules…
+149ms ║║Condition group #1 evaluated true (state changed) (19ms)
+151ms ║║Cancelling statement #2’s schedules…
+236ms ║║Calculating (string) red,orange,yellow,green,blue,purple,pink + (string) Empty device list >> (string) red,orange,yellow,green,blue,purple,pinkEmpty device list
+246ms ║║Executed physical command [Front Brick Wall].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (6ms)
+247ms ║║Executed [Front Brick Wall].setColor (8ms)
+254ms ║║Executed physical command [Front Dining Window].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (5ms)
+255ms ║║Executed [Front Dining Window].setColor (7ms)
+262ms ║║Executed physical command [Front Garage Left].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (5ms)
+262ms ║║Executed [Front Garage Left].setColor (6ms)
+270ms ║║Executed physical command [Front Garage Right].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (5ms)
+270ms ║║Executed [Front Garage Right].setColor (6ms)
+277ms ║║Executed physical command [Front Living Window].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (4ms)
+278ms ║║Executed [Front Living Window].setColor (6ms)
+286ms ║║Executed physical command [Front Porch Light].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (5ms)
+287ms ║║Executed [Front Porch Light].setColor (7ms)
+294ms ║║Executed physical command [Front Wall Lamp].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (5ms)
+294ms ║║Executed [Front Wall Lamp].setColor (6ms)
+301ms ║║Comparison (time) 83186511 happens_daily_at (time) 84600000 = false (0ms)
+302ms ║║Condition #30 evaluated false (4ms)
+304ms ║║Cancelling statement #30’s schedules…
+308ms ║║Requesting time schedule wake up at Tue, Jan 23 2018 @ 11:30:00 PM CST
+310ms ║║Condition group #24 evaluated false (state did not change) (13ms)
+316ms ║║Comparison (time) 83186526 happens_daily_at (time) 24960000 = false (0ms)
+317ms ║║Condition #34 evaluated false (4ms)
+319ms ║║Cancelling statement #34’s schedules…
+323ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 6:56:00 AM CST
+325ms ║║Condition group #31 evaluated false (state did not change) (13ms)
+330ms ║╚Execution stage complete. (229ms)
+333ms ║Setting up scheduled job for Tue, Jan 23 2018 @ 11:30:00 PM CST (in 1413.455s), with 3 more jobs pending
+342ms ╚Event processed successfully (342ms)
1/23/2018, 11:06:17 PM +929ms
+1ms ╔Received event [Foyer Switch B].switch = on with a delay of 230ms
+158ms ║RunTime Analysis CS > 17ms > PS > 74ms > PE > 68ms > CE
+161ms ║Runtime (44380 bytes) successfully initialized in 74ms (v0.2.102.20180116) (159ms)
+162ms ║╔Execution stage started
+170ms ║║Comparison (time) 83178096 happens_daily_at (time) 62940000 = false (0ms)
+172ms ║║Condition #44 evaluated false (5ms)
+173ms ║║Cancelling statement #44’s schedules…
+178ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 5:29:00 PM CST
+183ms ║║Comparison (enum) on changes_to (string) on = true (1ms)
+185ms ║║Cancelling condition #45’s schedules…
+186ms ║║Condition #45 evaluated true (5ms)
+187ms ║║Cancelling condition #38’s schedules…
+187ms ║║Condition group #38 evaluated true (state changed) (20ms)
+190ms ║║Cancelling statement #39’s schedules…
+210ms ║║Executed physical command [Front Brick Wall].setLevel([100]) (12ms)
+210ms ║║Executed [Front Brick Wall].setLevel (14ms)
+225ms ║║Executed physical command [Front Dining Window].setLevel([100]) (12ms)
+226ms ║║Executed [Front Dining Window].setLevel (13ms)
+241ms ║║Executed physical command [Front Garage Left].setLevel([100]) (12ms)
+242ms ║║Executed [Front Garage Left].setLevel (14ms)
+257ms ║║Executed physical command [Front Garage Right].setLevel([100]) (12ms)
+257ms ║║Executed [Front Garage Right].setLevel (13ms)
+271ms ║║Executed physical command [Front Living Window].setLevel([100]) (11ms)
+272ms ║║Executed [Front Living Window].setLevel (12ms)
+286ms ║║Executed physical command [Front Porch Light].setLevel([100]) (12ms)
+287ms ║║Executed [Front Porch Light].setLevel (12ms)
+301ms ║║Executed physical command [Front Wall Lamp].setLevel([100]) (12ms)
+302ms ║║Executed [Front Wall Lamp].setLevel (12ms)
+310ms ║║Executed physical command [Front Brick Wall].setColorTemperature([3100]) (5ms)
+310ms ║║Executed [Front Brick Wall].setColorTemperature (6ms)
+317ms ║║Executed physical command [Front Dining Window].setColorTemperature([3100]) (6ms)
+317ms ║║Executed [Front Dining Window].setColorTemperature (6ms)
+324ms ║║Executed physical command [Front Garage Left].setColorTemperature([3100]) (5ms)
+324ms ║║Executed [Front Garage Left].setColorTemperature (6ms)
+331ms ║║Executed physical command [Front Garage Right].setColorTemperature([3100]) (5ms)
+332ms ║║Executed [Front Garage Right].setColorTemperature (7ms)
+338ms ║║Executed physical command [Front Living Window].setColorTemperature([3100]) (5ms)
+339ms ║║Executed [Front Living Window].setColorTemperature (7ms)
+345ms ║║Executed physical command [Front Porch Light].setColorTemperature([3100]) (5ms)
+346ms ║║Executed [Front Porch Light].setColorTemperature (7ms)
+352ms ║║Executed physical command [Front Wall Lamp].setColorTemperature([3100]) (5ms)
+353ms ║║Executed [Front Wall Lamp].setColorTemperature (7ms)
+355ms ║║Cancelling statement #42’s schedules…
+363ms ║║Skipped execution of physical command [Front Garden Lighting].on([]) because it would make no change to the device. (4ms)
+363ms ║║Executed [Front Garden Lighting].on (4ms)
+368ms ║║Skipped execution of physical command [Sideyard Garage Light].on([]) because it would make no change to the device. (2ms)
+369ms ║║Executed [Sideyard Garage Light].on (3ms)
+376ms ║║Comparison (time) 83178301 happens_daily_at (time) 62940000 = false (0ms)
+377ms ║║Condition #11 evaluated false (5ms)
+378ms ║║Cancelling statement #11’s schedules…
+382ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 5:30:00 PM CST
+390ms ║║Condition #37 evaluated false (6ms)
+391ms ║║Condition group #1 evaluated false (state did not change) (19ms)
+397ms ║║Comparison (time) 83178323 happens_daily_at (time) 84600000 = false (0ms)
+398ms ║║Condition #30 evaluated false (4ms)
+400ms ║║Cancelling statement #30’s schedules…
+404ms ║║Requesting time schedule wake up at Tue, Jan 23 2018 @ 11:30:00 PM CST
+406ms ║║Condition group #24 evaluated false (state did not change) (12ms)
+412ms ║║Comparison (time) 83178338 happens_daily_at (time) 24960000 = false (1ms)
+413ms ║║Condition #34 evaluated false (4ms)
+414ms ║║Cancelling statement #34’s schedules…
+419ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 6:56:00 AM CST
+421ms ║║Condition group #31 evaluated false (state did not change) (13ms)
+426ms ║╚Execution stage complete. (265ms)
+428ms ║Setting up scheduled job for Tue, Jan 23 2018 @ 11:30:00 PM CST (in 1421.643s), with 3 more jobs pending
+438ms ╚Event processed successfully (438ms)
Clear Full


Light On Using Color Or Color Temperature
#7

I have done some more playing around with this, including manually stacking the string list by individual index and debugging the values out. It seems no matter how I define the string, I get Front_Light_Colors[0] returns Null. This is for all indices. I have defined the variable as a string and set it equal to a list and I have set the variable as a string list and set it equal one index at a time. This seems to be the source of the issue. All other aspects appear to work fine.

What could I be missing???


#8

Index doesent exist in a regular statement.

You need to turn on advanced statements in settings and then use a ‘for each loop’.

Each loop has an $index, starting at 0

For each light in front_light_devices
Set color to Front_Light_Colors[$index]


#9

Here is where I am this morning. I found the advanced settings and added the Index variable last night. More or less same log, just added some debug lines to help figure it out. List still returns Null.

Logs
1/24/2018, 7:27:28 AM +656ms
+1ms ╔Received event [Foyer Switch A].switch = on with a delay of 991ms
+92ms ║RunTime Analysis CS > 11ms > PS > 35ms > PE > 46ms > CE
+95ms ║Runtime (45585 bytes) successfully initialized in 35ms (v0.2.102.20180116) (93ms)
+96ms ║╔Execution stage started
+107ms ║║Comparison (time) 26848757 happens_daily_at (time) 63000000 = false (3ms)
+109ms ║║Condition #44 evaluated false (8ms)
+110ms ║║Cancelling statement #44’s schedules…
+115ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 5:30:00 PM CST
+123ms ║║Condition #45 evaluated false (6ms)
+124ms ║║Condition group #38 evaluated false (state did not change) (23ms)
+130ms ║║Comparison (time) 26848783 happens_daily_at (time) 63000000 = false (1ms)
+131ms ║║Condition #11 evaluated false (5ms)
+132ms ║║Cancelling statement #11’s schedules…
+136ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 5:31:00 PM CST
+142ms ║║Comparison (enum) on changes_to (string) on = true (1ms)
+143ms ║║Cancelling condition #37’s schedules…
+144ms ║║Condition #37 evaluated true (6ms)
+145ms ║║Cancelling condition #1’s schedules…
+146ms ║║Condition group #1 evaluated true (state changed) (19ms)
+149ms ║║Cancelling statement #52’s schedules…
+155ms ║║Executed virtual command setVariable (3ms)
+165ms ║║null
+166ms ║║Executed virtual command log (6ms)
+176ms ║║Cancelling statement #55’s schedules…
+183ms ║║0
+184ms ║║Executed virtual command [Front Brick Wall].log (1ms)
+190ms ║║Front Brick Wall
+190ms ║║Executed virtual command [Front Brick Wall].log (1ms)
+196ms ║║null
+197ms ║║Executed virtual command [Front Brick Wall].log (1ms)
+211ms ║║Executed physical command [Front Brick Wall].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (7ms)
+212ms ║║Executed [Front Brick Wall].setColor (11ms)
+221ms ║║Cancelling statement #55’s schedules…
+228ms ║║1
+229ms ║║Executed virtual command [Front Dining Window].log (1ms)
+235ms ║║Front Dining Window
+235ms ║║Executed virtual command [Front Dining Window].log (1ms)
+241ms ║║null
+242ms ║║Executed virtual command [Front Dining Window].log (1ms)
+252ms ║║Executed physical command [Front Dining Window].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (6ms)
+253ms ║║Executed [Front Dining Window].setColor (7ms)
+262ms ║║Cancelling statement #55’s schedules…
+269ms ║║2
+270ms ║║Executed virtual command [Front Garage Left].log (1ms)
+275ms ║║Front Garage Left
+276ms ║║Executed virtual command [Front Garage Left].log (1ms)
+282ms ║║null
+283ms ║║Executed virtual command [Front Garage Left].log (1ms)
+292ms ║║Executed physical command [Front Garage Left].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (5ms)
+293ms ║║Executed [Front Garage Left].setColor (7ms)
+302ms ║║Cancelling statement #55’s schedules…
+310ms ║║3
+310ms ║║Executed virtual command [Front Garage Right].log (1ms)
+316ms ║║Front Garage Right
+317ms ║║Executed virtual command [Front Garage Right].log (1ms)
+323ms ║║null
+324ms ║║Executed virtual command [Front Garage Right].log (1ms)
+334ms ║║Executed physical command [Front Garage Right].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (5ms)
+334ms ║║Executed [Front Garage Right].setColor (8ms)
+344ms ║║Cancelling statement #55’s schedules…
+351ms ║║4
+352ms ║║Executed virtual command [Front Living Window].log (1ms)
+358ms ║║Front Living Window
+358ms ║║Executed virtual command [Front Living Window].log (1ms)
+367ms ║║null
+367ms ║║Executed virtual command [Front Living Window].log (3ms)
+377ms ║║Executed physical command [Front Living Window].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (6ms)
+378ms ║║Executed [Front Living Window].setColor (8ms)
+387ms ║║Cancelling statement #55’s schedules…
+397ms ║║5
+397ms ║║Executed virtual command [Front Porch Light].log (2ms)
+404ms ║║Front Porch Light
+404ms ║║Executed virtual command [Front Porch Light].log (1ms)
+411ms ║║null
+412ms ║║Executed virtual command [Front Porch Light].log (1ms)
+421ms ║║Executed physical command [Front Porch Light].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (5ms)
+422ms ║║Executed [Front Porch Light].setColor (8ms)
+432ms ║║Cancelling statement #55’s schedules…
+439ms ║║6
+440ms ║║Executed virtual command [Front Wall Lamp].log (1ms)
+446ms ║║Front Wall Lamp
+447ms ║║Executed virtual command [Front Wall Lamp].log (1ms)
+453ms ║║null
+454ms ║║Executed virtual command [Front Wall Lamp].log (2ms)
+463ms ║║Executed physical command [Front Wall Lamp].setColor([[hex: #000000, hue:0, saturation:0, level:0]]) (4ms)
+464ms ║║Executed [Front Wall Lamp].setColor (6ms)
+471ms ║║Comparison (time) 26849124 happens_daily_at (time) 84600000 = false (0ms)
+473ms ║║Condition #30 evaluated false (4ms)
+474ms ║║Cancelling statement #30’s schedules…
+478ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 11:30:00 PM CST
+481ms ║║Condition group #24 evaluated false (state did not change) (13ms)
+487ms ║║Comparison (time) 26849139 happens_daily_at (time) 24960000 = false (0ms)
+488ms ║║Condition #34 evaluated false (5ms)
+489ms ║║Cancelling statement #34’s schedules…
+494ms ║║Requesting time schedule wake up at Thu, Jan 25 2018 @ 6:56:00 AM CST
+496ms ║║Condition group #31 evaluated false (state did not change) (13ms)
+502ms ║╚Execution stage complete. (406ms)
+505ms ║Setting up scheduled job for Wed, Jan 24 2018 @ 5:30:00 PM CST (in 36150.839s), with 3 more jobs pending
+514ms ╚Event processed successfully (514ms)
1/24/2018, 7:27:23 AM +416ms
+1ms ╔Received event [Foyer Switch A].switch = off with a delay of 1009ms
+142ms ║RunTime Analysis CS > 16ms > PS > 52ms > PE > 74ms > CE
+144ms ║Runtime (45584 bytes) successfully initialized in 52ms (v0.2.102.20180116) (142ms)
+145ms ║╔Execution stage started
+156ms ║║Comparison (time) 26843566 happens_daily_at (time) 63000000 = false (3ms)
+157ms ║║Condition #44 evaluated false (7ms)
+158ms ║║Cancelling statement #44’s schedules…
+163ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 5:30:00 PM CST
+171ms ║║Condition #45 evaluated false (6ms)
+172ms ║║Condition group #38 evaluated false (state did not change) (22ms)
+178ms ║║Comparison (time) 26843591 happens_daily_at (time) 63000000 = false (1ms)
+179ms ║║Condition #11 evaluated false (4ms)
+180ms ║║Cancelling statement #11’s schedules…
+184ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 5:31:00 PM CST
+190ms ║║Comparison (enum) off changes_to (string) on = false (0ms)
+191ms ║║Condition #37 evaluated false (5ms)
+192ms ║║Condition group #1 evaluated false (state did not change) (18ms)
+198ms ║║Comparison (time) 26843611 happens_daily_at (time) 84600000 = false (1ms)
+199ms ║║Condition #30 evaluated false (4ms)
+200ms ║║Cancelling statement #30’s schedules…
+204ms ║║Requesting time schedule wake up at Wed, Jan 24 2018 @ 11:30:00 PM CST
+206ms ║║Condition group #24 evaluated false (state did not change) (12ms)
+212ms ║║Comparison (time) 26843625 happens_daily_at (time) 24960000 = false (0ms)
+213ms ║║Condition #34 evaluated false (4ms)
+214ms ║║Cancelling statement #34’s schedules…
+218ms ║║Requesting time schedule wake up at Thu, Jan 25 2018 @ 6:56:00 AM CST
+220ms ║║Condition group #31 evaluated false (state did not change) (12ms)
+224ms ║╚Execution stage complete. (79ms)
+227ms ║Setting up scheduled job for Wed, Jan 24 2018 @ 5:30:00 PM CST (in 36156.358s), with 3 more jobs pending
+236ms ╚Event processed successfully (236ms)


#10

your color list appears to be empty?


#11

Exactly. So Im either not defining it correctly or Im not stacking it correctly. One thing I noticed is that once I define variable as a String List, I can no longer set a default value to it.

In the latest code, I specifically defined it null and then loaded three values into it using the [0] designation and it still returns null. I’m beaten down on this one.

Is it possible that the $Index variable in a decimal and not an integer is causing a problem. There are a few threads on here regarding that issue but this was allegedly corrected in a WebCore version older than what I am using. Is there a command in WebCore that I can convert a decimal variable into an integer to test this out?


#12

Specifically lines 50 and 51, I try to load a “red” value into the string list and then retrieve it with a debug command, but the debug command returns a ‘0’.


#13

Don’t bother with the string list variable… just use string and populate it with one long string of comma separated values


#14

I tried that too with the same result. I will give it a go again tonight to check for sanity.

Separate question. I am currently at work and I have access to Webcore, so I can change the code now. Is there a way for me to test this not being at home?


#15

you would need to setup simulated devices… but you probably shouldn’t be broadcasting that you’re working on webcoRE at work haha


#16

On testing… I seem to be having issues with variableName[$index] as well… returns an error ‘empty device list’ on evaluation. variableName[0] is returning error ‘invalid device variable 0’

I’m sure this used to work!!

Luckily webCoRE gives us multiple routes of attack :slight_smile:

try - set color to {arrayItem($index, Front_Light_Colors)}


#17

eh hmm…I work at home, just in the back lol.

That’s exactly the error I was receiving. When I added the debug statements, it was returning null…which interestingly defaults to a black color light (I would have guessed white or all LED’s on).

I will check out the array command - to me that makes more sense as I could not understand how WebCore would “know” the string was a list/array if it was not defined as one.

I have a very (very) minor background in Fortran programming and Microsoft Access Visual Basic programming LOL. I understand the concepts but I need to learn the modern languages.


#18

Holy Array Batman it worked!
Thanks. Let me tweak it and add the holiday schedule. I may tweak a few things, document it better and share it.


#19

Ok,

Now on to stage 2, I am running into issues with the holiday schedule. I did decide to put this in its own piston to run every night at midnight. The piston sets a few global time variables I setup so was a natural placement for this one.

I defined a variable @home_holiday and set it to “normal”. The I use a series if If conditions to evaluate the variable $date between other date sets to determine if the variable should be changed. I went with this approach because the “Every year on the xxx…” approach would have required me to list every individual date. I am running into two problems.

First problem, I can not set ‘Values’ to date variables. Once I define a variable as a date, the only value it will accept is today’s date and the field is not editable. This applies to local variables and global variables. My goal was to setup date variable and assign the dates on the front end of the piston so they could all be changed in one location at the start of each year…until I automate that as well. So, my conditional statements all have the dates hard coded. Rather disappointing but I am hoping you know a fix.

Second problem, using the conditional statement "If Date is between XXX and YYY, what is the specific date format I need for XXX and YYY. I have tried several formats and cannot get there. Using ‘Feb 14, 2018’ formatted dates resulted in today flag day. Using ‘2018-Feb-14’ formatted dates resulted in today being null.

And the log from this morning’s run - sorry I did not get a chance to put in some debug statements as I am curious as to which flag day criteria triggered the ‘TRUE’ condition.

Logs:
1/24/2018, 11:59:59 PM +103ms
+0ms ╔Received event [Mystic’s House].time = 1516860000000 with a delay of -898ms
+127ms ║RunTime Analysis CS > 16ms > PS > 53ms > PE > 58ms > CE
+131ms ║Runtime (49116 bytes) successfully initialized in 53ms (v0.2.102.20180116) (129ms)
+132ms ║╔Execution stage started
+154ms ║║Comparison (time) 86399245 happens_daily_at (datetime) 1516773600000 = true (6ms)
+155ms ║║Time restriction check passed
+157ms ║║Cancelling condition #8’s schedules…
+158ms ║║Condition #8 evaluated true (16ms)
+160ms ║║Cancelling statement #8’s schedules…
+166ms ║║Requesting time schedule wake up at Fri, Jan 26 2018 @ 12:00:00 AM CST
+170ms ║║Cancelling condition #1’s schedules…
+171ms ║║Condition group #1 evaluated true (state changed) (30ms)
+175ms ║║Cancelling statement #2’s schedules…
+205ms ║║Executed virtual command setVariable (2ms)
+209ms ║║Executed virtual command setVariable (1ms)
+213ms ║║Executed virtual command setVariable (1ms)
+224ms ║║Executed virtual command setVariable (2ms)
+229ms ║║Executed virtual command setVariable (2ms)
+233ms ║║Executed virtual command setVariable (1ms)
+239ms ║║Executed virtual command setVariable (2ms)
+261ms ║║Calculating (string) Jan 01, + (string) 2018 >> (string) Jan 01, 2018
+265ms ║║Calculating (string) Jan 01, 2018 + (string) >> (string) Jan 01, 2018
+273ms ║║Calculating (string) Jan 05, + (string) 2018 >> (string) Jan 05, 2018
+276ms ║║Calculating (string) Jan 05, 2018 + (string) >> (string) Jan 05, 2018
+286ms ║║Comparison (date) 1516773600000 is_between (string) Jan 01, 2018 … (string) Jan 05, 2018 = false (8ms)
+288ms ║║Condition #14 evaluated false (45ms)
+298ms ║║Calculating (string) Dec 01 + (string) 2018 >> (string) Dec 01 2018
+300ms ║║Calculating (string) Dec 01 2018 + (string) >> (string) Dec 01 2018
+307ms ║║Calculating (string) Dec 31 + (string) 2018 >> (string) Dec 31 2018
+309ms ║║Calculating (string) Dec 31 2018 + (string) >> (string) Dec 31 2018
+315ms ║║Comparison (date) 1516773600000 is_between (string) Dec 01 2018 … (string) Dec 31 2018 = false (4ms)
+317ms ║║Condition #15 evaluated false (27ms)
+317ms ║║Condition group #11 evaluated false (state did not change) (75ms)
+328ms ║║Comparison (date) 1516773600000 is_between (string) Jan 06, 2018 … (string) Feb 13, 2018 = true (5ms)
+329ms ║║Time restriction check passed
+330ms ║║Condition #19 evaluated true (10ms)
+331ms ║║Condition group #16 evaluated true (state did not change) (11ms)
+333ms ║║Cancelling statement #17’s schedules…
+337ms ║║Executed virtual command setVariable (1ms)
+347ms ║║Calculating (string) Feb 14, + (string) 2018 >> (string) Feb 14, 2018
+349ms ║║Calculating (string) Feb 14, 2018 + (string) >> (string) Feb 14, 2018
+356ms ║║Calculating (string) Feb 14, + (string) 2018 >> (string) Feb 14, 2018
+358ms ║║Calculating (string) Feb 14, 2018 + (string) >> (string) Feb 14, 2018
+364ms ║║Comparison (date) 1516773600000 is_between (string) Feb 14, 2018 … (string) Feb 14, 2018 = true (5ms)
+365ms ║║Time restriction check passed
+366ms ║║Condition #23 evaluated true (26ms)
+367ms ║║Condition group #20 evaluated true (state did not change) (27ms)
+369ms ║║Cancelling statement #21’s schedules…
+373ms ║║Executed virtual command setVariable (1ms)
+384ms ║║Comparison (date) 1516773600000 is_between (string) Mar 30, 2018 … (string) Apr 07, 2018 = false (5ms)
+386ms ║║Condition #29 evaluated false (9ms)
+386ms ║║Condition group #26 evaluated false (state did not change) (10ms)
+400ms ║║Comparison (date) 1516773600000 is_between (string) May 28, 2018 … (string) May 28, 2018 = true (8ms)
+401ms ║║Time restriction check passed
+402ms ║║Condition #33 evaluated true (13ms)
+403ms ║║Condition group #30 evaluated true (state did not change) (14ms)
+405ms ║║Cancelling statement #31’s schedules…
+409ms ║║Executed virtual command setVariable (1ms)
+418ms ║║Calculating (string) Oct 01, + (string) 2018 >> (string) Oct 01, 2018
+421ms ║║Calculating (string) Oct 01, 2018 + (string) >> (string) Oct 01, 2018
+428ms ║║Calculating (string) Oct 31, + (string) 2018 >> (string) Oct 31, 2018
+431ms ║║Calculating (string) Oct 31, 2018 + (string) >> (string) Oct 31, 2018
+437ms ║║Comparison (date) 1516773600000 is_between (string) Oct 01, 2018 … (string) Oct 31, 2018 = false (5ms)
+438ms ║║Condition #39 evaluated false (26ms)
+439ms ║║Condition group #36 evaluated false (state did not change) (27ms)
+442ms ║╚Execution stage complete. (310ms)
+443ms ║Setting up scheduled job for Fri, Jan 26 2018 @ 12:00:00 AM CST (in 86400.454s)
+451ms ╚Event processed successfully (451ms)


#20

You’re over complicating things!

Every year on x date
Set variable to x holiday

Every year on y date
Set variable to y holiday

Every year on z date
Set variable to z holiday

Every year on n date
Set variable to n holiday