HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Help => Topic started by: bkenobi on May 15, 2014, 05:36:19 AM

Title: C# documentation
Post by: bkenobi on May 15, 2014, 05:36:19 AM
There was a page that showed all the methods and whatnot in a list broken up by module (or something like that).  I can't find the link now and it doesn't appear to be linked to the homegenie.it/docs page.  I think it was on http://generoso.info (http://generoso.info) somewhere.  Any idea where that went?

I'm trying to figure out where UpdateTime can be used, currently.  I'll need that page in the future surely, but that'sthe main thing right now.
Title: Re: C# documentation
Post by: bkenobi on May 15, 2014, 05:45:19 AM
I think the page was off of

http://generoso.info/homegenie/learn.html (http://generoso.info/homegenie/learn.html)

It looks like this now redirects to the main homegenie.it site, though.
Title: Re: C# documentation
Post by: dutchie on May 16, 2014, 06:53:44 PM
I think it's gone for now. Maybe in future (I hope in near future  ;)) it will be here:
http://www.homegenie.it/docs_api/index.html (http://www.homegenie.it/docs_api/index.html)
Title: Re: C# documentation
Post by: bkenobi on May 16, 2014, 07:42:19 PM
That's where I was reviewing.  Looks like the page that used to contain all the methods and whatnot is lost for now.  Hope Gene can bring it back soon as I could really use it!
Title: Re: C# documentation
Post by: dutchie on May 16, 2014, 08:46:45 PM
I hope so too.
Gene stated somewhere else he's not a fan of writing docs  :'(

Right now struggling through Visual Studio and Google (wish I knew how to prgram)
Title: Re: C# documentation
Post by: bkenobi on May 27, 2014, 05:31:32 PM
Is there a property that holds the last activity of a module?  I have a motion sensor that works great, but the X10 signal can occasionally not reach the controller.  The module transmits via PLC and for whatever reason it doesn't get the signal to the controller every time.  I've done everything I can and it's up to 95-99%, but that's the best it will be.

So, what I need to do is check for the motion sensor being stuck in the ON position in the code.  The Advanced Smart Lights code I am working on tracks the last 2 instances of ON/OFF.  If I use the same motion sensor for multiple instances of this code, it gets confused.  The solution would really be to just check when the last time the MODULE was triggered rather than the last time the code saw it trigger.

If there is no property for this, I suppose I could write a code to track this and turn it off if it's been on for too long.  Just thinking it might be nice if I could access the last activity time like:

Modules.WithAddress("A1").UpdateTime
Title: Re: C# documentation
Post by: bkenobi on May 28, 2014, 07:28:56 AM
I think this is a little clunky without the UpdateTime field on each module, but it does seem to work.  I suppose it could be added to the user contributions thread, but I don't know it's that useful.
Title: Re: C# documentation
Post by: Gene on May 28, 2014, 09:28:33 AM
Hi Ben,

you can try:

Code: [Select]
var mySensor = Modules.WithName("My Sensor");
var currentUpdate = mySensor.Parameter("Sensor.MotionDetect").UpdateTime;
var previousUpdate = mySensor.Parameter("Sensor.MotionDetect").LastUpdateTime;

these are returning a DateTime object (UTC format) you could use for the purpose.

g.
Title: Re: C# documentation
Post by: bkenobi on May 28, 2014, 04:44:07 PM
Yeah, that will definitely help!  Is there a way to know what the previous value was?

Code: [Select]
var mysensor = Modules.WithName("My Sensor");
var currentevent= mysensor.Parameter("Sensor.MotionDetect").Value;
var currenteventUpdate= mysensor.Parameter("Sensor.MotionDetect").UpdateTime;
var lastevent= mysensor.Parameter("Sensor.MotionDetect").LastValue;
var lasteventUpdate= mysensor.Parameter("Sensor.MotionDetect").LastUpdateTime;

If so, my Advanced Smart Lights code could be simplified, too.  I'll try tonight when I get back to my Raspi, but knowing the correct syntax would help reduce development time.
Title: Re: C# documentation
Post by: bkenobi on May 28, 2014, 06:34:54 PM
I just searched the readme and found the entry for 0.96 alpha:

Code: [Select]
22/03/2013 0.96 alpha
...
- added UpdateTime, LastValue, LastUpdateTime and ValueIncrement to Module data class

So I've got my answer.
Title: Re: C# documentation
Post by: Gene on May 28, 2014, 06:48:59 PM
Right,

you can find more insight by looking at the source code:

https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Data/ModuleParameter.cs

Cheers,
g.
Title: Re: C# documentation
Post by: bkenobi on May 28, 2014, 06:51:31 PM
That's exactly what I'm doing now.  Thanks!
Title: Re: C# documentation
Post by: bkenobi on May 29, 2014, 03:55:19 AM
Where in the code are the parameter types/values defined?  In other words, what parameters does the device type switch have?  I know the sensors have "sensor.MotionDetect" and "sensor.Level", but I'm not sure what Switches, Lights, Dimmers, etc. have.
Title: Re: C# documentation
Post by: bkenobi on May 30, 2014, 04:30:48 AM
In lieu of a response, I searched the code and found a file that contained a set of parameters that I think indicates that switch, light, dimmer, etc all use "status.level".  This worked for switch as expected.

I did run into an issue using LastValue with a C# defined parameter.  I can use the LastValue for HG coded parameters but it appears that they don't work for user code parameters.  Is that correct, or am I somehow using it wrong (it should work)?
Title: Re: C# documentation
Post by: bkenobi on May 30, 2014, 04:54:46 AM
I think I need help understanding some code in ModuleParameter.cs.

Code: [Select]
        public string Value
        {
            get
            {
                return parameterValue;
            }
            set
            {
                //TODO: find a better solution for "Meter.Watts" case
                //if (_value != value || Name == Properties.METER_WATTS || Name.StartsWith("ZWaveNode."))
                {
                    if ((!string.IsNullOrEmpty(parameterValue) && parameterValue != value)) // || Name == Properties.METER_WATTS || Name.StartsWith("ZWaveNode."))
                    {
                        LastValue = parameterValue;
                        LastUpdateTime = UpdateTime.ToUniversalTime();
                    }
                    UpdateTime = DateTime.UtcNow;
                    parameterValue = value;
                    //
                    // can we add this value for statistics?
                    double v;
                    if (value != "" && StatisticsLogger.IsValidField(this.Name) && double.TryParse(value.Replace(",", "."), System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out v))
                    {
                        Statistics.AddValue(v, this.UpdateTime);
                    }
                }
            }
        }

Line 74 looks like it will only allow Value to be updated if the new value is different than the last value.  However, this is a problem for me.  I need to watch for a single or double tap of a switch.  In order to do this, I need to know what the current and last values of the switch are.  I have code that looks for a double tap (ON + ON or Off + OFF) in order to act.  The way it's currently coded, it looks like I cannot detect a double tap of the switch.

I could change the code to eliminate this, but I'm not sure if that would break something else.  Could you help understand why HG won't let a double sending of the current value?  The only thing I can think of is that this is in an effort to keep RF commands from being stored as a LastValue since they are most likely repeated when sent.
Title: Re: C# documentation
Post by: Gene on May 30, 2014, 03:26:54 PM
Hi Ben,

Value/UpdateTime fields are always updated with current received data.
Indeed LastValue/LastUpdateTime is only updated when a new value is received and it's not updated if received data keep being the same.

This is because the meaning of LastValue is "last value different from current one".

If you need to access all values history you can implement an automation program that uses the WhenModuleParameterChange event to store all received values into a List<ModuleParameter> .

Cheers,
g.
Title: Re: C# documentation
Post by: bkenobi on May 30, 2014, 04:15:16 PM
Sounds like that's the approach I'll take.  Do you have an example of defining and accessing a list in C# for HG?  Is it possible to generate a list in a parameter such that it could be accessed by something like:
Code: [Select]
Modules.WithName("My Module").Parameter("ActivityList(0)").Value"Maybe this would be better implemented directly in the code.  I know I can just make parameters "LastValue", "LastLastValue", etc., I was just thinking about a cleaner implementation.
Title: Re: C# documentation
Post by: bkenobi on June 18, 2014, 08:15:19 PM
I know that when a module changes, the UpdateTime field is updated.  But, if I create my own parameter (a timer for example), do I need to set the UpdateTime field manually or does this get updated by HG?  For example,

Code: [Select]
Modules.WithFeature(SMART_LIGHT_ENABLE).Each((light_mod)=>
{
  light_mod.Parameter(TIMER_ON).Value="TRUE";
  light_mod.Parameter(TIMER_ON).UpdateTime=DateTime.UtcNow;
});

Do I really need to have the second line to set the TIMER_ON UpdateTime?  It doesn't seem to update on its own.