Author Topic: Help retrieving template id for ruby script  (Read 463 times)

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Help retrieving template id for ruby script
« on: November 15, 2011, 08:55:22 pm »
I am modifying the following code and I can not figure out how to get the template id for the child I am sending the command to. I added childtype, but I fear it is incorrect. I need the template id because the command to send it a little different from the default command.

Code: [Select]
#### Written by Dan Damron
#### #760 Send Command to Child ####


@insteonID = id.chomp.split('.')
@parameters = parameters
@command = pk_command
@cmd = cmd
childtype =device_.childdevices_[cmdTo].devtemplid_ # find out device type

log('#760:id=' + id.inspect)
log('#760:parameters=' + parameters.inspect)
log('#760:pk_command=' + pk_command.inspect)
log('#760:cmd=' + cmd.inspect)
### ok, I get the insteonID in @insteonID
# pk_command has one of THREE values, 192, 193, or NOTHING
# when I click 50%, I get in parameters: 76
# but NOTHING in pk_command.

case pk_command

when '193' #OFF
when childtype == 4 #used when Device is Thermostat
param = {'Command' => 'SndIns',
'Parameter1' => @insteonID[0],
'Parameter2' => @insteonID[1],
'Parameter3' => @insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '6B',
'Parameter6' => '09'} #OFF
when childtype != 4 #used when Device not Thermostat
param = {'Command' => 'SndIns',
'Parameter1' => @insteonID[0],
'Parameter2' => @insteonID[1],
'Parameter3' => @insteonID[2],
'Parameter4' => '0F',
'Parameter5' => '13', #OFF
'Parameter6' => '00'}
$cmdqueue << param
SndIns()

Thanks.

-Gregg

JoakimL

  • Veteran
  • ***
  • Posts: 149
    • View Profile
Re: Help retrieving template id for ruby script
« Reply #1 on: November 15, 2011, 09:08:23 pm »
I have this code in the Tellstick code:

 cmdTo           = cmd.devidto_                                            # Device ID in LinuxMCE
 devPort         = device_.childdevices_[cmdTo].devdata_[12]  # 12 contains a port/channel
 childType       = device_.childdevices_[cmdTo].devtemplid_    # Template ID to know type of device

Hope it helps.


/Joakim

trippleg

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: Help retrieving template id for ruby script
« Reply #2 on: November 15, 2011, 09:28:36 pm »
I have this code in the Tellstick code:

 cmdTo           = cmd.devidto_                                            # Device ID in LinuxMCE
 devPort         = device_.childdevices_[cmdTo].devdata_[12]  # 12 contains a port/channel
 childType       = device_.childdevices_[cmdTo].devtemplid_    # Template ID to know type of device

Hope it helps.


/Joakim

Can you tell me what childType returns?  Is it numeric, or string.  I have the same variable defined above.  I am using
when childtype == 4 #used when Device is Thermostat
...
Is this the correct way to use this variable.

Is there a way to test the code prior to placing it into the template?

Sorry for the noob question.  I am new to both Linuxmce and Ruby. 

-Gregg

JoakimL

  • Veteran
  • ***
  • Posts: 149
    • View Profile
Re: Help retrieving template id for ruby script
« Reply #3 on: November 15, 2011, 10:07:02 pm »
Sorry,  I don't. But try doing a .to_s and output it to a log to see the value.

/Joakim