Jump to content

How to Trigger a Computer Upon a Device Powering Up


apostolakisl

Recommended Posts

Posted

OK, not an Insteon or ISY thing here at all, but it is kind of similar automation issues and I was thinking someone here might have an idea.

 

I have a sound system at my church that powers up from a sequential power strip.  When that power strip turns on, I want a computer (which of course is not turned on that way, but rather is always on) to run a program.  I am using autohotkey on that computer to run some scripts that turn on a live internet feed from the sound system and would like to trigger that autohotkey script whenever the sound system powers up, and then have it trigger the shut down script when the sound system turns off.

 

Any ideas?

 

I can use autohotkey to react to just about anything the computer does and trigger the script, but somehow I need to get the computer to do something for autohotkey to see.  I even though about hot wiring a key on the keyboard and having a relay powered by the power strip simulate a key press.  But that just seems really rigged.

Posted

I know you said this is NOT an ISY thing but is there an ISY available?  If so, you could use a synchrolinc or IOLinc input to tell ISY the status of the sound system and trigger an event ghost script on the PC to do whatever. 

 

Other thoughts might include a Aeon Labs Smart Energy Switch powering the sound system paired to a Zstick on the PC.  Not sure of the software end of that equation however.  Kind of the same idea as above but with cheap ZWave components and no ISY.

 

Or do it all on the PC: http://numato.com/gpio-modules/usb-gpio/8-channel-usb-gpio-module.html?gclid=COGx-vG9_cICFcXm7AodgH8A9g

 

 

-Xathros

Posted

Well I do have my old isy 99 that I could donate to the church, but I would rather not do it that way.

 

The numato seems like exactly what I want, except as you mentioned, I am concerned about what software I need to pull the info off of it.

 

EDIT:  It looks like you use a terminal emulator to read/control it.  Unfortunately I don't know how to use that in an automatic fashion.  I would need to keep polling the device and when the input goes high, execute a program, then when it goes low, execute a different program (both programs are autohotkey scripts).  I suppose I could use an autohotkey script to keep typing in the polling command and then "reading" the response, but that seems pretty sloppy.

 

EDIT Again:  It looks like autohotkey can query the com port and react to the returned value.  Now to figure out the code.

Posted

Well I do have my old isy 99 that I could donate to the church, but I would rather not do it that way.

 

The numato seems like exactly what I want, except as you mentioned, I am concerned about what software I need to pull the info off of it.

 

EDIT:  It looks like you use a terminal emulator to read/control it.  Unfortunately I don't know how to use that in an automatic fashion.  I would need to keep polling the device and when the input goes high, execute a program, then when it goes low, execute a different program (both programs are autohotkey scripts).  I suppose I could use an autohotkey script to keep typing in the polling command and then "reading" the response, but that seems pretty sloppy.

 

EDIT Again:  It looks like autohotkey can query the com port and react to the returned value.  Now to figure out the code.

Excellent.  I'll be watching with interest to see how this works out for you.

 

-Xathros

Posted

I know you said this is NOT an ISY thing but is there an ISY available?  If so, you could use a synchrolinc or IOLinc input to tell ISY the status of the sound system and trigger an event ghost script on the PC to do whatever. 

 

Other thoughts might include a Aeon Labs Smart Energy Switch powering the sound system paired to a Zstick on the PC.  Not sure of the software end of that equation however.  Kind of the same idea as above but with cheap ZWave components and no ISY.

 

Or do it all on the PC: http://numato.com/gpio-modules/usb-gpio/8-channel-usb-gpio-module.html?gclid=COGx-vG9_cICFcXm7AodgH8A9g

 

 

-Xathros

Would an ISY even be needed?

 

The IOLinc should be able to be scene-linked to a module to turn devices on. Not sure about sensing Off to activate devices without an ISY to invert the logic.

Posted

Would an ISY even be needed?

 

The IOLinc should be able to be scene-linked to a module to turn devices on. Not sure about sensing Off to activate devices without an ISY to invert the logic.

The goal was to detect a device turning on and notify a PC/Start a script running..  Not sure how you would accomplish that in Insteon without the ISY's network module and Event ghost on the PC.

 

-Xathros

Posted

The goal was to detect a device turning on and notify a PC/Start a script running..  Not sure how you would accomplish that in Insteon without the ISY's network module and Event ghost on the PC.

 

-Xathros

