Announcement

Collapse
No announcement yet.

Script to run an event only when a device is on?

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

    Script to run an event only when a device is on?

    Hey there clever coders. I need some help writing a script to run an event but only when a specific device is on. The way I'm calling the event the event conditions aren't respected. Or actually maybe everything could just be tossed into one script and the event could be ditched. My event sends a command to Media Player Classic on my desktop to pause or play. So for example to pause MPC I just run an immediate script command like so: &hs.geturl "192.168.1.2", "/command.html?wm_command=888", False, 13579. I have virtual devices for paused and playing that are controlled by EventGhost. So I need to be able to send the above command but only if the EventGhost controlled virtual device for MPC playing is on. Make sense?

    EDIT:

    Will this do it?

    Code:
    Sub Main(params as object)
    
     Dim MPC On As Boolean = hs.IsOn(hs.DeviceExistsCode("\624"))
    
     If MPC On = True then
        &hs.geturl "192.168.1.2", "/command.html?wm_command=888", False, 13579
     End if
    
    End Sub

    EDIT 2:

    Nope. Doesn't work. Is there a complete idiot's guide to HS3 scripts?
    Last edited by S-F; February 10, 2016, 02:49 PM.
    Originally posted by rprade
    There is no rhyme or reason to the anarchy a defective Z-Wave device can cause

    #2
    Not sure if this will help you, and I am not a coder at all either. I built this script to display the time on my russound keypads when the zone is off. It checks if a zone is off, and then runs a command. Its similar to what you are wanting to do, check a device and do something if its true
    Code:
    Sub Main(ByVal parm As Object)
    'Device for Time
    DIM Time = (hs.DeviceString(218))
    DIM Temp = (hs.DeviceValue(864))
    'Power Status for Each Panel
    DIM Kitchen_Panel = (hs.DeviceValue(525)) 'Device 2
    DIM Bathroom_Panel = (hs.DeviceValue(564)) 'Device 5
    DIM Loft_Panel = (hs.DeviceValue(551)) 'Device 4
    DIM Outside_Panel = (hs.DeviceValue(538)) 'Device 3
    
    If Kitchen_Panel = 0 Then
        hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,2,Time,"Center",0})
    End If
    If Bathroom_Panel = 0 Then
        hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,5,Time,"Center",0})
    End If
    If Loft_Panel = 0 Then
        hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,4,Time,"Center",0})
    End If
    If Outside_Panel = 0 Then
        hs.PluginFunction("BLRussound", "", "SendMessageZone", {1,3,Time,"Center",0})
    End If
    End Sub

    Comment


      #3
      Also I don't think you can do dim MPC On (because of the space), maybe do MPC_On

      Comment


        #4
        Here's where I'm at now, and it's not working:


        Code:
        Sub Main(ByVal parm As Object)
            Dim MPC_On = (hs.DeviceValue(624))
            
            If MPC_On = 100 Then
                hs.geturl "192.168.1.145", "/command.html?wm_command=888", False, 13579
            End If
        
        End Sub
        Originally posted by rprade
        There is no rhyme or reason to the anarchy a defective Z-Wave device can cause

        Comment


          #5
          Hmmm... that looks right to me. Do you get an error in the logs if you manually try to run the event?

          Comment


            #6
            Well crap, i should read your whole post. You are wanting a script that watches for a device change and then do something when that device changes. My script I just run a reoccurring event every minute to update the time on the displays, so my idea won't work for you I don't think.

            Comment


              #7
              Originally posted by S-F View Post
              Here's where I'm at now, and it's not working:


              Code:
              Sub Main(ByVal parm As Object)
                  Dim MPC_On = (hs.DeviceValue(624))
                  
                  If MPC_On = 100 Then
                      hs.geturl "192.168.1.145", "/command.html?wm_command=888", False, 13579
                  End If
              
              End Sub
              Geturl is going to need surrounding with brackets because it is .net, also check the log for errors that may explain what is wrong...

              Comment


                #8
                Originally posted by waynehead99 View Post
                Well crap, i should read your whole post. You are wanting a script that watches for a device change and then do something when that device changes. My script I just run a reoccurring event every minute to update the time on the displays, so my idea won't work for you I don't think.

                No you had it right originally. I want to manually run the script, if device 624 is on then I want to send that command.
                Originally posted by rprade
                There is no rhyme or reason to the anarchy a defective Z-Wave device can cause

                Comment


                  #9
                  New (geturl) version

                  Code:
                  Sub Main(ByVal parm As Object)
                      Dim MPC_On = (hs.DeviceValue(624))
                      
                      If MPC_On = 100 Then
                          hs.(geturl) "192.168.1.145", "/command.html?wm_command=888", False, 13579
                      End If
                  
                  End Sub

                  Error:

                  Code:
                  Feb-10 3:46:51 PM      Error    Compiling script C:\Program Files (x86)\HomeSeer  HS3\scripts\Pause_MPC.vb: 'geturl' is not declared. It may be  inaccessible due to its protection level.        Feb-10 3:46:51 PM      Error    Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Pause_MPC.vb: Identifier expected.        Feb-10 3:46:51 PM      Error    Compiling script C:\Program Files (x86)\HomeSeer  HS3\scripts\Pause_MPC.vb: Namespace or type specified in the Imports  'System.Core' doesn't contain any public member or cannot be found. Make  sure the namespace or the type is defined and contains at least one  public member. Make sure the imported element name doesn't use any  aliases. 
                  Originally posted by rprade
                  There is no rhyme or reason to the anarchy a defective Z-Wave device can cause

                  Comment


                    #10
                    on a different script i have this geturl to control my heater

                    hs.GetURL("10.0.254.204","/api/1/hold?activity=manual&hold=on",FALSE,3000)

                    Comment


                      #11
                      Originally posted by waynehead99 View Post
                      on a different script i have this geturl to control my heater

                      hs.GetURL("10.0.254.204","/api/1/hold?activity=manual&hold=on",FALSE,3000)

                      Ah ha! Fantastic! I had hs.(geturl). I put the parentheses in the wrong place. Thanks for the example. It's all working like a charm now.
                      Originally posted by rprade
                      There is no rhyme or reason to the anarchy a defective Z-Wave device can cause

                      Comment

                      Working...
                      X