Hue switch, multiple button presses and variables


#1

1) Give a description of the problem
Spent couple of hours building piston…and it does not work :slight_smile:

2) What is the expected behaviour?
First press in “Entrance Hue Switch” button should do different things than second button press. Buttons are used to manage lights.

3) What is happening/not happening?
Whole piston runs and turns all entrance lights on because my rules are bad. I wanted to entrance lights “normal” turn on with first press. Then if button is pressed again I would like to turn entrance lights “ceiling” on. Now when pressing button all entrance lights turn on and don’t know how to use variable so that ceiling would not turn on from first button press.

**4) Post a Green Snapshot of the piston![image|45x37]

5) Attach logs after turning logging level to Full
2.2.2021 klo 6.55.20 +828ms
+20ms ╔Received event [Entrance Hue Switch].pushed = 1 with a delay of 26ms, canQueue: true, calledMyself: false
+59ms ║RunTime initialize > 58 LockT > 1ms > rtDT > 37ms > pistonT > 37ms (first state access 20 21 37)
+63ms ║Runtime (9515 bytes) successfully initialized in 37ms (v0.3.110.20210123_HE)
+64ms ║╔Execution stage started
+71ms ║║Comparison (integer) 1 gets (integer) 1 = true (1ms)
+72ms ║║Cancelling condition #46’s schedules…
+73ms ║║Condition #46 evaluated true (6ms)
+77ms ║║Comparison (boolean) false is (boolean) false = true (1ms)
+79ms ║║Condition #57 evaluated true (4ms)
+80ms ║║Cancelling condition #45’s schedules…
+81ms ║║Condition group #45 evaluated true (state changed) (14ms)
+83ms ║║Cancelling statement #47’s schedules…
+89ms ║║Executed virtual command [Entrance Normal].setVariable (2ms)
+208ms ║║Executed physical command [Entrance Normal].on() (115ms)
+209ms ║║Executed [Entrance Normal].on (116ms)
+215ms ║║Comparison (integer) 1 gets (integer) 1 = true (0ms)
+216ms ║║Cancelling condition #60’s schedules…
+218ms ║║Condition #60 evaluated true (6ms)
+221ms ║║Comparison (boolean) true is (boolean) true = true (1ms)
+223ms ║║Cancelling condition #61’s schedules…
+224ms ║║Condition #61 evaluated true (5ms)
+225ms ║║Cancelling condition #59’s schedules…
+227ms ║║Condition group #59 evaluated true (state changed) (15ms)
+228ms ║║Cancelling statement #62’s schedules…
+332ms ║║Executed physical command [Entrance Ceiling].on() (100ms)
+333ms ║║Executed [Entrance Ceiling].on (102ms)
+339ms ║║Executed virtual command [Entrance Ceiling].setVariable (2ms)
+345ms ║║Comparison (integer) 1 gets (integer) 4 = false (1ms)
+347ms ║║Condition #54 evaluated false (5ms)
+349ms ║║Condition group #53 evaluated false (state did not change) (7ms)
+354ms ║║Comparison (integer) 1 gets (integer) 4 = false (0ms)
+356ms ║║Condition #69 evaluated false (5ms)
+358ms ║║Condition group #68 evaluated false (state did not change) (7ms)
+361ms ║╚Execution stage complete. (298ms)
+364ms ╚Event processed successfully (346ms)


#2

If you intend it to do 1 action block, add an exit command inside the block so that the piston runs no further (on that button press)


#3

Well that works! Thanks! This was the first time using exit command so learned something new too.


#4

Sorry to bother @E_Sch you again but can you share your thoughts about my piston issue. Piston works mostly like it is supposed to.


But sometimes…for example today couple of times my variables in piston became static. First variable was true and second false. According piston when button 4 is pressed and first variable is false and second true ->
image

But nothing happens. Light does not turn off and both variables keep their status information.

Is there something that still needs to be done to get these variables work correctly? I’m not sure if this has something to do with other light automations (in other pistons and in hue smart app) where bulb status changes but this hue switch piston does not know it. I have disabled command optimization. Is there something more to look for…


#5

I think you should post the entire piston it is hard to look at snippets.

This will also allow others in the forum (who are better than me at writing pistons) to comment.

In general you are building a state machine, the question is it a deterministic state machine, or are there cases it become indeterminate.

If you always force thru the same cycle - is one form of writing this.

If you allow short circuiting or multiple different cycles, then things can get complicated…

Trace is your friend in the webcore UI. You can run with logging medium.

I think you can put messages on the exit commands so they can say what they just did

I use this sometimes so the piston state shows me what decision (like “turned on light one”)


#6

Hi,

Entire piston is there. Not sure why it can’t be seen fully without clicking it. Actually piston is long that it goes so small and needs to be downloaded/opened from there.
Other stuff you wrote -> You are completely right. This seems to be quite complicated thing even though there is just two variables. I’m guessing there is more sophisticated way to build pistons with variables comparing to my way of doing it.
I need to check log and try to find out what is going on. I already tried to understand it but couldn’t figure out why command does not go through.