Isn't Insteon designed around directly connecting controllers and responders without any CSA (central smart agency)? Shouldn't an IOLinc and a On/Off module be able to be linked together using only link buttons? I have done this with my MS and LampLincs (thanks to your persistent drilling methods into my brain).

Posted

Isn't Insteon designed around directly connecting controllers and responders without any CSA (central smart agency)? Shouldn't an IOLinc and a On/Off module be able to be linked together using only link buttons? I have done this with my MS and LampLincs (thanks to your persistent drilling methods into my brain).

Hi Larry-

 

Yes it is.  It works quite well just as you have described.  Only that is not what the OP asked for here. In this situation, the OP wants to control something (run a script) on an already running PC when an unrelated device was turned on.  This is not something that Insteon can do by itself.  With the ISY, network module  and Event Ghost - it could be done.  We have since identified one or more simpler approaches.

 

-Xathros

Posted

Hi Larry-

 

Yes it is.  It works quite well just as you have described.  Only that is not what the OP asked for here. In this situation, the OP wants to control something (run a script) on an already running PC when an unrelated device was turned on.  This is not something that Insteon can do by itself.  With the ISY, network module  and Event Ghost - it could be done.  We have since identified one or more simpler approaches.

 

-Xathros

OK My bad!  I misread the importance of the computer and thought it was just an aftermention.

Thanks.

 

The gadget J_Barret linked to (above) looks promising.

Posted

 

What about some thing like  this  

 

SmartWye USB Keyboard Encoders

 

http://www.vetra.com/312utxt.html

 

 

Looks like another possibility albeit a bit more expensive.

 

-Xathros

Posted

Looks like another possibility albeit a bit more expensive.

 

-Xathros

 

Yes.  I agree, I think that would work.  It might come with software though so the extra cost might save me some learning.  The downside of the other is I have to figure out the ahk coding for com port stuff.  AHK is a pretty versatile item.  It really is a pretty highly functioning programming language.  I have used it just for making "hot keys" in the past, but with this project I have it doing so much more.  It automatically configures all the settings on Mixxx for me allowing me to switch back and forth between playing recordings and playing live.  You can program it to check the color of a toggle button to see if it is on or off and set it to whichever you want if it the opposite.  It can execute programs, drag and drop, slide volume sliders, save things to disk.  It has if/then, loops, and on and on.  Really it can do anything that a human can do with a keyboard and mouse and eyeballs.  And it is free.

 

The trouble is that at present I just have it set to go live at scheduled times and shut off similarly.  If our priest was on time things would be great.  But alas he is not. :cry:  

Posted

OK My bad! I misread the importance of the computer and thought it was just an aftermention.

Thanks.

 

The gadget J_Barret linked to (above) looks promising.

Yep.

 

I love learning about all these odd gadgets here. Lots of cool devices out there if you know where to look!

 

-Xathros

 

Sent from my iPhone using Tapatalk

Posted

Numato people responded to emails and posted code for controlling the device with autohotkey.  Here it is in case anyone cares to use it.  I ordered the device, but it is coming from Europe so I won't have it for a while.

;##############################################################################
;#                                                                            #
;#           Autohotkey Script to control Numato Lab USB GPIO Module          #
;#                           www.numato.com                                   #
;# Uses subroutines from the script published by aobrien at http://www.autoho #
;# tkey.com/board/topic/26231-serial-com-port-console-script/#187247          #
;#                                                                            #
;#         This script can be used with all Numato USB GPIO modules.          #
;##############################################################################

SendMode Input
SetWorkingDir %A_ScriptDir%

InputBox, comport, Enter Port Number, Simply enter the decimal number. COM will be added automatically.,,,,,,,,0
if ErrorLevel
	ExitApp

InputBox, gpionum, Enter GPIO Number ,Enter the number of the GPIO. GPIOs are usually numbered 0 - 9 then A - Z. Make sure to use upper case letters when typing GPIO numbers from A onwards.  ,,,,,,,,0
if ErrorLevel
	ExitApp
	
InputBox, gpiocommand, Enter GPIO Command (set/clear/read),Enter command (set/clear/read),,,,,,,,read 
if ErrorLevel
	ExitApp
	
if ( not gpiocommand = "set" and not gpiocommand = "clear" and not gpiocommand = "read"){
	msgbox Please enter a valid GPIO command
	ExitApp
}

RS232_Port = COM%comport%
	
RS232_Settings = %RS232_Port%:baud=19200 parity=N data=8 stop=1 dtr=Off xon=off to=off odsr=off octs=off rts=off idsr=off
RS232_FileHandle:=RS232_Initialize(RS232_Settings)

if (gpiocommand = "set"){
	command = gpio set %gpionum%`r
	RS232_Write(RS232_FileHandle, command)
}

if (gpiocommand = "clear"){
	command = gpio clear %gpionum%`r
	RS232_Write(RS232_FileHandle, command)
}

if (gpiocommand = "read"){
	command = gpio read %gpionum%`r
	RS232_Write(RS232_FileHandle, command)
	Sleep, 10
	Read_Data := RS232_Read(RS232_FileHandle, 20,RS232_Bytes_Received)
	
	StringGetPos OutputVar, Read_Data, 0`n`r>
	if(not ErrorLevel)
		msgbox GPIO is Off
		
	StringGetPos OutputVar, Read_Data, 1`n`r>
	if(not ErrorLevel)
		msgbox GPIO is On
}

RS232_Close(RS232_FileHandle)
ExitApp

;########################################################################
;#                      Initialize RS232 Port                           #
;########################################################################
RS232_Initialize(RS232_Settings)
{
  ;###### Extract/Format the RS232 COM Port Number ######
  ;7/23/08 Thanks krisky68 for finding/solving the bug in which RS232 COM Ports greater than 9 didn't work.
  StringSplit, RS232_Temp, RS232_Settings, `:
  RS232_Temp1_Len := StrLen(RS232_Temp1)  ;For COM Ports > 9 \\.\ needs to prepended to the COM Port name.
  If (RS232_Temp1_Len > 4)                   ;So the valid names are
    RS232_COM = \\.\%RS232_Temp1%             ; ... COM8  COM9   \\.\COM10  \\.\COM11  \\.\COM12 and so on...
  Else                                          ;
    RS232_COM = %RS232_Temp1%

  ;8/10/09 A BIG Thanks to trenton_xavier for figuring out how to make COM Ports greater than 9 work for USB-Serial Dongles.
  StringTrimLeft, RS232_Settings, RS232_Settings, RS232_Temp1_Len+1 ;Remove the COM number (+1 for the semicolon) for BuildCommDCB.
  ;MsgBox, RS232_COM=%RS232_COM% `nRS232_Settings=%RS232_Settings%

  ;###### Build RS232 COM DCB ######
  ;Creates the structure that contains the RS232 COM Port number, baud rate,...
  VarSetCapacity(DCB, 28)
  BCD_Result := DllCall("BuildCommDCB"
       ,"str" , RS232_Settings ;lpDef
       ,"UInt", &DCB)        ;lpDCB
  If (BCD_Result <> 1)
  {
    MsgBox, There is a problem with Serial Port communication. `nFailed Dll BuildCommDCB, BCD_Result=%BCD_Result% `nThe Script Will Now Exit.
    Exit
  }

  ;###### Create RS232 COM File ######
  ;Creates the RS232 COM Port File Handle
  RS232_FileHandle := DllCall("CreateFile"
       ,"Str" , RS232_COM     ;File Name         
       ,"UInt", 0xC0000000   ;Desired Access
       ,"UInt", 3            ;Safe Mode
       ,"UInt", 0            ;Security Attributes
       ,"UInt", 3            ;Creation Disposition
       ,"UInt", 0            ;Flags And Attributes
       ,"UInt", 0            ;Template File
       ,"Cdecl Int")

  If (RS232_FileHandle < 1)
  {
    MsgBox, There is a problem with Serial Port communication. `nFailed Dll CreateFile, RS232_FileHandle=%RS232_FileHandle% `nThe Script Will Now Exit.
    Exit
  }

  ;###### Set COM State ######
  ;Sets the RS232 COM Port number, baud rate,...
  SCS_Result := DllCall("SetCommState"
       ,"UInt", RS232_FileHandle ;File Handle
       ,"UInt", &DCB)          ;Pointer to DCB structure
  If (SCS_Result <> 1)
  {
    MsgBox, There is a problem with Serial Port communication. `nFailed Dll SetCommState, SCS_Result=%SCS_Result% `nThe Script Will Now Exit.
    RS232_Close(RS232_FileHandle)
    Exit
  }

  ;###### Create the SetCommTimeouts Structure ######
  ReadIntervalTimeout        = 0x00000001
  ReadTotalTimeoutMultiplier = 0x00000000
  ReadTotalTimeoutConstant   = 0x00000000
  WriteTotalTimeoutMultiplier= 0x00000000
  WriteTotalTimeoutConstant  = 0x00000000

  VarSetCapacity(Data, 20, 0) ; 5 * sizeof(DWORD)
  NumPut(ReadIntervalTimeout,         Data,  0, "UInt")
  NumPut(ReadTotalTimeoutMultiplier,  Data,  4, "UInt")
  NumPut(ReadTotalTimeoutConstant,    Data,  8, "UInt")
  NumPut(WriteTotalTimeoutMultiplier, Data, 12, "UInt")
  NumPut(WriteTotalTimeoutConstant,   Data, 16, "UInt")

  ;###### Set the RS232 COM Timeouts ######
  SCT_result := DllCall("SetCommTimeouts"
     ,"UInt", RS232_FileHandle ;File Handle
     ,"UInt", &Data)         ;Pointer to the data structure
  If (SCT_result <> 1)
  {
    MsgBox, There is a problem with Serial Port communication. `nFailed Dll SetCommState, SCT_result=%SCT_result% `nThe Script Will Now Exit.
    RS232_Close(RS232_FileHandle)
    Exit
  }
  
  Return %RS232_FileHandle%
}

;########################################################################
;#                         Close RS232 Port                             #
;########################################################################
RS232_Close(RS232_FileHandle)
{
  ;###### Close the COM File ######
  CH_result := DllCall("CloseHandle", "UInt", RS232_FileHandle)
  If (CH_result <> 1)
    MsgBox, Failed Dll CloseHandle CH_result=%CH_result%

  Return
}

;########################################################################
;#                         Write to RS232 Port                          #
;########################################################################
RS232_Write(RS232_FileHandle,Message)
{

  ;###### Write the data to the RS232 COM Port ######
  WF_Result := DllCall("WriteFile"
       ,"UInt" , RS232_FileHandle ;File Handle
       ,"UInt" , &Message          ;Pointer to string to send
       ,"UInt" , Strlen(Message)            ;Data Length
       ,"UInt*", Bytes_Sent     ;Returns pointer to num bytes sent
       ,"Int"  , "NULL")
  If (WF_Result <> 1 or Bytes_Sent <> Strlen(Message))
    MsgBox, Failed Dll WriteFile to RS232 COM, result=%WF_Result% `nData Length=%Data_Length% `nBytes_Sent=%Bytes_Sent%
}

;########################################################################
;#                         Read from RS232 port                         #
;########################################################################
RS232_Read(RS232_FileHandle,Num_Bytes,ByRef RS232_Bytes_Received)
{
  SetFormat, Integer, HEX

  ;Set the Data buffer size, prefill with 0x55 = ASCII character "U"
  ;VarSetCapacity won't assign anything less than 3 bytes. Meaning: If you
  ;  tell it you want 1 or 2 byte size variable it will give you 3.
  Data_Length  := VarSetCapacity(Data, Num_Bytes, 0x55)
  ;MsgBox, Data_Length=%Data_Length%

  ;###### Read the data from the RS232 COM Port ######
  ;MsgBox, RS232_FileHandle=%RS232_FileHandle% `nNum_Bytes=%Num_Bytes%
  Read_Result := DllCall("ReadFile"
       ,"UInt" , RS232_FileHandle   ; hFile
       ,"Str"  , Data             ; lpBuffer
       ,"Int"  , Num_Bytes        ; nNumberOfBytesToRead
       ,"UInt*", RS232_Bytes_Received   ; lpNumberOfBytesReceived
       ,"Int"  , 0)               ; lpOverlapped

  ;MsgBox, RS232_FileHandle=%RS232_FileHandle% `nRead_Result=%Read_Result% `nBR=%RS232_Bytes_Received% ,`nData=%Data%
  If (Read_Result <> 1)
  {
    MsgBox, There is a problem with Serial Port communication. `nFailed Dll ReadFile on RS232 COM, result=%Read_Result% - The Script Will Now Exit.
    RS232_Close(RS232_FileHandle)
    Exit
  }

  Return Data
}


Posted

Nice.  Can't wait to hear how the device works once you get to playing with it.  It's an excellent sign that you were able to get this kind of response from the developer.

 

-Xathros

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...