more G-Labs products

Author Topic: Advanced Smart Lights  (Read 20535 times)

September 22, 2015, 08:40:04 AM
Reply #45

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Also have a look at the new documentation:

http://genielabs.github.io/HomeGenie/api/ape/a00005.html

perhaps there are some useful properties you may want to use in your programs (like IdleTime).

g.

September 22, 2015, 04:27:45 PM
Reply #46

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I left the house before sunrise this morning and found that although the chime went off multiple times, the lights themselves behaved correctly.  Both sections of code use the history[X] parameter, so it must be working to some degree.  Perhaps the change is in how multiple triggers are registered?  I'll let you know what I find.

For reference, I did not set the HistoryLimit value, but since I'm only using the first two elements of the array, the default value of 10 should be sufficient.

September 23, 2015, 06:11:25 PM
Reply #47

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I haven't seen an issue compiling history
  • through my testing.  I did find a peculiar result in doing some testing though.  When I use the following code to determine how long it's been since the last event, it should produce a time span of approximately 2 seconds.
Code: [Select]
var event1 = module.Parameter("Status.Level").Statistics.History[0].
var event2 = module.Parameter("Status.Level").Statistics.History[1].Timestamp;
var elapsed = new TimeSpan(event1.Ticks - event2.Ticks);

However, in at least one instance (I was looking at other things, so this wasn't thoroughly sused yet) it returns a value <1 second even though the motion sensor doesn't act anywhere near that quick (roughly 2 second detect timeout).  The reported elapsed time was ~0.2 seconds.  I'm going to have to look at the entire history[] array to verify that I witnessed a fluke of some kind.



Also, perhaps someone could explain the correct syntax for switching my setup commands that are causing warning messages (AddFeature, AddFeatureTextInput, AddInputField).  Am I just supposed to add another blank field somewhere and change the method?  I'll take a look but last time it looked confusing so I've been ignoring the warnings.

September 23, 2015, 09:27:18 PM
Reply #48

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer

September 23, 2015, 11:45:41 PM
Reply #49

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Oh, that's much easier than I thought it would be.  The only thing that probably should be noted is that when changing from AddFeature (old) or AddFeatureTextInput to AddFeature (new), the value held within the module parameters is lost and needs to be reset.  It's not a big deal for my code here, but it might be problematic if the feature holds more complex values (e.g., cron events).

September 25, 2015, 08:11:35 AM
Reply #50

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
The documentation for AddOption suggests that all types in the html/ui/widgets directory are available.  However, it appears that neither slider nor checkbox works.  Perhaps I'm missing something, but the following lines produce text boxes:
Code: [Select]
    Program.AddOption("Adv_SmartLight.EnableLog", "false", "1) Enable log file","checkbox");
    Program.AddOption("Adv_SmartLight.LogPath", @"/usr/local/bin/homegenie/log/SmartLights.log", "2) Path to log file","text");
    Program.AddOption("Adv_SmartLight.TimerFidelity", "1", "3) How often does code check for timer end (seconds)","slider:0:30:1");
    Program.AddOption("Adv_SmartLight.SwitchTimeout", "5", "4) How long between switch commands constitutes double tap (seconds)","slider:0:10:1");
    Program.AddOption("Adv_SmartLight.SensorNuisanceLimiter", "20", "5) Nuisance limiter - Two motion detects within limiter will trigger chime (seconds)","slider:0:60:1");
If I'm doing something wrong or misunderstand implementation, please correct me!

September 25, 2015, 05:55:55 PM
Reply #51

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi bkenobi,

they all works with AddFeature, but currently the only supported type for AddOption is "text". You can leave them specified, because in some next hg update these will be implemented for AddOption as well.

g.

September 25, 2015, 07:04:28 PM
Reply #52

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
My primary concern is that checkbox holds a value of "On" or blank and my code currently checks for the string "TRUE" or "FALSE".  I want to update to be consistent with the new methods but don't want to have to redo my logic if possible.  It would be ideal (I think) if the checkbox value was boolean so we could just use it directly in logic, but I don't know if that's possible.  I used an inline if in my updated code to simplify one checkbox (addfeature) so that can be used as well if I know what to expect.

September 25, 2015, 09:54:00 PM
Reply #53

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
I try the following code :
Code: [Select]
When.ModuleParameterChanged((module, parameter) =>
{
............
if ( parameter.Statistics.History[0].Value != parameter.Statistics.History[1].Value ) {
.........
The parameter.Statistics.History[0].Value work fine but parameter.Statistics.History[1].Value as the error : Argument is out of range / Parameter name : index
Does it work on your side ? Any idea why ?

September 26, 2015, 12:13:19 AM
Reply #54

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
When do you get that error?  Is it when you compile it or when it's running?  I'm not getting any compile errors, but the code doesn't work right now (I've been making some changes so I could have broken it some other way).  There should be 10 values in the history[X] array by default (presumably 0-9).  These should be the last 10 events (even if they are repeated).  When I was initially testing this code, I was outputing the array and it was exactly as expected but I have not tested it since my last release.

September 26, 2015, 06:28:43 AM
Reply #55

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Running, error is pop-up by a try/catch. I write HistoryLimit "parameter.Statistics.HistoryLimit" and the value is 10, but something seems to fail with array ....
« Last Edit: September 26, 2015, 06:57:14 AM by nolio »

September 26, 2015, 07:38:17 PM
Reply #56

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I added the following code to the script just after the WhenParameterIsChanging line:

Code: [Select]
  //Log sensor_mod history array
  Program.Notify("HistoryLimit",module.Parameter("Status.Level").Statistics.HistoryLimit.ToString());
  string tmp = "";
  for (int i = 0; i<=9; i++ )
  {
    tmp += module.Parameter("Status.Level").Statistics.History[i].Value + " ";
  }
  Program.Notify("History array",tmp);

When a parameter changes, I get only one line of notification for the HistoryLimit output.  I do not see anything for the History[X] output.  I changed the notification to output each history[X] element.  I am able to output element 0 but nothing else prints.  When I compile the code, I get the following error:
Code: [Select]
TC: Object reference not set to an instance of an object
Without this value, my code won't work.

October 06, 2015, 04:40:47 PM
Reply #57

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I believe I have tested all related code and found that the only part that seems to be an issue is the HistoryValue array which contains a value in element 0 only.  Without element 1 as well, I cannot determine my timer functions so lights will turn on but not off.

At this time, I have determined that there was a change in mid September 2015 that modified code related to Statistics.HistoryValue.  I don't know why this change caused problems, but I can confirm that it does seem to cause problems.  I will be migrating back to a version prior to r494 so that this code will be reverted.  Hopefully this issue will be resolved and I can eliminate this recommendation.

EDIT: r496 has fixed the issue with the HistoryValue array.  If you have issues with ASL, update HG to something more recent than 496.
« Last Edit: October 21, 2015, 04:18:43 PM by bkenobi »

October 26, 2015, 08:17:37 PM
Reply #58

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I have noticed that on my setup I have certain scenarios where the ASL enabled light will take 10 seconds to turn on.  I am currently debugging this issue to determine what is causing this.  It only started happening after the history array issue was introduced as older versions of HG worked as expected.  Currently, I can say that using a switch causes a delay.  I have also seen that one motion sensor light works correctly but another (using the start timer on ON) does not work.  When I locate the bug I will post a fixed APP and/or submit an issue on github to get things working correctly.

If you have any issues with a lengthy delay to turn your light on, please post to hopefully shorten the debug cycle.

November 12, 2015, 07:57:34 AM
Reply #59

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
After further testing it appears that r496 (HG 1.1) does not work well with my setup (RPi v1B w/ CM15A).  I believe there was a change to the mono requirements that necessitates an update not available (i.e., a newer .NET framework).  I have not been able to fix the issue with a fresh system install, so I am currently recommending using HG 1.0 r493 or earlier.  Email support was also lost at some point so an earlier version might also be good if that is useful.