Hello bkneobi,
First of all, I was able to start HG again. I post the solution in case someone coud have the same issue.
Looking into programs.xml I've found the block of my program code which was causing a segment fault. This is not normale that it causes a crash, btw... then I've taken a look to the ID HG has associated to my program. Moving than in the programs folder I've deleted the <id>.dll file. The result is the program needs to be compiled again. Starting HG I was able to login, go to my program, correct the code and compile it again. All went well
Back to the switch issue. Now I've tried the following to turn off a switch (only the display status):
Modules.InDomain("HomeAutomation.XefilHomeArduino").WithAddress("100").Off();
This refers to:
{
"Name": "TEST123",
"Description": "",
"DeviceType": "Switch",
"Domain": "HomeAutomation.XefilHomeArduino",
"Address": "100",
"Properties": [
{
"Name": "HomeGenie.ScheduleControl",
"Description": "",
"Value": "",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "HomeGenie.ScheduleOff",
"Description": "",
"Value": "",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "HomeGenie.ScheduleOn",
"Description": "",
"Value": "",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "HomeGenie.SecurityAlarm",
"Description": "",
"Value": "",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "HomeGenie.SmartLights.CheckLuminosity",
"Description": "",
"Value": "",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "HomeGenie.SmartLights.Enable",
"Description": "",
"Value": "",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "HomeGenie.SmartLights.OnMotionDetect",
"Description": "",
"Value": "",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "HomeGenie.SmartLights.SwitchOffTimeout",
"Description": "",
"Value": "",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "HomeGenie.TurnOffDelay",
"Description": "",
"Value": "",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "MobileNotification.SendChanges",
"Description": "",
"Value": "",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "VirtualMeter.Watts",
"Description": "",
"Value": "0",
"UpdateTime": "2015-01-19 18:46:16Z"
},
{
"Name": "VirtualModule.ParentId",
"Description": "",
"Value": "1007",
"UpdateTime": "2015-01-19 18:49:03Z"
},
{
"Name": "Widget.DisplayModule",
"Description": "",
"Value": "homegenie/generic/switch",
"UpdateTime": "2015-01-19 18:44:38Z"
} ],
"RoutingNode": ""
},
Why the switch doesn't change status?
The widget is created in another program (domain: HomeAutomation.XefilHomeArduino) and I'm trying to change that value from this program (domain: HomeAutomation.XefilHomeArduinoSwitch).
I've noticed It's missing this attribute:
{
"Name": "Status.Level",
"Description": "",
"Value": "0",
"UpdateTime": "2015-01-19 16:36:40Z"
},
Does it have someting to do?
Is it possible I'm missing this parameter because I'm creating two types of VirtualModules from the same program?
// create 9 virtual modules in the domain HomeAutomation.Arduino with address from 1 to 10
Program.AddVirtualModules("HomeAutomation.XefilHomeArduino", "Sensor", "homegenie/generic/sensor", 1, 10);
// create virtual modules in the domain HomeAutomation.Arduino with address from 100 to 112
Program.AddVirtualModules("HomeAutomation.XefilHomeArduino", "Switch", "homegenie/generic/switch", 100, 112);
To be more precise, on program 1 (domain: HomeAutomation.XefilHomeArduino) I'm collecting informations via json parser and creating virtualmodules of type sensor and switch. This program runs every 500secs to update these values.
Then, program 2 (domain: HomeAutomation.XefilHomeArduinoSwitch) should take care about the switches. It should load the values of the switch from program 1 (domain: HomeAutomation.XefilHomeArduino) and, if pressed, change the status.
For now I would be happy only to change in program 2 the status from the switch statically and I should see in the dashboard On or Off (statically) up on what I've written in the code of program 2:
OFF:
Modules.InDomain("HomeAutomation.XefilHomeArduino").WithAddress("100").Off();
OR ON:
Modules.InDomain("HomeAutomation.XefilHomeArduino").WithAddress("100").On();
BTW changing the values I cannot obtain any result.
Ideas?
Thank's a lot!
Whole code:
// CSharp Automation Program Plugin
// Example for using Helper Classes:
// Modules.WithName("Light 1").On();
// Initialise parameters (Status Off)
var SettingSwitchModules = Modules.InDomain("HomeAutomation.XefilHomeArduinoSwitch");
Modules.InDomain("HomeAutomation.XefilHomeArduino").WithAddress("100").Off(); ///////////// HERE!!!
// We want to do further processing whenever a module prop changes
When.ModuleParameterChanged( (module, property) => {
Console.WriteLine("---");
Console.WriteLine("Why this is matching often even if nothing is touched???");
Console.WriteLine("---");
if (module.Is("Prova Switch")) {
Console.WriteLine("---");
Console.WriteLine("This works, if the Switch has name 'Prova Switch' I get this line");
Console.WriteLine("---");
return true;
}
return false;
});
When.WebServiceCallReceived("HomeAutomation.XefilHomeArduinoSwitch", ( args ) =>
{
string[] reqs = ((string)args).Split('/');
string switchnumber = reqs[1];
string command = reqs[2];
var module = SettingSwitchModules.WithAddress(switchnumber).Get();
//
switch(command)
{
case "Control.On":
Program.RaiseEvent(module, "Status.Level", "1", "SettingSwitch");
break;
case "Control.Off":
Program.RaiseEvent(module, "Status.Level", "0", "SettingSwitch");
break;
case "Control.Toggle":
if (module.Parameter("Status.Level").DecimalValue == 0)
{
Program.RaiseEvent(module, "Status.Level", "1", "SettingSwitch");
}
else
{
Program.RaiseEvent(module, "Status.Level", "0", "SettingSwitch");
}
break;
}
return "{ 'ResponseValue' : 'OK' }";
});
Program.GoBackground();