Announcement

Collapse
No announcement yet.

C# scripting question for InitialState.com graphing

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

  • C# scripting question for InitialState.com graphing

    I'm trying to get InitialState.com graphs working using my HS3 Zee S2 (which is linux and thus doesn't have vb) plus it would seem that C# is much faster on linux anyway.

    So I have a simple Immediate script event triggered every time the temperature of a device changes.
    But I can't get the script to work.

    I get the following error:

    Code:
    Dec-31 10:06:04	 	Error	Running C# script statement: {interactive}(10,145): error CS0103: The name `fhs' does not exist in the current context {interactive}(10,149): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(10,7): error CS1502: The best overloaded method match for `Scheduler.hsapplication.URLAction(string, string, string, string)' has some invalid arguments {interactive}(5,17): warning CS0414: The private field `Script.hs' is assigned but its value is never used
    Dec-31 10:06:04	 	SCRIPT	hs.URLAction("https://groker.initialstate.com/api/events?accessKey=removed&bucketKey=removed","POST","FRTemp="&fhs.DeviceValueEx(403),"");
    Dec-31 10:06:04	 	Event	Running script statement immediately: &shs.URLAction("https://groker.initialstate.com/api/events?accessKey=removed&bucketKey=removed","POST","FRTemp="&fhs.DeviceValueEx(403),"");
    I removed my keys from the script for privacy.

    The problem is that the "FRTemp="&fhs.DeviceValueEx(403) isn't being recognized as a function call within the call to the URLAction.

    Is there a trick or some quoting or something I need to wrap around it?

  • #2
    Couple of things.

    Note, you can use vb.net on the Zee, its slow the first time its run, but after that it will be quick since it will be compiled.

    The "f" in "fhs" tells the system that its a function and it should handle a return value. In this case you don't care what the return value is, so change that to "shs". This says its a sub.

    In the URLAction string you have:

    FRTemp="&fhs.DeviceValueEx(403)

    You are missing a " at the end.

    But, script statements cannot be used inside a function call, its just used to call the entire function. So in this case, just make the call normally like:

    hs.DeviceValueEx(403)

    You don't need the FRTemp since the call will return the value and pass it as a parameter.

    If this is still not working, I would turn it into a .cs script, would be easier to debug like:

    get_temp.cs:

    public Object Main(Object[] parm)
    {
    int frtemp;

    frtemp = hs.DeviceValueEx(403);

    hs.URLAction("https://groker.initialstate.com/api/events?accessKey=removed&bucketKey=removed","POST",frtemp,"" );
    }



    Originally posted by DrZWave View Post
    I'm trying to get InitialState.com graphs working using my HS3 Zee S2 (which is linux and thus doesn't have vb) plus it would seem that C# is much faster on linux anyway.

    So I have a simple Immediate script event triggered every time the temperature of a device changes.
    But I can't get the script to work.

    I get the following error:

    Code:
    Dec-31 10:06:04	 	Error	Running C# script statement: {interactive}(10,145): error CS0103: The name `fhs' does not exist in the current context {interactive}(10,149): error CS0023: The `.' operator cannot be applied to operand of type `' {interactive}(10,7): error CS1502: The best overloaded method match for `Scheduler.hsapplication.URLAction(string, string, string, string)' has some invalid arguments {interactive}(5,17): warning CS0414: The private field `Script.hs' is assigned but its value is never used
    Dec-31 10:06:04	 	SCRIPT	hs.URLAction("https://groker.initialstate.com/api/events?accessKey=removed&bucketKey=removed","POST","FRTemp="&fhs.DeviceValueEx(403),"");
    Dec-31 10:06:04	 	Event	Running script statement immediately: &shs.URLAction("https://groker.initialstate.com/api/events?accessKey=removed&bucketKey=removed","POST","FRTemp="&fhs.DeviceValueEx(403),"");
    I removed my keys from the script for privacy.

    The problem is that the "FRTemp="&fhs.DeviceValueEx(403) isn't being recognized as a function call within the call to the URLAction.

    Is there a trick or some quoting or something I need to wrap around it?
    website | buy now | support | youtube

    Comment


    • #3
      C# scripting question for InitialState.com graphing - SOLVED!

      SOLVED!

      The Immediate script looks like this:
      &sdouble frtemp;frtemp=hs.DeviceValueEx(403);hs.URLAction("https://groker.initialstate.com/api/events?accessKey=REMOVED&bucketKey=REMOVED","POST","FRTemp=" +frtemp.ToString(),"");

      The trick is that you cannot embed one routine inside another.
      But you can make them multi-line using ;
      So assign the DeviceValueEx to a double, then convert that to a string and then finally append it to the other string for the InitialState URL.

      In the morning I'll post the graph which will have some data in it (I hope!).
      Last edited by DrZWave; January 1st, 2017, 04:27 PM.

      Comment


      • #4
        Here is the promised graph. Very easy to do. Nice looking graphs. Nice UI. I am disappointed that HST doesn't offer this by default. I've been asking for it since I starting using it way back in the olden days but RJH says there aren't enough people asking for it so he's working on other things. He has all the infrastructure from the energy monitoring so it wouldn't be too hard.

        What I want is a simple checkbox that says - yes, put this device on the graphs page. Copying an event and changing the Device trigger and the device # isn't hard but takes a couple minutes per device.

        InitialState.com makes money by selling you their "upgrade plans".
        Free gets you 24hrs of data and as many devices as you want. For me this is sufficient. There is a limit of 25k updates/mo but I won't come close to that.
        $60/yr gets you all the data you can push up on their servers.
        Then there is a "pro" plan but I wasn't interested in that.
        Attached Files

        Comment


        • #5
          Hmmm... Looks like there might be a memory leak in the C# scripting engine.
          My Zee S2 has been very reliable.
          Until I put these C# Immediate scripts in and now it appears to crash after about 36 hours.
          I'm watching it closely right now so we'll see in the morning.

          Comment


          • #6
            Memory leak confirmed for C# scripting.

            This is a known issue and there was already a Bugzilla bug reported and I added to it:
            http://bugzilla.homeseer.com/bugzill...ug.cgi?id=2558

            Hopefully HST can fix it now that I've given them an easy method to reproduce it.

            Comment


            • #7
              C# leak fixed in HS3 build 3.0.0.306. I have only posted the ZEE S2 build for now. If all looks good I will post the others.

              To update, go into Setup and click on the Beta Update button.
              website | buy now | support | youtube

              Comment


              • #8
                Not quite - the memory leak still exists if the C# script is an immediate one.
                RJH believes it is fixed if the script has been compiled.
                I updated the Bugzilla ticket with this info.

                But I can't figure out how to convert my immediate script into a full script file.
                How do I pass in parameters?
                The script examples never use any parameters - just write a value to the log.

                The script will look something like:
                public void Main(object[] param) {
                double frtemp;
                frtemp=hs.DeviceValueEx(param[0]);
                hs.URLAction("https://groker.initialstate.com/api/events?accessKey=xxx&bucketkey=" + param[1],"POST", param[2] + "=" + frtemp.ToString(),"");
                }

                but this isn't even close - how do I get the parameters? I'm not a C# programmer which is why the simple immediate script worked OK for me. I can write 3 lines of code (on 1 line).

                Comment


                • #9
                  You cannot pass parameters from the event config, if that is what you are trying to do. I assume the "bucketkey" is just a fixed value? Just include it in the script. You will need a different script if the bucket key changes for other calls, just copy the script and change those values.
                  website | buy now | support | youtube

                  Comment


                  • #10
                    If you can't pass in parameters, why do you have them?

                    I was hoping to have 1 script that I can reuse for every device.
                    That's the purpose of having a script in the first place - reusability.

                    I would pass in the device RefID and the name and the script would use those values.

                    Please look over this script and help me with the correct syntax.
                    Attached Files

                    Comment


                    • #11
                      I was wrong, you can use the parameters box in the event action. However, you can only add one parameter. So enter your parameters and use a string seperator, like a comma. For example, you can enter:

                      hello,1234

                      As your 2 parameters.

                      Now in the script, extract them and then pass them to your function:

                      String parms = (String)Parms[0]; // get the passed parameter seperated by a comma
                      String P1 = parms.Split(',')[0]; // get the first parameter
                      String P2 = parms.Split(',')[1]; // get the second
                      website | buy now | support | youtube

                      Comment


                      • #12
                        My script is now:
                        Code:
                        public void Main(object[] Parms) {
                        String parms = (String)Parms[0]; // get the passed parameter seperated by a comma
                        String P1 = parms.Split(',')[0]; // get the Device ID#
                        String P2 = parms.Split(',')[1]; // get the label for the device
                        String P3 = parms.Split(',')[2]; // get the InitialStateBucket
                        double frtemp;
                        int DeviceRef=Convert.ToInt32(P1);
                        frtemp=hs.DeviceValueEx(DeviceRef);
                        hs.URLAction("https://groker.initialstate.com/api/events?accessKey=xxx&bucketkey=" + P3,"POST", P2 + "=" + frtemp.ToString(),"");
                        }
                        but I get a ton of errors in the log and it won't compile.
                        Complains there are multiple Convert.ToInt32 defined???

                        Compiling script /usr/local/HomeSeer/scripts/InitialState.cs: {interactive}(13,1): error CS0433: The imported type `string' is defined multiple times {interactive}(23,15): error CS0433: The imported type `System.Convert' is defined multiple times Internal(1,1):

                        Comment


                        • #13
                          Still using this?

                          Originally posted by DrZWave View Post
                          My script is now:
                          Code:
                          public void Main(object[] Parms) {
                          String parms = (String)Parms[0]; // get the passed parameter seperated by a comma
                          String P1 = parms.Split(',')[0]; // get the Device ID#
                          String P2 = parms.Split(',')[1]; // get the label for the device
                          String P3 = parms.Split(',')[2]; // get the InitialStateBucket
                          double frtemp;
                          int DeviceRef=Convert.ToInt32(P1);
                          frtemp=hs.DeviceValueEx(DeviceRef);
                          hs.URLAction("https://groker.initialstate.com/api/events?accessKey=xxx&bucketkey=" + P3,"POST", P2 + "=" + frtemp.ToString(),"");
                          }
                          but I get a ton of errors in the log and it won't compile.
                          Complains there are multiple Convert.ToInt32 defined???

                          Compiling script /usr/local/HomeSeer/scripts/InitialState.cs: {interactive}(13,1): error CS0433: The imported type `string' is defined multiple times {interactive}(23,15): error CS0433: The imported type `System.Convert' is defined multiple times Internal(1,1):
                          Hi DrZWave, I too any using Linux for my HS server and am fairly new to HS having moved from a small Vera box before which to be fair I had only used for a few months since I moved into the current house. Did you end up still using your existing script with statically defined values? I've just used the same to get me up and running in InitialState.

                          In case anyone else is looking for a quick copy/paste thats:
                          &sdouble thingtemp;thingtemp=hs.DeviceValueEx(DEVICENUMBER);hs.URLAct ion("https://groker.initialstate.com/api/events?accessKey=ACCESSKEYHERE&bucketKey=BUCKETKEYHERE","POS T","ThingTemp=" +thingtemp.ToString(),"");

                          Where thingtemp, DEVICENUMBER, ACCESSKEYHERE and BUCKETKEYHERE are changed

                          Thanks
                          Mark

                          Comment

                          Working...
                          X