@mvdarend,
I added the control.toggle handling but that did not resolve the issue.
Turns out that when the switch is set from the Android app, the third parameter is NULL, hence the code that retrieves this parameter raises an exception. When I commented out the third argument (see below) the error is gone.
What does the third parameter contain? It is not used in the code for the virtual switch anyway so commenting out should not harm.
var moduleDomain = "HomeAutomation.Virtual.Switch";
When.WebServiceCallReceived(moduleDomain,(args) =>
{
string[] request = ((string)args).Split('/');
var response = "{ 'ResponseValue' : 'ERROR' }";
try
{
string moduleId = request[1];
string command = request[2];
// string parameter = request[3].Replace("%20", " ");
var module = Modules.InDomain(moduleDomain).WithAddress(moduleId).Get();
switch(command)
{
case "Control.On":
module.Parameter("Status.Level").Value = "1";
Program.RaiseEvent(module, "Status.Level", "1", "Virtual Switch");
break;
case "Control.Off":
module.Parameter("Status.Level").Value = "0";
Program.RaiseEvent(module, "Status.Level", "0", "Virtual Switch");
break;
case "Control.Toggle":
if (module.Parameter("Status.Level").DecimalValue == 0)
{
module.Parameter("Status.Level").Value = "1";
Program.RaiseEvent(module, "Status.Level", "1", "VirtualSwitch");
Cheers
Pim