Jump to content

Creating a Toggle out of a button


Dinboise

Recommended Posts

I wrote this little program thinking it would tun off the lights in the kitchen (the scene) if any of the lights were on.  And if the lights were all off it would turn on the typical light selection. But it will turn all the lights off and immediately turn the two lights on that are mentioned in the "Else".  I tried putting a "stop program" command under the "Then" commands but that didn't seem to do anything.  Has anyone had luck creating a toggle like function into a single press of a button?

IR06 - [ID 0012][Parent 000B]

If
        IR 'IR_006' is Pressed
    And (
             Status  'Kitchen Cans' is not Off
          Or Status  'Kitchen Pendant' is not Off
          Or Status  'Kitchen Sink' is On
          Or Status  'Kitchen flouresc living' is not Off
          Or Status  'Kitchen flouresc living' is not Off
        )
 
Then
        Set Scene 'Kitchen Lights' Off
 
Else
        Set 'Kitchen Pendant' On
        Set 'Kitchen Sink' On
 

David

Link to comment

What's happening is that the act of turning all of the lights off triggers the program to be re-evaluated, comes up false and then follow the else path.  Since the lights act like state variables and cause the program to be immediately re-evaluated, what I'd usually fix this by creating as second program with more fine-grained conditions and put the Else into the Then statement of it.

I'd probably use an integer variable, so the then becomes:

$Variable = 0
Set Scene Off
Wait 5 seconds
$Variable = 1

Then use that 1/0 variable as a condition on the second program, so that the If reads:

$Variable is 1
And Status of all lights
And IR_006 is pressed

And then make the Then part your current Else statement.

I believe there's a flag that only allows a program to run if it hasn't been run in a certain period of time that's now built into the 5.x firmware, but I've never used it so can't speak to it. :)

Link to comment

I think jec6613 correctly diagnosed the problem.  I don’t know that variables are the simple solution, however.

What about modifying your original program:

- disable it

- remove the first condition (if ir006 is pressed)

Then, add a second program such as:

if

if ir006 is pressed

then

run modified IR 06 program (if path)

 

 

Link to comment

hmm.  I have a state variable set up for my leak sensors and it is a bit complicated but doable.  I might try the disabling solution first when I have time.  For now, my wife and I had a good laugh as to why she couldn't tun off the lights. :)  Yeah, that's me - left the bad program enabled and went to bed. 

David

Link to comment

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...