Create a scene (multiple devices on/off with one command) that restores prior settings

This is an advanced scene scenario (requiring 4.0 Pro), based on the basic scenes How-To, with some additional functionality. It is sometimes desirable to return a light or other device to a previous state when a “scene” is turned off. In this How-to, we'll describe how to restore the lights in a scene to their state prior to the scene getting activated. This How-to level of difficulty is Moderate.

What you need to start

  • Some devices to control (typically lights, but could also be devices such as window shade controllers)
  • Something to trigger the scene (typically a switch or remote)

Scenario Overview

To recap the scenes scenario: Joe has some nice wall sconce lights in his TV room that are controlled by an SwitchLinc and a table lamp connected through an ICON Lamp Module. He also has just installed some X10 controllable window shades (an X10 ON command lowers them, an X10 OFF command raises them in this example). He has a ControLinc that he wants to set up so that when he hits Button 1 ON, the sconces dim to 20%, the table lamp turns off, and the window shades go down. Here's the difference between the basic scenario and this one: when he hits Button 1 OFF, the sconces, the table lamp, and the window shades will return to their previous state. In other words, the room will look like it did before he pressed the Button 1 ON. This scenario will require Indigo 4.0 Pro since we'll need to use some AppleScript.

Steps to create this scenario

This scenario isn't really too difficult, but it does require some AppleScript, which we will provide here:

Create a variable for each device for which you want to restore the state

  1. Open the Variable window by selecting Variable List from the Window menu
  2. Click on the New… button to create a new variable
  3. Double click on the new variable's name (usually “variable”) and type in a new name - in this example I'm going to use “sconce_previous”
  4. Repeat steps 2 and 3 again, this time naming the variable “lamp_previous”
  5. Repeat steps 2 and 3 once more, this time naming the variable “shades_previous”


You now have 3 variables, named “sconce_previous”, “lamp_previous”, and “shades_previous”. These variables will hold the state that those devices were in prior to setting them to what they need to be for the scene.

Create ON Trigger Action

