I am attempting to save the value of a virtual device to a windows environment variable.
I have your sample script (see below) and added only 1 line to it.
The line "setx athome 3" creates an environment variable and assigns the value 3 to it. Since it is written to the registry it is non volatile. I then hope to read it back after a system restart using a different script. I will replace the 3 with getNodeByShortId(10);
the problem is I cannot get it to compile. The log says it is missing a ; in line 13.
What am I doing wrong here? It works from the cli.
Thanks
N0VTN
using MLS.ZWave.Service.Rules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MLS.HA.DeviceController.Common.Device.ZWave;
public class MyScript : ScriptBase, ScriptInterface {
public void runScript() {
// This is where the magic happens
// Your code should go here
setx athome 3;
}
}
Script Issue
- 102 Views
- Last Post 29 January 2014
I am attempting to save the value of a virtual device to a windows environment variable.
I have your sample script (see below) and added only 1 line to it.
The line "setx athome 3" creates an environment variable and assigns the value 3 to it. Since it is written to the registry it is non volatile. I then hope to read it back after a system restart using a different script. I will replace the 3 with getNodeByShortId(10);
the problem is I cannot get it to compile. The log says it is missing a ; in line 13.
What am I doing wrong here? It works from the cli.
Thanks
N0VTN
using MLS.ZWave.Service.Rules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MLS.HA.DeviceController.Common.Device.ZWave;
public class MyScript : ScriptBase, ScriptInterface {
public void runScript() {
// This is where the magic happens
// Your code should go here
setx athome 3;
}
}
You'll need to move the setx command to a batch file and then try it that way. Something akin to this:
string targetDir = string.Format(@"c:\somefolder"); //this is where mybatch.bat lies
proc = new Process();
proc.StartInfo.WorkingDirectory = targetDir;
proc.StartInfo.FileName = "mybatch.bat";
proc.StartInfo.Arguments = getNodeByShortId(10).level.ToString(); //this is value of the light you want to save
proc.StartInfo.CreateNoWindow = false;
proc.Start();
proc.WaitForExit();
Then make sure you read the parameter in the bat file...
setx athome %1
I didn't test any of the above, so there could be syntax errors, but the concept is generally what should work.
I plugged your sample into my script, see below.
When I attempt to run it I get the following compiler errors,
12/21/2013 5:41:04 PM: Script failed to compile with error: The name 'proc' does not exist in the current context on line 14.
12/21/2013 5:41:04 PM: Script failed to compile with error: The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) on line 14.
12/21/2013 5:41:04 PM: Script failed to compile with error: The name 'proc' does not exist in the current context on line 15.
12/21/2013 5:41:04 PM: Script failed to compile with error: The name 'proc' does not exist in the current context on line 16.
12/21/2013 5:41:04 PM: Script failed to compile with error: The name 'proc' does not exist in the current context on line 17.
12/21/2013 5:41:04 PM: Script failed to compile with error: The name 'proc' does not exist in the current context on line 18.
12/21/2013 5:41:04 PM: Script failed to compile with error: The name 'proc' does not exist in the current context on line 19.
12/21/2013 5:41:04 PM: Script failed to compile with error: The name 'proc' does not exist in the current context on line 20.
// My script called SaveAtHomeValue.cs
using MLS.ZWave.Service.Rules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MLS.HA.DeviceController.Common.Device.ZWave;
public class MyScript : ScriptBase, ScriptInterface {
public void runScript() {
// This is where the magic happens
// Your code should go here
string targetDir = string.Format(@"c:\batfiles"); //this is where SaveAtHome.bat lies
proc = new Process();
proc.StartInfo.WorkingDirectory = targetDir;
proc.StartInfo.FileName = "SaveAtHome.bat";
proc.StartInfo.Arguments = getNodeByShortId(38).level.ToString(); //this is value of the light you want to save
proc.StartInfo.CreateNoWindow = false;
proc.Start();
proc.WaitForExit();
}
}
My batch file is c:\batfiles\Save_AtHome.bat
setx athome %1
exit
This seems like a lot of work just to retain the setting on a virtual device after reboot.
See the bolded edit. Again, I haven't tried to compile this script myself, so there could be other errors.
// My script called SaveAtHomeValue.cs
using MLS.ZWave.Service.Rules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MLS.HA.DeviceController.Common.Device.ZWave;
public class MyScript : ScriptBase, ScriptInterface {
public void runScript() {
// This is where the magic happens
// Your code should go here
string targetDir = string.Format(@"c:\batfiles"); //this is where SaveAtHome.bat lies
[b]var proc = new Process();[/b]
proc.StartInfo.WorkingDirectory = targetDir;
proc.StartInfo.FileName = "SaveAtHome.bat";
proc.StartInfo.Arguments = getNodeByShortId(38).level.ToString(); //this is value of the light you want to save
proc.StartInfo.CreateNoWindow = false;
proc.Start();
proc.WaitForExit();
}
}