Global variable to track state?


#1

1) Give a description of the problem
Looking for a better way to implement state tracking. I want to track the state of the curtains (dimmer 2). Either opened or closed so they can be restored to a prior state. I can get it to work with a global variable but there is probably a better way.

2) What is the expected behaviour?
Save state of curtains (dimmer 2) and restore it later

3) What is happening/not happening?
currently works as expected I’m thinking there is a better more efficient way to do this.

**4) Post a Green Snapshot of the piston


#2

I use previous state often, but never for simply binary comparisons.

  • In other words, if the curtains are open, then you know without fail, that the last state was closed.
  • Likewise, if the curtains are closed, you know with 100% certainty that they were previously open.

I will use previous states for more complex situations.

IE: Store current bulb’s level… Brighten for a minute, then return to previous level.


#3

What I am thinking here is curtains could be already closed for some other reason. Either the person wanted them closed or some other function previously closed them.

This feature is intended to work off my harmony remote “watch movie” activity. I click watch movie and it shuts the lights off and if the curtains are open/closed it stores the state. Then it closes the curtains. When “watch movie” is excited it restores the state prior to the “watch movie” being pushed.

switch 1= harmony activity “watch movie”


#4

Ahh OK, that makes sense. I think you have to keep the variables global then.
(or you can use a Simulated Switch to represent the previous state)