So, now we need to create 2 trigger actions so that when Joe presses the right buttons on his ControLinc, the actions listed in the scenario above happen correctly. The first one will be for the On command:

  1. Select TRIGGERS in the outline view on the left side (we're going to make these
  2. Click the New… button above the trigger list
  3. Name the trigger “Start watching a movie”
  4. Select INSTEON Command Received from the Type: popup
  5. Click the Device radio button beside From: if not already checked
  6. Select the name of the ControLinc from the device popup next to the word Device
  7. Select On on the popup next to Received:, and Button/Group 1 on the popup next to that
  8. That specifies that this trigger will fire when the Button 1 ON command is received from the ControLinc - now select the Actions tab (you can skip Condition for this example)
  9. Select Execute AppleScript from the Type: popup
  10. Ensure that the radio button next to Embedded: is checked
  11. In the text field below Embedded:, paste in the following script (note, you should replace the device names below with actual devices that you want to use):
    -- First, we'll save off the sconces - we're assuming here that they are on a dimmer switch, so we'll
    -- save either the word "off" or the number representing the brightness value
    if (on state of device "TV Room Sconce") then
        set value of variable "sconce_previous" to brightness of device "TV Room Sconce"
    else
        set value of variable "sconce_previous" to "off"
    end if
    
    -- Next, we'll save off the lamp - again, we'll assume that they are on a dimmer switch, so we'll
    -- save either the word "off" or the number representing the brightness value
    if (on state of device "TV Room Lamp") then
        set value of variable "lamp_previous" to brightness of device "TV Room Lamp"
    else
        set value of variable "lamp_previous" to "off"
    end if
    
    -- Last, we'll save off the blind state - here, we're assuming that the blinds are either down or up
    -- depending on the on/off state of the device, which is why we just save either true or false
    -- which is what's returned when you say "on state of device...".
    set value of variable "shades_previous" to on state of device "TV Room Shades"
  12. That takes care of storing the states, now we want to actually change them to their desired states - click on the Add New button at the lower left side of the dialog - don't worry, the one you just created isn't gone, it's just hidden - you can see all actions by clicking the Show All button and you can cycle through all actions using the Prev and Next buttons next to Show:, and you can see from the text that we're now on action 2 of 2.
  13. Select Control Light / Appliance from the Type: popup
  14. Select Set Brightness from the Action: popup
  15. Select the device that represents the sconces from the Device: popup
  16. Enter 20 in the text field next to Amount:
  17. Now, add another for the lamp by clicking on the Add New button again
  18. Select Control Light / Appliance from the Type: popup
  19. Select Turn Off from the Action: popup
  20. Select the device that represents the table lamp from the Device: popup
  21. Now, add one more for the blinds by clicking on the Add New button again
  22. Select Control Light / Appliance from the Type: popup
  23. Select Turn On from the Action: popup
  24. Select the device that represents the blinds from the Device: popup


That's it! So, to recap, what we did was create a trigger action that will fire when Button 1 ON on the ControLinc is pressed. It executes 4 actions: runs an AppleScript that saves the state of each device into variables, set's the brightness of the sconces to 20%, turns off the table lamp, and lowers the blinds by sending them an ON command (note, if they are already down, nothing will happen). So, how do we reverse the process? Read on…

Create OFF Trigger Action

As you may have guessed, we need to create another trigger like the one above, except it reverses the process:

  1. Select TRIGGERS in the outline view on the left side (we're going to make these
  2. Click the New… button above the trigger list
  3. Name the trigger “Stop watching a movie”
  4. Select INSTEON Command Received from the Type: popup
  5. Click the Device radio button beside From: if not already checked
  6. Select the name of the ControLinc from the device popup next to the word Device
  7. Select Off on the popup next to Received:, and Button/Group 1 on the popup next to that
  8. That specifies that this trigger will fire when the Button 1 Off command is received from the ControLinc - now select the Actions tab (again, skip Condition for this example)
  9. Select Execute AppleScript from the Type: popup
  10. Ensure that the radio button next to Embedded: is checked
  11. In the text field below Embedded:, paste in the following script (note, you should replace the device names below with actual devices that you want to use):
    -- First, we restore the sconce setting
    if ((value of variable "sconce_previous") ≠ "off") then
        set brightness of device "TV Room Sconce" to value of variable "sconce_previous"
    else
        set on state of device "TV Room Sconce" to false
    end if
    
    -- Next, we restore the lamp state
    if ((value of variable "lamp_previous") ≠ "off") then
        set brightness of device "TV Room Lamp" to value of variable "lamp_previous"
    else
        set on state of device "TV Room Lamp" to false
    end if
    
    -- Last, we put the shades back to their orignial state 
    -- Note: if they were already down, they'll just stay down
    set on state of device "TV Room Shades" to value of variable "shades_previous"

Congratulations!

You've now created two scenes for Joe's TV room: one he'll use when watching a movie and another that returns the room to it's previous state. As you can probably see, there are other things you can do to make this scene even more useful: if you have an Infrared receiver, you could program a button on your current IR remote to trigger the actions. If you have an Infrared transmitter, you could add extra actions that would set your A/V equipment up so that it's ready to watch a movie.

A word about Action Groups

In a simple trigger action, there is probably only one action that you want to take. In the scenario that we just finished, though, we have several actions we want to perform (adjust 2 different lights and the window shades). Indigo let's you specify multiple actions in the “Create New Trigger Action” dialog, and that's how we did it here. If, however, you had multiple ways you wanted to trigger these actions (besides just buttons on a single ControLinc), then you would implement the actions in Action Groups. Feel free to read up on those at your leisure!

scenes_restore_state.txt · Last modified: 2019/01/25 22:53 (external edit)
 

© Perceptive Automation, LLC. · Privacy