Very new to this...Time of day lighting virtual switch


#1

1) Give a description of the problem
Trying to set up a virtual switch to control 3 lights. My gym/studio are downstairs, access to which is through a stairway lit by a window. Half of setup is working when I use a Momentary Button Tile, everything gets wonky when I use a Simulated Switch. I freely admit I’m very new but wanting to learn.

2) What is the expected behavior?
I’d like to be able to tell me Echo to “turn on Workout” and turn on the gym and studio lights, and if it’s dark out turn on the stairway light long enough for me to get down there, then timeout. I’d then like to be able to say “turn off Workout” and turn off the gym and studio lights after a delay so I have time to get out of there, then if it’s now dark out turn on the stairway light and time it out after a few minutes.

3) What is happening/not happening?
If I set this up using a Momentary Button Tile the turning-on piston works. If I resume the turning-off piston it works and then immediately turns off. I suspect this is because a momentary button registers as a quick ‘on’ followed by going back to off. Makes sense. So I turned it into a Simulated Switch and the entire thing freaks out, ie. turning Workout on does nothing, turning it off turns the lights on, I can’t make sense of it.

4) Post a Green Snapshot of the pistonimage


5) Attach any logs (From ST IDE and by turning logging level to Full)
Couldn't really find any logs...

Like I said, very new so be gentle. I was so excited when I got the first half of the momentary version to work and a touch heartbroken when everything went wonky. Any help would be greatly appreciated.


#2

If nobody gets back to you on this by this evening I’ll write up some pointers/help. I’m just going to be in an airplane until this evening and don’t have the ability.

Tag me in a reply this evening if I haven’t gotten to it. :wink:


#3

Is this what you are trying to do?


#4

Thank you all for having a look!

Yes this is 99% what I was trying to do. Thank you :slight_smile:

When I first tried this using the momentary switch my thinking was it wouldn’t have an ‘on’ state or an ‘off’ state, so that if the script is run using the Workout virtual switch, then if the affected lights are shut off manually, or by someone else, or if you just forget you turned them on with the command, the virtual switch wouldn’t still be in an on or off state. This way I was hoping to be able say Turn On Workout again later and have it work even if no one issued a Turn Off Workout. I thought this would work since a switch once on stays on and cannot be turned on again until turned off. I hope any of that made sense :slight_smile:

Was I correct thinking that a momentary switch is still just a switch that quickly turns itself off?

whoismoses, can you briefly explain ‘async with’ in line 43 vs a ‘with’ command?

Also, I can now see that my having two pistons is a convoluted, messy attempt, but I’m still not understanding why they didn’t work. Not that I’m not grateful for a functioning one, but I really am enjoying learning from my mistakes!


#5

Going to kind of jump in here.

Yes that is correct.

Check this out From the wiki


#6

Thank you @c1arkbar, that wiki will be a great resource :slight_smile:


#7

Not at a spot where I can play around at the moment, but would implementing aspects of this sample piston

https://wiki.webcore.co/File:Advancedmotionv1.png

get me closer to my goal of command/manual switch interoperability?


#8

Ok I think I’m getting closer to what I want to do but I’m running into some more trouble I can’t figure out. I tried editing the piston given to me by @whoismoses (which I understand WHY it works, thank you :slight_smile:) to incorporate the variable aspects of the sample I posted and I can’t understand why it’s not working correctly. Here’s what happens:

From an everything off state, turning Workout on turns all three lights on, but the stairway does not timeout. Then, turning Workout off does nothing. With all three lights still on from the initial turn on, turning Workout on again does nothing to the Gym and Studio (as expected), but now the Stairway does properly timeout. Turning Workout off from here behaves properly (Stairway turns on and everything times out after 5 seconds)

I think it’s an order of operations or something not being set correctly but I’ve been at it a few hours and can’t see where the problem is. @Cozdabuch I’ll take you up on your advice now :slight_smile: Hopefully exactly WHAT I’m trying to do is a little clearer seeing my attempt:

https://imgur.com/fBeljCt

And I found logs! Here’s me turning the Workout virtual switch on, waiting a minute, then turning it off. Stairway light timeout broke and I can’t see why, and something (state not properly changing?) is preventing it from shutting off properly.

