Announcement

Collapse
No announcement yet.

How do I turn OFF 20 devices but save each of their (ON/OFF) stage for later restore?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    You could try using virtual devices for each device that you want to know the previous state of before the house went into Alarm mode. Do you have a device in HS for the Alarm status? If so, and lets assume that it is, A1, then if you have a light device, say L1, you could create a virtual device for it, say S1. Then create an event that sets s1 "on" whenever L1 is set "on" BUT put in a condition that A1 (alarm status) is "off" (Using off for disarmed, on for armed). Then also creat an event that sets s1 "off" whenever L1 is set to "off" and again put in the condition that A1 is "off".

    Then when you arm your system, and A1 goes to "on" (armed) and you shut all your devices off, which L1 is a part of, s1 will stay at "on" because the event above won't fire because A1 is "on".

    When A1 is then set to "off" (disarmed) have an event that sets L1 to "on" using the condition that s1 is "on", and also an event that would set L1 to "off" if s1 is "off".

    This is alot of work I know, but if the scripts aren't working for you, this is a way around that. If you have alot of devices, which it seems that you do with 20, after you create all of the above events, putting them into their own group, say Device Holdings, then you can copy them and edit them as needed, if that makes it easier for you.

    HTH

    Comment


      #17
      Originally posted by Jakob.Sand View Post
      I tried the scrips without sucess.
      Will spend more time on this and get back.
      Thank you again for the feedback.
      Jakob,
      When you are ready, it will be helpful to get more specifics about what is and is not working. Where are you running into difficulty? Are you getting error messages? If so, at what point and what are they? Can you store the state information? Can you retrieve states, but not retore the physical devices to those states?
      Mike____________________________________________________________ __________________
      HS3 Pro Edition 3.0.0.548, NUC i3

      HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

      Comment


        #18
        Hi Michael,
        Thank you for offering help on this.

        I get no errors. I tested with 3 devices "For 0 to 2".
        When I ran the script for savestate no errors, but when I ran the restore nothing was restored either.
        Will send you my scripts later. (A bit busy the next couple of days.).
        Best,
        Jakob Sand, I automate everything!

        Comment


          #19
          Jakob,
          After you ran the restore script, did you look at the new status values? My guess, is that, as written, the status of the HS devices probably changed, but that was not sufficient to actually turn on the physical devices.

          I think the place to start is to identify what you need to do to have HS turn on each of your devices, independent of this exercise. (I'm assuming you have HS events that you use to turn each of the devices off and on. If you do not, then that will be a necessary first step.)

          Warning: As I said in my post with the scripts, they are a start, but it is likely to get a bit more complex now. In at least some cases, you may have to execute commands targeted to specific devices to change their physical on/off state.
          Mike____________________________________________________________ __________________
          HS3 Pro Edition 3.0.0.548, NUC i3

          HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

          Comment


            #20
            In status view, I can by clicking at the buttons ON and OFF change the device state. Ie. any event etc. that changes that device "Status" from ON to OFF will turn the lamps OFF.

            This is what I did:
            0. I turned on the lamp with device code ^4 also part of the script. The Status field changed to ON, and I can see light in the bulp :-)
            1. I run the script manually in the event I have created
            2. I turned OFF the lamp manually via the status view in HS
            3. I ran the retrievestate.vb manually
            4. Nothing chanced on the bulp.
            5. The status of the device in HS Status view did not change.
            Best,
            Jakob Sand, I automate everything!

            Comment


              #21
              Jakob,
              What you are seeing is consistent with my suspicion. We're going to have to modify the retrieve script a bit. There are many ways to accomplish any task, but two come to mind right now. One is a bit quicker to start, but will be messy. The other will take a little more work up front, but will probably be easier to maintain. I'd prefer the second.

              Caveat: I do not do anything exactly like this myself, so I cannot guarantee that it will work as I imagine it, but with some effort, a workable solution should emerge.

              The first step is to create a HS event for each device that you want to turn on. These can have manual triggers if you have no other use for them, or they can be triggered by any means you choose, at your option. Most will be fairly simple, with single actions. It will help if the events have short, easily identifiable names.

              The next step will be to insert a line in the script that will trigger the required events for the devices you want to turn on. I'll put that in another post.

              To make this as easy to follow as possible, it would be useful to use the actual device codes for the three devices in your test and the names of the events that turn them on. That way, we can use concrete examples. Let me know if that is ok with you. If so, please post them.
              Mike____________________________________________________________ __________________
              HS3 Pro Edition 3.0.0.548, NUC i3

              HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

              Comment


                #22
                here is the codes for the 3 devices and I will call the events the same.
                ^4", "^24", "^22
                Best,
                Jakob Sand, I automate everything!

                Comment


                  #23
                  Jacob,
                  Here is my next cut with a modified retrieve script. There are just a few changes. I've added a second array with the event names. (I hope I've interpreted your last post correctly on these names. If I didn't please substitute the names you actually gave to the events.)

                  The only other changes are in the loop. Instead of updating the device status, which didn't have any effect, I'm asking HS to trigger the events that actually turn on the physical devices.

                  I've also added a couple of lines that insert the retrieved data into the HS log. You can either delete those lines or put a ' in front of them to turn them into comments if you want to stop the extra lines in the log.

                  Code:
                  Sub Main(ByVal Params As Object)
                  
                          '                                                   List of the Device Codes for all devices to restore (identical to list in the Save script)
                          Dim strSensor_addr() As String = {"^4", "^24", "^22"}
                          Dim strOnEvent() As String = {"^4", "^24", "^22"} ' List of the names of the events used to turn these devices on
                          Dim I As Integer
                          Dim intDStatus As Integer
                          Dim strAddr As String
                          Dim strFileName As String
                          Dim strApPath As String
                          Dim strTemp As String
                  
                         ' Find the file
                          strApPath = hs.GetAppPath() & "\"
                          strFileName = strApPath & "SavedState.txt"
                          
                          Dim FS As New System.IO.FileStream(strFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)
                          Dim sReader As New System.IO.StreamReader(FS)
                  
                          ' Read past time stamp
                          sReader.ReadLine
                  
                          ' Reset each device
                          For I = 0 To 2
                              strTemp = sReader.ReadLine
                              strAddr = strSensor_addr(I)        ' debug
                              hs.WriteLog(strAddr, strTemp)        ' debug
                  
                              If strTemp = "2" Then            '  This device was on, turn it back on
                                   hs.TriggerEventAndWait(strOnEvent(I))
                              End If
                  
                          Next 'I
                  
                          ' Close the file
                          sReader.Close()
                          FS = Nothing
                  
                      End Sub
                  I'm not sure it is necessary to wait for each event to finish, but that seems the safest place to start. (hs.TriggerEvent does the same thing, but the script doesn't wait for each event to finish.)
                  Mike____________________________________________________________ __________________
                  HS3 Pro Edition 3.0.0.548, NUC i3

                  HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

                  Comment


                    #24
                    Jacob, you may be interested in the attached scripts.

                    Rather than specify the devices, all devices within a specified location are captured and restored. The "StoreDevice" is run to capture the state of all devices within a location. The "RestoreDevice" is used to restore the captured state of "StoreDevice".

                    Change the file extention to .vb

                    Code:
                    '10-15-08 Script to save and restore the state of devices. Works on specific device locations
                     
                    sub StoreDevice(parm as object)
                    Dim x as integer = 1
                    Dim en as object = hs.GetDeviceEnumerator()
                    Dim dv as object
                    Dim DeviceArrayTemp(hs.DeviceCount(),5) as string
                    'Array: DevName   HC DC    Status DimValue
                    ' Enumerate the devices, gather required info and place in array
                    do While Not en.Finished
                     dv = en.GetNext
                     if dv.location = parm then
                      DeviceArrayTemp(x,1) = dv.name
                       DeviceArrayTemp(x,2) = dv.hc
                      DeviceArrayTemp(x,3) = dv.dc
                      DeviceArrayTemp(x,4) = hs.DeviceStatus(dv.hc & dv.dc)
                      if DeviceArrayTemp(x,4) = "4" then DeviceArrayTemp(x,5) = hs.DeviceValue(dv.hc & dv.dc)
                      x=x+1
                     end if
                    loop
                     
                    Dim DeviceStatusArray(x-1,5) as string
                    'compress array
                    Array.Copy(DeviceArrayTemp, DeviceStatusArray, x*6)
                    'store out array for use later
                    hs.CreateVar("DeviceStatusArray")
                    hs.SaveVar("DeviceStatusArray",DeviceStatusArray)
                    end sub
                     
                    sub RestoreDevice(parm as object)
                    Dim x as integer
                    Dim DeviceStatusArray as array
                    Dim UpperBound as integer
                    Dim CurrentStatus as integer
                    Dim CurrentDimLevel as integer
                    DeviceStatusArray = hs.GetVar("DeviceStatusArray")
                    UpperBound = UBound(DeviceStatusArray)
                    for x=1 to UpperBound
                    CurrentStatus = hs.DeviceStatus(DeviceStatusArray(x,2) & DeviceStatusArray(x,3))
                    CurrentDimLevel = hs.DeviceValue(DeviceStatusArray(x,2) & DeviceStatusArray(x,3))
                    if CurrentStatus <> cint(DeviceStatusArray(x,4)) then
                    ' hs.writelog("SaveRestore","Restoring device " & DeviceStatusArray(x,1) & " to it's previous state")
                     if cint(DeviceStatusArray(x,4)) = 2 then hs.ExecX10NoLog(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "on", 0, 0)
                     if cint(DeviceStatusArray(x,4)) = 3 then hs.ExecX10NoLog(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "off", 0, 0)
                     if cint(DeviceStatusArray(x,4)) = 4 then hs.ExecX10NoLog(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "dim",DeviceStatusArray(x,5), 0)
                    elseif CurrentStatus = cint(DeviceStatusArray(x,4)) and CurrentDimLevel <> cint(DeviceStatusArray(x,5)) then
                     hs.ExecX10NoLog(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "dim", DeviceStatusArray(x,5), 0)
                    end if
                    next
                    end sub




                    -Ron
                    Attached Files

                    Comment


                      #25
                      Added Flexibility

                      Updated script to allow multiple locations to be saved and restored.

                      Save example:
                      SaveRestoreDevices.vb("StoreDevice","Downstairs")
                      SaveRestoreDevices.vb("StoreDevice","1st Floor")
                      SaveRestoreDevices.vb("StoreDevice","Upstairs")
                      SaveRestoreDevices.vb("StoreDevice","Outside")

                      Restore example:
                      SaveRestoreDevices.vb("RestoreDevice","Downstairs")
                      SaveRestoreDevices.vb("RestoreDevice","1st Floor")
                      SaveRestoreDevices.vb("RestoreDevice","Upstairs")
                      SaveRestoreDevices.vb("RestoreDevice","Outside")

                      I use the scripts for the following:
                      - Capture state of lights before activating security/fire lighting, then restore when alarm is reset.
                      - Capture state of lights before entering a party scene, then restore after party

                      Also fixed a bug.

                      -Ron

                      Code:
                      '10-15-08 Script to save and restore the state of devices. Works on specific device locations
                       
                      sub StoreDevice(parm as object)
                      Dim y as integer
                      Dim x as integer = 1
                      Dim en as object = hs.GetDeviceEnumerator()
                      Dim dv as object
                      Dim DeviceArrayTemp(hs.DeviceCount(),5) as string
                      'Array: DevName   HC DC    Status DimValue
                      ' Enumerate the devices, gather required info and place in array
                      do While Not en.Finished
                       dv = en.GetNext
                       if dv.location = parm then
                        DeviceArrayTemp(x,1) = dv.name
                         DeviceArrayTemp(x,2) = dv.hc
                        DeviceArrayTemp(x,3) = dv.dc
                        DeviceArrayTemp(x,4) = hs.DeviceStatus(dv.hc & dv.dc)
                        if DeviceArrayTemp(x,4) = "4" then DeviceArrayTemp(x,5) = hs.DeviceValue(dv.hc & dv.dc)
                        x=x+1
                       end if
                      loop
                      'for y=1 to x-1
                      'hs.writelog("info","name:" & DeviceArrayTemp(y,1) & "HC:" & DeviceArrayTemp(y,2) & "DC:" & DeviceArrayTemp(y,3) & "Stat:" & DeviceArrayTemp(y,4) & "dim:" & DeviceArrayTemp(y,5))
                      'next
                       
                      Dim DeviceStatusArray(x-1,5) as string
                      'compress array
                      Array.Copy(DeviceArrayTemp, DeviceStatusArray, x*6)
                      'store out array for use later
                      hs.CreateVar(parm & "DeviceStatusArray")
                      hs.SaveVar(parm & "DeviceStatusArray",DeviceStatusArray)
                      end sub
                       
                      sub RestoreDevice(parm as object)
                      Dim x as integer
                      Dim DeviceStatusArray as array
                      Dim UpperBound as integer
                      Dim CurrentStatus as integer
                      Dim CurrentDimLevel as integer
                      DeviceStatusArray = hs.GetVar(parm & "DeviceStatusArray")
                      UpperBound = UBound(DeviceStatusArray)
                       
                      'for x= 1 to UpperBound
                      'hs.writelog("info","name:" & DeviceStatusArray(x,1) & "HC:" & DeviceStatusArray(x,2) & "DC:" & DeviceStatusArray(x,3) & "Stat:" & DeviceStatusArray(x,4) & "dim:" & DeviceStatusArray(x,5))
                      'next
                      for x=1 to UpperBound
                      CurrentStatus = hs.DeviceStatus(DeviceStatusArray(x,2) & DeviceStatusArray(x,3))
                      CurrentDimLevel = hs.DeviceValue(DeviceStatusArray(x,2) & DeviceStatusArray(x,3))
                      'hs.writelog("info",CurrentDimLevel)
                      if CurrentStatus <> cint(DeviceStatusArray(x,4)) then
                       hs.writelog("SaveRestore","Restoring device " & DeviceStatusArray(x,1) & " to it's previous state")
                       if cint(DeviceStatusArray(x,4)) = 2 then hs.ExecX10NoLog(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "on", 0, 0)
                       if cint(DeviceStatusArray(x,4)) = 3 then hs.ExecX10NoLog(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "off", 0, 0)
                       if cint(DeviceStatusArray(x,4)) = 4 then hs.ExecX10NoLog(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "dim",DeviceStatusArray(x,5), 0)
                      elseif CurrentStatus = cint(DeviceStatusArray(x,4)) and CurrentDimLevel <> cint(DeviceStatusArray(x,5)) and CurrentStatus = 4 then
                       hs.ExecX10(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "dim", DeviceStatusArray(x,5), 0)
                      end if
                      next
                      end sub

                      Comment


                        #26
                        Save and restore device

                        I saved the script into vb file and under optional i write ("RestoreDevice","test")
                        is for restoring the devices test.

                        i then created a simple virtual device with on and off state, and try to save and restore that - without luck.

                        any input?


                        Originally posted by basshook View Post
                        Updated script to allow multiple locations to be saved and restored.

                        Save example:
                        SaveRestoreDevices.vb("StoreDevice","Downstairs")
                        SaveRestoreDevices.vb("StoreDevice","1st Floor")
                        SaveRestoreDevices.vb("StoreDevice","Upstairs")
                        SaveRestoreDevices.vb("StoreDevice","Outside")

                        Restore example:
                        SaveRestoreDevices.vb("RestoreDevice","Downstairs")
                        SaveRestoreDevices.vb("RestoreDevice","1st Floor")
                        SaveRestoreDevices.vb("RestoreDevice","Upstairs")
                        SaveRestoreDevices.vb("RestoreDevice","Outside")

                        I use the scripts for the following:
                        - Capture state of lights before activating security/fire lighting, then restore when alarm is reset.
                        - Capture state of lights before entering a party scene, then restore after party

                        Also fixed a bug.

                        -Ron

                        Code:
                        '10-15-08 Script to save and restore the state of devices. Works on specific device locations
                         
                        sub StoreDevice(parm as object)
                        Dim y as integer
                        Dim x as integer = 1
                        Dim en as object = hs.GetDeviceEnumerator()
                        Dim dv as object
                        Dim DeviceArrayTemp(hs.DeviceCount(),5) as string
                        'Array: DevName   HC DC    Status DimValue
                        ' Enumerate the devices, gather required info and place in array
                        do While Not en.Finished
                         dv = en.GetNext
                         if dv.location = parm then
                          DeviceArrayTemp(x,1) = dv.name
                           DeviceArrayTemp(x,2) = dv.hc
                          DeviceArrayTemp(x,3) = dv.dc
                          DeviceArrayTemp(x,4) = hs.DeviceStatus(dv.hc & dv.dc)
                          if DeviceArrayTemp(x,4) = "4" then DeviceArrayTemp(x,5) = hs.DeviceValue(dv.hc & dv.dc)
                          x=x+1
                         end if
                        loop
                        'for y=1 to x-1
                        'hs.writelog("info","name:" & DeviceArrayTemp(y,1) & "HC:" & DeviceArrayTemp(y,2) & "DC:" & DeviceArrayTemp(y,3) & "Stat:" & DeviceArrayTemp(y,4) & "dim:" & DeviceArrayTemp(y,5))
                        'next
                         
                        Dim DeviceStatusArray(x-1,5) as string
                        'compress array
                        Array.Copy(DeviceArrayTemp, DeviceStatusArray, x*6)
                        'store out array for use later
                        hs.CreateVar(parm & "DeviceStatusArray")
                        hs.SaveVar(parm & "DeviceStatusArray",DeviceStatusArray)
                        end sub
                         
                        sub RestoreDevice(parm as object)
                        Dim x as integer
                        Dim DeviceStatusArray as array
                        Dim UpperBound as integer
                        Dim CurrentStatus as integer
                        Dim CurrentDimLevel as integer
                        DeviceStatusArray = hs.GetVar(parm & "DeviceStatusArray")
                        UpperBound = UBound(DeviceStatusArray)
                         
                        'for x= 1 to UpperBound
                        'hs.writelog("info","name:" & DeviceStatusArray(x,1) & "HC:" & DeviceStatusArray(x,2) & "DC:" & DeviceStatusArray(x,3) & "Stat:" & DeviceStatusArray(x,4) & "dim:" & DeviceStatusArray(x,5))
                        'next
                        for x=1 to UpperBound
                        CurrentStatus = hs.DeviceStatus(DeviceStatusArray(x,2) & DeviceStatusArray(x,3))
                        CurrentDimLevel = hs.DeviceValue(DeviceStatusArray(x,2) & DeviceStatusArray(x,3))
                        'hs.writelog("info",CurrentDimLevel)
                        if CurrentStatus <> cint(DeviceStatusArray(x,4)) then
                         hs.writelog("SaveRestore","Restoring device " & DeviceStatusArray(x,1) & " to it's previous state")
                         if cint(DeviceStatusArray(x,4)) = 2 then hs.ExecX10NoLog(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "on", 0, 0)
                         if cint(DeviceStatusArray(x,4)) = 3 then hs.ExecX10NoLog(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "off", 0, 0)
                         if cint(DeviceStatusArray(x,4)) = 4 then hs.ExecX10NoLog(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "dim",DeviceStatusArray(x,5), 0)
                        elseif CurrentStatus = cint(DeviceStatusArray(x,4)) and CurrentDimLevel <> cint(DeviceStatusArray(x,5)) and CurrentStatus = 4 then
                         hs.ExecX10(DeviceStatusArray(x,2) & DeviceStatusArray(x,3), "dim", DeviceStatusArray(x,5), 0)
                        end if
                        next
                        end sub
                        Best,
                        Jakob Sand, I automate everything!

                        Comment


                          #27
                          Originally posted by Rupp View Post
                          ........Oddly enough this is the first time I believe I've ever seen this request..
                          Sorry Rupp this has been discussed a little bit and in fact there was a script that would do exactly what is being requested.

                          I ran the script, and have searched for it on this BBS to no avail.

                          I think it was an HS1 script and surmise the post has been lost in the moves of this BBS. If I can find it in my archive I will re-post it, do not hold your breath. Interesting I still have the events, disabled, that ran it.

                          Give me some time, if the events are there then the script should also be.

                          It was based on if "the other half" fell asleap HS would turn off the lights, but as soon as movememnt was detacted they returned to there last setting, including turning the TV back on.
                          sigpic
                          A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"

                          Comment


                            #28
                            That would be fantastic.
                            I have the same and other needs like: saving the TV channel of my TV (a device) for later restore etc.


                            Originally posted by Gogs View Post
                            Sorry Rupp this has been discussed a little bit and in fact there was a script that would do exactly what is being requested.

                            I ran the script, and have searched for it on this BBS to no avail.

                            I think it was an HS1 script and surmise the post has been lost in the moves of this BBS. If I can find it in my archive I will re-post it, do not hold your breath. Interesting I still have the events, disabled, that ran it.

                            Give me some time, if the events are there then the script should also be.

                            It was based on if "the other half" fell asleap HS would turn off the lights, but as soon as movememnt was detacted they returned to there last setting, including turning the TV back on.
                            Best,
                            Jakob Sand, I automate everything!

                            Comment


                              #29
                              Happy New Year! I was searching for this script, and posted elsewhere trying to find it. This is exactly what I need. However, I do have one difference. If I have a light that is dimmed 40%, how do I save it at 40% and then restore it back to 40% again? It seems like it's is only saving On or Off. Also, where do I find a list of all the properties and methods for the hs control in VB? Can I use Visual Studio 2008 and use intellisense? I've been using notepad and have no idea of what other properties I can look for.

                              Thanks!

                              Comment

                              Working...
                              X