Announcement

Collapse
No announcement yet.

Every Script error, Have to restart HS3???

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

    Every Script error, Have to restart HS3???

    So I am trying to debug some simple scripts and on every error I have to re-start HS3 or I get the script can't start because it's already running.

    Example:
    Jan-06 3:15:51 PM Warning Not running script since its already running: C:/Program Files (x86)/HomeSeer HS3/scripts/Sonos-Volume-Test.vb Single instance option enabled in event properties
    Jan-06 3:15:51 PM Event Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/Sonos-Volume-Test.vb
    Jan-06 3:15:51 PM Event Event Trigger "Test Events Sonos Test Script"
    Jan-06 3:15:51 PM Event Event Test Events Sonos Test Script triggered by the event page 'Run' button.
    Jan-06 3:15:21 PM Warning VB.Net script exception(0), re-starting: Object reference not set to an instance of an object.

    This is what I am trying to run:

    Code:
    Public Sub Main()
    
        Dim value As Integer = 40
    
        Dim DeviceRef As Integer = hs.GetDeviceRefByName("Sonos Office Volume")
        Dim CurVol As Integer = hs.DeviceValue(DeviceRef)
    
        hs.writelog("Sonos Script", "Current Volume is: " & CurVol)
    
        If CurVol < 30 Then
            hs.SetDeviceValue(DeviceRef, value)
            hs.writelog("Sonos Script", "Volume set to: " & value)
        End If
    
    End Sub
    Thank for any help or comments.
    -Skybolt

    #2
    Does anyone else get these errors and have to re-start every time?

    I understand the error, but not having to re-start HS ...
    -Skybolt

    Comment


      #3
      Hi,
      on the tools, setup, general tab, would unchecking/checking "Enable Event Processing" stop the script? Its just a question as I'm not sure if this would work.

      Stuart

      Comment


        #4
        You might commenting out line by line to find the offending code. I wish I had better advice for you.
        Don

        Comment


          #5
          The "Enable Event Processing" is to stop HS from processing events. Mostly needed when start up problems occur. Unfortunately that doesn't help with scripting.

          The offending line is an issue with my Sonos system. That plug-in has always been a little finicky on my system.

          But the issue still remains, HS doesn't seem to timeout when running a script with an error. I gave it 24hrs and it still complains about the script still running. I can't believe that no-one else has encountered this problem by now. Just my luck though, makes debugging next to impossible.
          -Skybolt

          Comment


            #6
            Have you tried wrapping the script - or the offending lines - in a Try...Catch structure?
            Mike____________________________________________________________ __________________
            HS3 Pro Edition 3.0.0.548, NUC i3

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

            Comment


              #7
              Originally posted by Uncle Michael View Post
              Have you tried wrapping the script - or the offending lines - in a Try...Catch structure?
              No, I didn't know that work with scripts. Thanks, I'll give that a try.

              EDIT: Tried that and didn't change anything, bummer, nice thought though. Thanks.
              Last edited by skybolt; January 7, 2018, 06:40 PM.
              -Skybolt

              Comment


                #8
                You can uncheck "only allow a single instance of this script to run at a time" which will allow you to run more than one script. When you get it all sorted out then check it and restart homeseer so you don't have a bunch of scripts stuck in unfinished status.

                Comment


                  #9
                  I like this idea. I've been using an EasyTrigger action in the 1st event shown to toggle between volume levels 50-40-30. However this has some issues and I think the script approach should allow finer control.

                  Couple of things:
                  1) Had to change your hs.SetDeviceValue(devRef, vol) to hs.SetDeviceValueByRef(devRef, vol, False) instead. The first parameter to the former is the 'device code', not the device reference.
                  2) After that fix, the script properly set the volume device, but that doesn't actually make the volume change. Apparently CAPI controls are needed for that. I've seen where tenScriptingAid can help with this, but EasyTrigger came to my rescue - after the script completes, setting the volume device to itself did the trick!

                  I'm going to switch over to this and try it in action tomorrow morning...
                  Attached Files

                  Comment


                    #10
                    This is what I ended up with and it works great. Now when my wife turns sonos off by turning the volume down, this script fixes it.
                    The original code posted was to test for this error problem I am having. Very strange how HS deals with scripts.

                    Code:
                    Public Sub Main(ByVal Parms As Object)
                    
                    	Dim room_name as string = "Office"
                    	Dim value as integer = 40
                    
                    	Dim DeviceRefId as integer = hs.GetDeviceRefByName("Sonos " & room_name & " Volume")
                    	Dim CurVol as integer = hs.DeviceValue(DeviceRefId)
                    
                    	hs.writelog("Sonos Script", "Current Volume is: " & CurVol)
                    
                    	If CurVol < 30 Then
                    		Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(DeviceRefId, True, "Volume (value)%", False, False)
                    		cc.ControlValue = value
                    		Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                    		hs.writelog("Sonos Script", "Volume set to: " & value)
                    	End If
                    
                    End Sub
                    zwolf you could also check the "wait for script to finish ..." box instead of waiting a second. That might allow for system delays.
                    Last edited by skybolt; January 9, 2018, 07:25 AM.
                    -Skybolt

                    Comment

                    Working...
                    X