10/3/2017, 11:12:00 PM +256ms
+1ms ╔Received event [Workout].switch = off with a delay of 57ms
+106ms ║RunTime Analysis CS > 14ms > PS > 46ms > PE > 46ms > CE
+114ms ║Runtime (40538 bytes) successfully initialized in 46ms (v0.2.0ec.20170927) (111ms)
+114ms ║╔Execution stage started
+124ms ║║Comparison (enum) off changes_to (string) on = false (1ms)
+125ms ║║Condition #10 evaluated false (6ms)
+125ms ║║Condition group #1 evaluated false (state did not change) (6ms)
+132ms ║║Comparison (enum) off changes_to (string) off = true (1ms)
+133ms ║║Cancelling condition #21’s schedules…
+133ms ║║Condition #21 evaluated true (6ms)
+136ms ║║Comparison (boolean) false is (boolean) true = false (1ms)
+136ms ║║Condition #23 evaluated false (3ms)
+137ms ║║Condition group #11 evaluated false (state did not change) (10ms)
+153ms ║║Condition #27 evaluated false (14ms)
+154ms ║║Condition group #24 evaluated false (state did not change) (16ms)
+155ms ║╚Execution stage complete. (41ms)
+162ms ╚Event processed successfully (162ms)
10/3/2017, 11:10:02 PM +752ms
+2ms ╔Received event [Studio Lights].switch = on with a delay of 710ms
+10015ms ║RunTime Analysis CS > 20ms > PS > 9952ms > PE > 43ms > CE
+10022ms ║Piston waited at a semaphore for 9905ms
+10024ms ║Runtime (40620 bytes) successfully initialized in 9952ms (v0.2.0ec.20170927) (10022ms)
+10024ms ║╔Execution stage started
+10039ms ║║Condition #10 evaluated false (10ms)
+10039ms ║║Condition group #1 evaluated false (state did not change) (10ms)
+10048ms ║║Condition #21 evaluated false (7ms)
+10048ms ║║Condition group #11 evaluated false (state did not change) (7ms)
+10061ms ║║Comparison (enum) on changes_to (string) off = false (0ms)
+10062ms ║║Condition #27 evaluated false (12ms)
+10063ms ║║Condition group #24 evaluated false (state did not change) (13ms)
+10064ms ║╚Execution stage complete. (40ms)
+10071ms ╚Event processed successfully (10071ms)
10/3/2017, 11:10:02 PM +614ms
+0ms ╔Received event [Gym Lights].switch = on with a delay of 717ms
+80ms ║RunTime Analysis CS > 14ms > PS > 29ms > PE > 38ms > CE
+91ms ║Runtime (40536 bytes) successfully initialized in 29ms (v0.2.0ec.20170927) (89ms)
+91ms ║╔Execution stage started
+101ms ║║Cancelling condition #10’s schedules…
+102ms ║║Condition #10 evaluated false (6ms)
+102ms ║║Cancelling condition #1’s schedules…
+103ms ║║Condition group #1 evaluated false (state changed) (7ms)
+110ms ║║Condition #21 evaluated false (5ms)
+110ms ║║Condition group #11 evaluated false (state did not change) (6ms)
+119ms ║║Comparison (enum) on changes_to (string) off = false (0ms)
+120ms ║║Cancelling condition #27’s schedules…
+120ms ║║Condition #27 evaluated false (8ms)
+121ms ║║Cancelling condition #24’s schedules…
+121ms ║║Condition group #24 evaluated false (state changed) (9ms)
+123ms ║╚Execution stage complete. (32ms)
+132ms ╚Event processed successfully (132ms)
10/3/2017, 11:10:02 PM +197ms
+0ms ╔Received event [Workout].switch = on with a delay of 50ms
+75ms ║RunTime Analysis CS > 10ms > PS > 30ms > PE > 36ms > CE
+84ms ║Runtime (40535 bytes) successfully initialized in 30ms (v0.2.0ec.20170927) (83ms)
+84ms ║╔Execution stage started
+91ms ║║Comparison (enum) on changes_to (string) on = true (0ms)
+92ms ║║Cancelling condition #10’s schedules…
+93ms ║║Condition #10 evaluated true (4ms)
+93ms ║║Cancelling condition #1’s schedules…
+93ms ║║Condition group #1 evaluated true (state changed) (5ms)
+95ms ║║Cancelling statement #8’s schedules…
+110ms ║║Executed physical command [Gym Lights].on() (13ms)
+111ms ║║Executed [Gym Lights].on (15ms)
+125ms ║║Executed physical command [Studio Lights].on() (13ms)
+125ms ║║Executed [Studio Lights].on (13ms)
+145ms ║║Comparison (datetime) 1507086602146 is_between (datetime) 1507070820000 … (datetime) 1507028940000 = true (2ms)
+146ms ║║Condition #7 evaluated true (19ms)
+146ms ║║Condition group #2 evaluated true (state did not change) (19ms)
+148ms ║║Cancelling statement #3’s schedules…
+164ms ║║Executed physical command [Stairway Light].on() (14ms)
+164ms ║║Executed [Stairway Light].on (15ms)
+166ms ║║Executed virtual command [Stairway Light].wait (0ms)
+167ms ║║Requesting a wake up for Tue, Oct 3 2017 @ 11:10:07 PM EDT (in 5.0s)
+171ms ║╚Execution stage complete. (86ms)
+172ms ║Setting up scheduled job for Tue, Oct 3 2017 @ 11:10:07 PM EDT (in 4.996s)
+191ms ╚Event processed successfully (191ms)

Thank you for any and all help. Really enjoying playing around with this.


#9

Anything?


#10

@webCoRE_Minions


#11

Can you repost the piston screenshot with trace turned on so we can see the lines that correspond to the conditions in the log? Also, can you give us an idea of which switch is which as the screenshot rightfully hides that?


#12

Sure thing:

https://imgur.com/dDtX4Ny

Switch 6 is the simulated Workout switch
Switch 1 is the physical Gym switch
Switch 3 is the physical Studio switch
Switch 5 is the Stairway Light switch

Interestingly, in running this piston during sun up, therefore bypassing the timed stairway, everything seemed to work as intended…


#14

Try this:


#15

@Gopack2, thank you for your help :slight_smile: While this does function as @whoismoses’s piston does, I’m still looking for additional functionality that looking back I maybe wasn’t clear about - Basically once Workout is on, if Gym or Studio are turned off directly, Workout silently reverts to off. Thereby allowing Workout to be used again later from a fresh start. I’ll keep digging but thank you all for your help. I only wish I had more chunks of time to dedicate to learning and testing with this :slight_smile: