Run Autoit Script or Batch File with a Scene

  • 224 Views
  • Last Post 30 June 2013
Rod posted this 24 December 2012

I have a bunch of bat and autoit script files for watching xbmc on my pc. So pushing the 'watch tv scene' will open xbmc on my tv and change the audio input to the stereo... I have a autoit script to open grooveshark and search for certain playlists etc.

I can do this with touchcontrol (iphone app), but I still need to launch my zwave devices for the lights tho.

Order By: Standard | Newest | Votes
Ryan-Scott posted this 24 December 2012

There's a Trello card already to track this one. Feel free to sign up for a Trello account and vote it up or subscribe to it so you can watch the development progress against it.

I'm curious - in your scenario, what do you plan to do with this feature?

Rod posted this 26 December 2012

I have a bunch of bat and autoit script files for watching xbmc on my pc. So pushing the 'watch tv scene' will open xbmc on my tv and change the audio input to the stereo... I have a autoit script to open grooveshark and search for certain playlists etc.

I can do this with touchcontrol (iphone app), but I still need to launch my zwave devices for the lights tho.

Axial-User posted this 04 January 2013

I'm not familiar with Autoit but you can easily run a batch from a scene using rule scripts, e.g. when a scene is activated, run a rule script.

Set up a rule to run when a scene is activated or whatever other conditions you want, then just plug in some code into the script.

System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\helloworld.bat";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);


-N

Ryan-Scott posted this 04 January 2013

I'm not familiar with Autoit but you can easily run a batch from a scene using rule scripts, e.g. when a scene is activated, run a rule script.

Set up a rule to run when a scene is activated or whatever other conditions you want, then just plug in some code into the script.

System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\helloworld.bat";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);


-Cy


Great idea Nelis... just to expound a little bit on this.

Browse to where you have InControl installed; this is probably C:\Program Files (x86)\Moonlit Software, LLC\InControl HA. You'll notice that you've got a Scripts folder. Open it up and make a copy of one of them - for example Max80.cs. Name it something like "RunBat.cs" and then open it up in your favorite text editor.

In the section called "public void runScript()" you'll add the code referenced by Nelis. You'll end up with something that looks like this:[code] public void runScript() {
try {
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\helloworld.bat";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);
} catch (Exception ex) {
// Log the exception here
var message = ex.Message;
}
}
[/code]

Rod posted this 07 January 2013

Thanks for the follow-up guys. Going to check this out. Thanks for the detailed responses.

Maybe being able to create a custom remote control in the app will make this even more useful.

Rod posted this 08 January 2013

Ok, here is what I'm stuck on.

How do I set this up in a rule to trigger when the scene is activated. I want to just assign the rule to a scene and not set a 'trigger'. It seems like I have to set a trigger but I dont want any of those options... I'm missing something.

Rod posted this 08 April 2013

I was never able to make this work. The error logs say 'Missing required value for NodeIds' when the rule was going to fire. I noticed in an early version you let the user input the effected 'nodes' for the rule. Now you have a checkbox for them. I don't think the nodeids are being inputted properly. I"m using your latest version: 2.224..

Ideas?

Ryan-Scott posted this 08 April 2013

I was never able to make this work. The error logs say 'Missing required value for NodeIds' when the rule was going to fire. I noticed in an early version you let the user input the effected 'nodes' for the rule. Now you have a checkbox for them. I don't think the nodeids are being inputted properly. I"m using your latest version: 2.224..

Ideas?



Your original question was how to run a script with a scene. Is that still what you are trying to do? With the new-ish "Pre" and "Post" script options for scenes, does this help in your scenario?

Rod posted this 09 April 2013

Thanks for responding. I see that the scene is firing and working except the code doesn't do anything.

This is the code in the Runbat.cs file in the Pre-Script .. Once I get this working I can attach scripts these to hard buttons ..

using System;
using System.Collections.Generic;
using System.Text;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;

public class Runbat : ScriptBase, ScriptInterface {
public void runScript() {
try {
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\HDTVMonitor.bat";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);
} catch (Exception ex) {
// Log the exception here
var message = ex.Message;
}
}
}

Rod posted this 10 April 2013

Based on the views, this seems to be a popular idea. Once we get a working script it will be easy for people to add any PC script they want with any scene (adding IR scripts with event ghost, grooveshark stations, starting air foil speakers in any room automatically, start xbmc and load your tv shows with a hardware button on your z-wave remote or when you walk into your theatre room etc)... Right now I don't know if the script is even attempting to run nor do I see any errors..

Ryan-Scott posted this 10 April 2013

Thanks for responding. I see that the scene is firing and working except the code doesn't do anything.

This is the code in the Runbat.cs file in the Pre-Script .. Once I get this working I can attach scripts these to hard buttons ..

using System;
using System.Collections.Generic;
using System.Text;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;

public class Runbat : ScriptBase, ScriptInterface {
public void runScript() {
try {
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\HDTVMonitor.bat";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);
} catch (Exception ex) {
// Log the exception here
var message = ex.Message;
}
}
}



My guess is that your script is running but that your .bat isn't working like you expect. An error may even occur but since it's not being logged, you won't see any mention of it.

Try adding some logs to see what your script is doing.

[code]


using System;
using System.Collections.Generic;
using System.Text;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;

public class Runbat : ScriptBase, ScriptInterface {
public void runScript() {
try {
base.writeFileLog("Starting my script");
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\HDTVMonitor.bat";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);
base.writeFileLog("Script executed");
} catch (Exception ex) {
// Log the exception here
var message = ex.Message;
base.writeFileLog("Error with my script: " + message);
}
}
}

[/code]

Then after you run, look in the logfile.txt and see if you can find any of your messages to determine where the script is failing.

Rod posted this 10 April 2013

There are no error logs in the logfile.txt other than a ton of failed polled devices (side note) and I tried other built in scripts to see if they would work with the scene and they didn't do anything either.

I installed V3 and tried again after a reboot. I know the scene is firing because my devices change to the specified scene levels. Other than browsing to the file clicking it so that the file name is there... is there something else you need to do to make the script run?

Ryan-Scott posted this 10 April 2013

There are no error logs in the logfile.txt other than a ton of failed polled devices (side note) and I tried other built in scripts to see if they would work with the scene and they didn't do anything either.

I installed V3 and tried again after a reboot. I know the scene is firing because my devices change to the specified scene levels. Other than browsing to the file clicking it so that the file name is there... is there something else you need to do to make the script run?


No, nothing else is required.

What other scripts did you try? If you have your email setup, you can use this script to send yourself a test email. Just create a new file in the scripts folder called "EmailOnly.cs". Put this in the script slot that your other script isn't using - so either Pre or Post script.

[code]

using System;
using System.Collections.Generic;
using System.Text;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;

public class SendEmailWhenActive : ScriptBase, ScriptInterface {

public void runScript() {
try {

sendEmail("Lights off", "Light off");

} catch (Exception ex) {
var message = ex.Message;
writeLog(message);
}
}
}

[/code]

Rod posted this 10 April 2013

You're right. That worked fine. Must be something with that script that just isn't working. The bat file runs fine when run manually

Ryan-Scott posted this 10 April 2013

You're right. That worked fine. Must be something with that script that just isn't working. The bat file runs fine when run manually


I modified the email script to do the following and it is able to execute the .bat file OK - I know because I got the email when I activated the scene.

[code]

using System;
using System.Collections.Generic;
using System.Text;
using MLS.ZWave.Service.Rules;
using MLS.ZWave.BusinessObjects;

public class SendEmailWhenActive : ScriptBase, ScriptInterface {

public void runScript() {
try {

System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo();
psi.FileName = @"C:\testfile.bat";
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
System.Diagnostics.Process.Start(psi);

sendEmail("Lights off", "Light off");

} catch (Exception ex) {
// Log the exception here
var message = ex.Message;
writeFileLog(message);
}
}
}

[/code]

Rod posted this 10 April 2013

aha! Ok, seems to be a problem with certain bat files. Must be an error somewhere but it works when I run it by double clicking. Perfect troubleshooting man, thanks so much. This opens up so much more fun

Rod posted this 31 May 2013

As an update to this. I have spent some time trying to get certain batch files to work which start programs or switch monitors with no luck. I have tried almost every single solution I could find.

I was able to fire basic task kill commands in batch files but that doesn't help. No exe or au3 files or any bat files that launch programs. If anyone else comes up with a solution please post it here.

Rod posted this 30 June 2013

I was able to find a work around for this. I used autoit to create a gmail checker to look for a Dropbox URL. That Dropbox destination URL contained my au3 file that runs on my local pc.

All I had to do was attach an email script with the Dropbox URL syntax for the gmail UDF and I was able to run any zwave devices with any script on my PC.

I had to setup gmail filters to take keywords and send a canned response back to myself with the correct Dropbox file URL to run.

Example

With this I'm able to launch scenes with Siri "email my computer to turn on music in the bedroom" (no Siri proxy needed)!. My pc checks gmail for those keywords and launches that autoit script which also has scripts to control InControl.

This is also useful if you want to control other Internet devices that don't have a plugin with InControl. Ie a lockitron lock or a Philips hue. Autoit can do almost anything.

Close