Announcement

Collapse
No announcement yet.

Multiple Subs in a script?

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

  • Multiple Subs in a script?

    I'm sure it is just my lack of understanding of the more modern .NET stuff, but I've been spending some time updating my UpdateEvent Script and I'm not finding the pattern that I need to use in order to make everything happy.

    Basically, I have 1 script file (maybe my first mistake?). That file under HS2 has 20+ functions and 10 or so subs, works without issue. Maybe my structure has always been wrong, but under HS2's lax script structure...everything seems AOK

    The Functions are just helpers for performing things like isBefore or similar, where I can just ask the question and the math is taken care of / True/False returned. I use that in making decisions in my updateEvent.vb file.

    The subs are representations of the rooms in my house. Used Subs as maintaining 1 script file per room was getting WAY too difficult to maintain, especially since they shared so much code (the updateEvent sub).

    In each sub, you can then customize it using simple if, then, else...what I really like is that I can copy/paste logic rather simply and easily. I'm not against the normal "programming" that HS uses through their webpage, but as a low level (gate level...below ASM), it frustrates me when I want to make quick simple changes...which would be a copy/paste/edit. Again, this was under HS2.

    By doing this, I tend to make the HS events VERY simple. Simply put, if I want the lights in my kitchen to go on when motion, but only after certain hours, I unequivocally call updateEvent.vb("kitchen","motion") at ANY time with a motion trigger.

    Thus, the kitchen sub is called, and the trigger type is motion. Then, I can do whatever I want with logic relating to time, deviceStatus, etc. Of course this was a simple example for the sake of explaining the reason for continuing to use updateEvent. Realistically, I found adding/understanding/using the conditionals in events really cumbersome. I think in HS3 it is better, but I've already got 2000 lines of code relating to how we want the house to function...I'd like to re-use that instead of reinventing things (greater WAF when things port without issues!).

    So, I played around for a while and THOUGHT I had everything figured out.
    Turns out - no.

    In HS2, the script would look like:
    Sub updateEvent(ByVal par as object)
    Sub kitchen(param as object)
    .
    .
    .
    within kitchen, after creating variables representing all the devices I wanted to work with, I had logic similar to this:
    if(param = "pictureFrame") then
    .
    .
    .

    In HS3, I currently have:
    Sub updateEvent(ByVal par as object)
    Sub kitchen(ByVal param as String) <--I tried object, but this is the last thing I had before getting frustrated)

    Which throws:
    Code:
    Jan-15 4:04:38 PM	 	Error 3	Running script C:\Program Files (x86)\HomeSeer HS3\scripts\updateEvent.vb :Exception has been thrown by the target of an invocation.->Does entry point kitchen exist in script? at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at A.c17b105f989efe61e5979e67bec1ef734.cffd66cb0782c50126727e3fa75582d7a()
    Jan-15 4:04:38 PM	 	Event	Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/updateEvent.vb("kitchen","cabinet")
    Jan-15 4:04:38 PM	 	Event	Event Trigger "My Test Events Test12 Kitchen"
    Jan-15 4:04:38 PM	 	Event	Event My Test Events Test12 Kitchen triggered by the event page 'Run' button.
    Any help is greatly appreciated...once I get this setup properly, where HS3 can call into this script, I gain 80+% of my HS3 ported over. I can't even create all my events until this is worked out, as my events are REALLY simple - just call into updateEvent with parameters (which might be where I am goofing up).

    --Dan
    Tasker, to a person who does Homeautomation...is like walking up to a Crack Treatment facility with a truck full of 3lb bags of crack. Then for each person that walks in and out smack them in the face with an open bag.

  • #2
    Hi Dan,

    Here's a simple example that works:

    Code:
    Sub Main(ByVal Parms As String)
    	hs.writelog("Main",Parms)
    end sub
    
    Sub Log1(Testing As String)
    	hs.writelog("Log1",Testing)
    End Sub
    
    Sub Log2(Testing As String)
    	hs.writelog("Log2",Testing)
    End Sub
    Click image for larger version

Name:	Capture.jpg
Views:	1
Size:	16.6 KB
ID:	1188560

    Code:
    Jan-15 2:45:00 PM	 	Log1	Write this to the log
    Jan-15 2:45:00 PM	 	Event	Running script in background: C:/program files (x86)/homeseer hs3/scripts/test.vb("Log1","Write this to the log")
    Hope that helps. I've seen that same error if there's something else wrong in the script, so it could be another issue.

    Cheers
    Al
    HS 3.0.0.548: 1976 Devices 1156 Events
    Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

    Comment


    • #3
      Al,

      Thanks again!
      Maybe you should come here and just set everything up for me?!

      Anyway, what I found out was causing my issues.
      Following your advice, I simplified my script to 3 subs. Then started to test. The short is, I would be editing the script, and then I would update the event (to call a different sub, or employ a different parameter). After updating the event, HomeSeer was overwriting the .vb file with it's cached version (whatever is shown in the script editing window). Anyway, what was happening was that overwrite and my changes (separate editor) were not getting "in there". At least now I know what is going on with that...do NOT edit the event AND the .vb file at the same time!

      That "error" message was really misleading...but I think I can't totally blame HS as it was doing what it thought it was supposed to be doing.

      So, I'll setup a few more events for testing then NOT TOUCH.

      Time to finish building up the updateEvent! Wherever would I be without you guiding me?!

      --Dan
      Tasker, to a person who does Homeautomation...is like walking up to a Crack Treatment facility with a truck full of 3lb bags of crack. Then for each person that walks in and out smack them in the face with an open bag.

      Comment


      • #4
        LOL. I went through one migration, don't think I want to do another one . Glad you got it working!

        Cheers
        Al
        HS 3.0.0.548: 1976 Devices 1156 Events
        Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

        Comment

        Working...
        X