I’m having trouble with a variable not changing. The bedtime variable is still false after running this piston. Can someone look at my pistion and point me in the right direction? (I know I have it listed 3 different times. I was just trying different things.)
Help with changing the value of a variable
First off, a lot is happening for a single piston.
Second, global variables change ONLY when piston runs all the way. That might be your problem.
just to test try this,
IF
Switch 20 changes to ON
set variable @bedtime = true
It does finish all the way through. It’s my night time routine and works great, except for this part. I can’t use a single switch, because they all go on and off all day. I also need a slight delay before i change the variable from false to true. this triggers another piston to stop it’s tasks.
here are the logs:
11/17/2020, 1:17:17 PM +960ms
+2ms ╔Received event [Last to Bed].switch = off with a delay of 76ms, canQueue: true, calledMyself: false
+192ms ║RunTime initialize > 188 LockT > 20ms > rtDT > 16ms > pistonT > 1ms (first state access 152 22 166)
+220ms ║Runtime (10373 bytes) successfully initialized in 16ms (v0.3.110.20201015_HE)
+221ms ║╔Execution stage started
+231ms ║║Comparison (enum) off changes_to (string) on = false (1ms)
+233ms ║║Cancelling condition #27’s schedules…
+242ms ║║Condition #27 evaluated false (17ms)
+244ms ║║Cancelling condition #1’s schedules…
+245ms ║║Condition group #1 evaluated false (state changed) (21ms)
+254ms ║╚Execution stage complete. (28ms)
+377ms ╚Event processed successfully (376ms)
11/17/2020, 1:17:12 PM +901ms
+5ms ╔Received event [Last to Bed].switch = on with a delay of 34ms, canQueue: true, calledMyself: false
+189ms ║RunTime initialize > 188 LockT > 2ms > rtDT > 177ms > pistonT > 176ms (first state access 9 7 181)
+213ms ║Runtime (10307 bytes) successfully initialized in 177ms (v0.3.110.20201015_HE)
+214ms ║╔Execution stage started
+230ms ║║Comparison (enum) on changes_to (string) on = true (1ms)
+231ms ║║Cancelling condition #27’s schedules…
+246ms ║║Condition #27 evaluated true (15ms)
+248ms ║║Cancelling condition #1’s schedules…
+250ms ║║Condition group #1 evaluated true (state changed) (32ms)
+252ms ║║Cancelling statement #16’s schedules…
+261ms ║║Executed virtual command setLocationMode (5ms)
+267ms ║║Executed virtual command setVariable (1ms)
+270ms ║║Cancelling statement #9’s schedules…
+304ms ║║Executed physical command [Nest Thermostat - Hallway].setCoolingSetpoint([72.0], ) (27ms)
+313ms ║║Executed [Nest Thermostat - Hallway].setCoolingSetpoint (29ms)
+359ms ║║Executed physical command [Nest Thermostat - Hallway].setHeatingSetpoint([67.0], ) (40ms)
+360ms ║║Executed [Nest Thermostat - Hallway].setHeatingSetpoint (42ms)
+364ms ║║Cancelling statement #12’s schedules…
+399ms ║║Executed physical command [Bedroom Fan].on() (31ms)
+400ms ║║Executed [Bedroom Fan].on (34ms)
+453ms ║║Executed physical command [Dad’s Fan].on() (50ms)
+454ms ║║Executed [Dad’s Fan].on (52ms)
+473ms ║║Executed physical command [Mom’s Fan].on() (17ms)
+474ms ║║Executed [Mom’s Fan].on (19ms)
+477ms ║║Cancelling statement #3’s schedules…
+488ms ║║Skipped execution of physical command [Back Porch Light1].off([]) because it would make no change to the device. (6ms)
+489ms ║║Executed [Back Porch Light1].off (8ms)
+497ms ║║Skipped execution of physical command [Back Porch Light2].off([]) because it would make no change to the device. (5ms)
+498ms ║║Executed [Back Porch Light2].off (7ms)
+507ms ║║Skipped execution of physical command [Backyard Pool Light].off([]) because it would make no change to the device. (6ms)
+508ms ║║Executed [Backyard Pool Light].off (8ms)
+517ms ║║Skipped execution of physical command [Bedroom Dimmer].off([]) because it would make no change to the device. (6ms)
+518ms ║║Executed [Bedroom Dimmer].off (9ms)
+525ms ║║Skipped execution of physical command [Canopy].off([]) because it would make no change to the device. (4ms)
+526ms ║║Executed [Canopy].off (6ms)
+533ms ║║Skipped execution of physical command [Canopy Fan1].off([]) because it would make no change to the device. (1ms)
+534ms ║║Executed [Canopy Fan1].off (6ms)
+538ms ║║Skipped execution of physical command [Canopy Fan2].off([]) because it would make no change to the device. (1ms)
grrr… I solved the problem. I didn’t have it set to never cancel tasks, and your right it wasn’t fully finishing.
I’m glad…
I still recommend this piston to be split into 3 pistons…
When global variable changes,
piston #1
deals woth thermostat
piston #2
deals with switches
Piston #3 deals with locks
etc
The issue you get with global variables is that they are read into a cache when a piston instance starts up and only get written back when it exits. This means changes aren’t immediately available to other pistons.
Your piston will have exited when it started each of the two waits and updated the global variable at those points (though it might not have made it past the first wait). If a wait is “cancelled” the piston has still finished elegantly.
I agree.
also note: You can subscribe to global variables changing, which can be helpful for running other pistons.