Defined variable value is empty


#1

1) Give a description of the problem
I am trying to use a loop to collect all the opened contact names into a text string then send to a web request.

2) What is the expected behaviour?
The variable allOpenContacts should have all the open contact names. I will make is as a message to be used to a web request.

3) What is happening/not happening?
I can see the correct value is generated into the text string “allOpenContacts”. However, after the loop, in all the after task this allOpenContacts is an empty string. No idea why it’s gone.

**4) Post a Green Snapshot of the piston

5) Attach logs after turning logging level to Full
1/7/2022, 5:49:39 PM +868ms
+2ms ╔Received event [Overall Contact Status].contact = closed with a delay of 107ms
+77ms ║RunTime Analysis CS > 23ms > PS > 12ms > PE > 41ms > CE
+79ms ║Runtime (46901 bytes) successfully initialized in 12ms (v0.3.113.20210203) (76ms)
+80ms ║╔Execution stage started
+87ms ║║Comparison (enum) closed changes_to (string) open = false (0ms)
+89ms ║║Cancelling condition #2’s schedules…
+90ms ║║Condition #2 evaluated false (6ms)
+91ms ║║Cancelling condition #1’s schedules…
+92ms ║║Condition group #1 evaluated false (state changed) (7ms)
+93ms ║╚Execution stage complete. (13ms)
+95ms ╚Event processed successfully (94ms)
1/7/2022, 5:49:27 PM +2ms
+0ms ╔Received event [Home].wc_async_reply = httpRequest with a delay of 0ms
+74ms ║RunTime Analysis CS > 25ms > PS > 8ms > PE > 42ms > CE
+77ms ║Runtime (46890 bytes) successfully initialized in 8ms (v0.3.113.20210203) (76ms)
+78ms ║╔Execution stage started
+100ms ║║Calculating (integer) 1 - (integer) 1 >> (integer) 0
+114ms ║║Calculating (string) + (string) open for more than three minutes. Temperature is set to sixty four degree Fahrenheit. >> (string) open for more than three minutes. Temperature is set to sixty four degree Fahrenheit.
+171ms ║║Executed virtual command sendSMSNotification (53ms)
+173ms ║╚Execution stage complete. (95ms)
+181ms ╚Event processed successfully (180ms)
1/7/2022, 5:49:26 PM +284ms
+0ms ╔Received event [Home].wc_async_reply = httpRequest with a delay of 1ms
+128ms ║RunTime Analysis CS > 37ms > PS > 8ms > PE > 83ms > CE
+131ms ║Runtime (46891 bytes) successfully initialized in 8ms (v0.3.113.20210203) (130ms)
+133ms ║╔Execution stage started
+170ms ║║Calculating (integer) 1 - (integer) 1 >> (integer) 0
+187ms ║║Calculating (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac& + (string) monkey=family-room-monkey&announcement= >> (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=family-room-monkey&announcement=
+191ms ║║Calculating (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=family-room-monkey&announcement= + (string) >> (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=family-room-monkey&announcement=
+195ms ║║Calculating (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=family-room-monkey&announcement= + (string) %20open%20for%20more%20than%20three%20minutes.%20Temperature%20is%20set%20to%20sixty%20four%20degree%20Fahrenheit. >> (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=family-room-monkey&announcement=%20open%20for%20more%20than%20three%20minutes.%20Temperature%20is%20set%20to%20sixty%20four%20degree%20Fahrenheit.
+203ms ║║Sending external web request to: api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=family-room-monkey&announcement=%20open%20for%20more%20than%20three%20minutes.%20Temperature%20is%20set%20to%20sixty%20four%20degree%20Fahrenheit.
+230ms ║║Executed virtual command httpRequest (28ms)
+231ms ║║Requesting a wake up for Fri, Jan 7 2022 @ 5:49:50 PM CST (in 24.0s)
+235ms ║╚Execution stage complete. (103ms)
+237ms ║Setting up scheduled job for Fri, Jan 7 2022 @ 5:49:50 PM CST (in 23s)
+246ms ╚Event processed successfully (246ms)
1/7/2022, 5:49:22 PM +807ms
+1ms ╔Received event [Overall Contact Status].contact = open with a delay of 104ms
+72ms ║RunTime Analysis CS > 21ms > PS > 9ms > PE > 42ms > CE
+75ms ║Runtime (45995 bytes) successfully initialized in 9ms (v0.3.113.20210203) (73ms)
+76ms ║╔Execution stage started
+85ms ║║Comparison (enum) open changes_to (string) open = true (0ms)
+86ms ║║Cancelling condition #2’s schedules…
+88ms ║║Condition #2 evaluated true (6ms)
+89ms ║║Cancelling condition #1’s schedules…
+90ms ║║Condition group #1 evaluated true (state changed) (9ms)
+93ms ║║Cancelling statement #16’s schedules…
+97ms ║║Executed virtual command setVariable (1ms)
+101ms ║║Executed virtual command setVariable (1ms)
+107ms ║║Executed virtual command setVariable (3ms)
+2292ms ║║Comparison (dynamic) closed is (enum) open = false (2ms)
+2295ms ║║Condition #5 evaluated false (2180ms)
+2296ms ║║Condition group #4 evaluated false (state did not change) (2182ms)
+2319ms ║║Comparison (dynamic) closed is (enum) open = false (2ms)
+2321ms ║║Condition #5 evaluated false (17ms)
+2323ms ║║Condition group #4 evaluated false (state did not change) (19ms)
+2343ms ║║Comparison (dynamic) closed is (enum) open = false (2ms)
+2346ms ║║Condition #5 evaluated false (17ms)
+2348ms ║║Condition group #4 evaluated false (state did not change) (19ms)
+2376ms ║║Comparison (dynamic) closed is (enum) open = false (2ms)
+2378ms ║║Condition #5 evaluated false (19ms)
+2380ms ║║Condition group #4 evaluated false (state did not change) (21ms)
+2404ms ║║Comparison (dynamic) open is (enum) open = true (2ms)
+2406ms ║║Cancelling condition #5’s schedules…
+2407ms ║║Condition #5 evaluated true (19ms)
+2409ms ║║Cancelling condition #4’s schedules…
+2410ms ║║Condition group #4 evaluated true (state changed) (23ms)
+2413ms ║║Cancelling statement #6’s schedules…
+2422ms ║║Executed virtual command setVariable (4ms)
+2428ms ║║Calculating (integer) 0 + (integer) 1 >> (integer) 1
+2432ms ║║Executed virtual command setVariable (2ms)
+2454ms ║║Comparison (dynamic) closed is (enum) open = false (2ms)
+2456ms ║║Cancelling condition #5’s schedules…
+2457ms ║║Condition #5 evaluated false (18ms)
+2458ms ║║Cancelling condition #4’s schedules…
+2460ms ║║Condition group #4 evaluated false (state changed) (21ms)
+2482ms ║║Comparison (dynamic) closed is (enum) open = false (1ms)
+2484ms ║║Condition #5 evaluated false (17ms)
+2485ms ║║Condition group #4 evaluated false (state did not change) (19ms)
+2508ms ║║Comparison (dynamic) closed is (enum) open = false (2ms)
+2511ms ║║Condition #5 evaluated false (20ms)
+2512ms ║║Condition group #4 evaluated false (state did not change) (21ms)
+2535ms ║║Comparison (dynamic) closed is (enum) open = false (1ms)
+2536ms ║║Condition #5 evaluated false (17ms)
+2538ms ║║Condition group #4 evaluated false (state did not change) (19ms)
+2562ms ║║Comparison (dynamic) closed is (enum) open = false (2ms)
+2564ms ║║Condition #5 evaluated false (20ms)
+2566ms ║║Condition group #4 evaluated false (state did not change) (21ms)
+2591ms ║║Comparison (dynamic) closed is (enum) open = false (2ms)
+2594ms ║║Condition #5 evaluated false (20ms)
+2595ms ║║Condition group #4 evaluated false (state did not change) (22ms)
+2622ms ║║Comparison (dynamic) closed is (enum) open = false (1ms)
+2625ms ║║Condition #5 evaluated false (22ms)
+2626ms ║║Condition group #4 evaluated false (state did not change) (24ms)
+2655ms ║║Comparison (dynamic) closed is (enum) open = false (1ms)
+2658ms ║║Condition #5 evaluated false (24ms)
+2659ms ║║Condition group #4 evaluated false (state did not change) (26ms)
+2687ms ║║Comparison (dynamic) closed is (enum) open = false (1ms)
+2689ms ║║Condition #5 evaluated false (23ms)
+2690ms ║║Condition group #4 evaluated false (state did not change) (24ms)
+2719ms ║║Comparison (dynamic) closed is (enum) open = false (1ms)
+2721ms ║║Condition #5 evaluated false (22ms)
+2722ms ║║Condition group #4 evaluated false (state did not change) (25ms)
+2753ms ║║Comparison (dynamic) closed is (enum) open = false (1ms)
+2755ms ║║Condition #5 evaluated false (25ms)
+2756ms ║║Condition group #4 evaluated false (state did not change) (27ms)
+2793ms ║║Comparison (dynamic) closed is (enum) open = false (2ms)
+2795ms ║║Condition #5 evaluated false (31ms)
+2796ms ║║Condition group #4 evaluated false (state did not change) (33ms)
+2808ms ║║Calculating (integer) 1 - (integer) 1 >> (integer) 0
+2813ms ║║Cancelling statement #14’s schedules…
+2827ms ║║Calculating (string) ,%20 + (string) Family Door >> (string) ,%20Family Door
+2832ms ║║Calculating (string) == (string) >> (boolean) true
+2836ms ║║Calculating (string) + (string) Family Door >> (string) Family Door
+2840ms ║║Executed virtual command setVariable (1ms)
+2844ms ║║Cancelling statement #21’s schedules…
+2852ms ║║Calculating (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac& + (string) monkey=office-monkey&announcement= >> (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=office-monkey&announcement=
+2937ms ║║Calculating (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=office-monkey&announcement= + (string) Family Door >> (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=office-monkey&announcement=Family Door
+2940ms ║║Calculating (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=office-monkey&announcement=Family Door + (string) %20open%20for%20more%20than%20three%20minutes.%20Temperature%20is%20set%20to%20sixty%20four%20degree%20Fahrenheit. >> (string) https://api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=office-monkey&announcement=Family Door%20open%20for%20more%20than%20three%20minutes.%20Temperature%20is%20set%20to%20sixty%20four%20degree%20Fahrenheit.
+2948ms ║║Sending external web request to: api.voicemonkey.io/trigger?access_token=d83b5af572d9d56f7a5817c3d9e9660a&secret_token=27e984fd5c9fc8dd3de25016e4bbdaac&monkey=office-monkey&announcement=Family%20Door%20open%20for%20more%20than%20three%20minutes.%20Temperature%20is%20set%20to%20sixty%20four%20degree%20Fahrenheit.
+2965ms ║║Executed virtual command httpRequest (18ms)
+2967ms ║║Requesting a wake up for Fri, Jan 7 2022 @ 5:49:49 PM CST (in 24.0s)
+2971ms ║╚Execution stage complete. (2895ms)
+2972ms ║Setting up scheduled job for Fri, Jan 7 2022 @ 5:49:49 PM CST (in 23s)
+3160ms ╚Event processed successfully (3160ms)

**REMOVE BELOW AFTER READING**
If a solution is found for your question then please mark the post as the solution.

#2

I might know what was going on.
If the array is size 0, the loop seems to be not run; therefore, it does not set any value.
index = 0 to 0 step 1 will not run anything that is my guess. I added a if statement. Hopefully it will work.


#3

Looks like you have the string value already defined as empty string, each time the piston runs it will set it to that value. You should leave it as undefined and clear it when you’re done processing the piston, or clear at the very top of the piston, your choice.

Also what does the message have to look like, there might be an easier way to construct it by using save matching devices to variable


#4

Yes I knew that and already updated in the later version. However, it’s not the root cause. It’s just the duplicated code. I answered my own question and I just tested and it worked.

Thank you anyway.