HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Help => Topic started by: kevin1 on May 20, 2015, 06:10:29 PM

Title: Help to understand HG better
Post by: kevin1 on May 20, 2015, 06:10:29 PM
1-When should we use or not use RunAsyncTask?

2-When should we use Program.GoBackground();?  Only when program code has no while loop?


3-Trigger Code
-runs only once at start from what I understand?  There is a pulldown to change this, what condition is being evaluated?
-have to have this Program.Setup( () => {?
-what is the return actually used for?  only return true if program code has a while enabled loop in it?
Title: Re: Help to understand HG better
Post by: Gene on May 20, 2015, 08:00:04 PM
1. Preferably avoid using RunAsyncTask unless you want the stuff inside executed asynchronously (it will not wait for those instructions to complete)
2. Yes, but only if you have some event listeners in your code (eg. When.WebServiceCallReceived, When.ModuleParameterChange...)
3. Trigger code:
-  is used by program engine to evaluate if the code to run is to be execute or not. So it will run only when the program code is not active.
- Program.Setup is not mandatory and it is to be used when you need to execute some code only once when the program is activated
- the return will tell the program engine if the code to run has to be executed or not

Trigger code was initially thought for Wizard scripts and then (not so wisely) applied to other type of programs as well.  In the near future, trigger code will be deprecated and there will be only the code to run. I hope there will be less confusion in users by then :)

Cheers,
g.
Title: Re: Help to understand HG better
Post by: kevin1 on May 28, 2015, 04:44:19 PM
Next question, trying to understand the interfaces between clicking on the widgets and the corresponding code.  For example I am trying to use the colorlight widget to adjust a RGB LED on my arduino.

I added the widget in trigger/setup:
Code: [Select]
Program.AddVirtualModules("HomeAutomation.ArduinoBsmtUtil", "Sensor", "homegenie/generic/sensor", 1, 4);
Program.AddVirtualModules("HomeAutomation.ArduinoBsmtUtil", "Light", "homegenie/generic/colorlight", 5, 5);

Then in my code I have a function to send the RGB values via my serial port to Arduino, this part is working :-) .

Looking at the Fibraro and MiLight RGB lights for examples, I see they have code in
Code: [Select]
When.ModuleParameterChanged( (module, property) => {for Control.On and Control.Off, but not for Control.Level or Control.ColorHsb

They do handle these in the  webservice call however:
Code: [Select]
When.WebServiceCallReceived("HomeAutomation.MiLight", ( args ) =>
...
        case "Control.ColorHsb":
        string[] values = parameter.Split(',');


So this brings the question, do widgets use the webservicecall or moduleparameterchange to execute the code? 

Do the LED's or HSV values need to be formal module parameters?

Thanks!!!
Title: Re: Help to understand HG better
Post by: dani on May 29, 2015, 08:20:21 AM
ModuleParameterChanged is used from Module to UI ou for perform some action when a module parameter changes.

WebServiceCall is used from WebAPI or UI (by WebAPI) to perform some action in HG, for exemple to send command to module.
Title: Re: Help to understand HG better
Post by: kevin1 on May 29, 2015, 01:13:50 PM
So WebServiceCallReceived is executed by the colorlight widget when color is changed or turned on with a mouse click?
Title: Re: Help to understand HG better
Post by: Gene on May 29, 2015, 03:20:30 PM
Yes kevin1,

FIY:

http://www.homegenie.it/docs/automation_advanced.php (http://www.homegenie.it/docs/automation_advanced.php) (the last paragraph)
http://www.homegenie.it/docs/automation_widgets.php (http://www.homegenie.it/docs/automation_widgets.php)

Cheers,
g.
Title: Re: Help to understand HG better
Post by: kevin1 on June 12, 2015, 02:35:38 AM

I'm having a difficult time getting my web service call to work.  The camera code works, I see result in browser:
Code: [Select]
http://192.168.1.100/api/Media.IpCamera/1/Camera.MotionDetected
{ 'ResponseValue' : 'OK' }


So I try to duplicate this code in my HomeAutomation.ArduinoGarage program and nothing happens.  Is there some trick or some key pieces I could be overlooking?

http://192.168.1.100/api/HomeAutomation.ArduinoGarage/1/Status (http://192.168.1.100/api/HomeAutomation.ArduinoGarage/1/Status)
---nothing in browser, no notification pops up

Code: [Select]
When.WebServiceCallReceived("HomeAutomation.ArduinoGarage/", ( args ) =>
{
    string[] reqs = ((string)args).Split('/');
    Program.Notify("Arduino Garage", "TEST");
Title: Re: Help to understand HG better
Post by: kevin1 on June 14, 2015, 05:57:53 AM
Even though the security system is enabled and has the default add feature for sensors and door windows, my arduino based door sensor and motion sensor widgets do not show the use as security Feature.  Why, how to get these to show up?
Title: Re: Help to understand HG better
Post by: nolio on June 14, 2015, 10:00:07 PM
In "90 Security Alarm System" and trigger code :
Code: [Select]
Program.AddFeature("Sensor,DoorWindow", "HomeGenie.SecuritySensor", "Use as Security Sensor");
Program.AddFeature("Siren,Light,Dimmer,Switch", "HomeGenie.SecurityAlarm", "Use as Security Alarm");

You could see that your trigger for alarm is "sensor" or "doorwindow", are you sure you have selected one of this type in the configuration of the module ?
Title: Re: Help to understand HG better
Post by: kevin1 on June 15, 2015, 03:51:37 AM
Yes, I have the arduino virtuals set as DoorWindow but they don't show any security options in the Control view.